Code Search for Developers
 
 
  

process_messages.html from AlphaMail at Krugle


Show process_messages.html syntax highlighted

% # vim: set syntax=mason:
<%args>
$folder
@uids => ()
$uidv
$start
$n
$sortby
$action => 'none'
$empty => 0
$delete => 0
</%args>
<& /mail/index.html, message => $msg &>
<%init>
my $user = Apache::SiteControl->getCurrentUser($r);
my $c;
my $msg = "";
my $prefs = new AlphaMail::Preferences($user->getUsername(), 
                                   $user->getAttribute('imap'), $config);
my $trash = $prefs->get('trash_folder', 'none');
my $logger = Log::Log4perl->get_logger('alphamail');
my $dir = $config->get('message_tmpdir', '/tmp');
my $destfolder;

eval {
   $c = new AlphaMail::Middleware($user->getAttribute('imap'), 
                                 $user->getUsername(), 
                                 $user->getAttribute('password'), 
                                 $config);

   if($folder eq $trash && $empty) {
      # Get all the uids
      my $hdrs = $c->getMessageHeaders($trash, 1, 100000, 'date');
      @uids = ();
      for my $h (@$hdrs) {
         push @uids, $h->{uid};
      }
      $c->deleteMessages($trash, $hdrs->[0]{uidvalidity}, \@uids) if(@uids);
      $c->expungeFolder($trash);
   } elsif(@uids && $delete) {
      if($folder eq $trash) { # We are in the trash folder
         $c->deleteMessages($folder, $uidv, \@uids);
         $c->expungeFolder($folder);
      } elsif($trash eq 'none') { # Wait for purge request to expunge
         $c->deleteMessages($folder, $uidv, \@uids);
      } else {
         eval {
            $c->moveMessages($folder, $uidv, \@uids, $trash);
            $c->expungeFolder($folder);
         };
         if($@) {
            # Failure...probably over quota. Switch to no trash and mark
            # deleted.
            $logger->error('Unable to move messages to trash. User probably over quota.');
            $msg = "Unable to move messages to $trash. You either deleted your trash folder from the system, or you are over quota. Your settings were changed so that no trash folder is in use. Press the 'Purge Deleted Messages' to complete the message removal. NOTE: This will permanently remove the deleted messages. Use Settings to select a Trash folder if you want one.";
            $prefs->set('trash_folder', 'none');
            $c->deleteMessages($folder, $uidv, \@uids);
         }
      }
   } elsif(@uids && $action =~ m/^kill$/i) {
      $c->deleteMessages($folder, $uidv, \@uids);
      $c->expungeFolder($folder);
   } elsif(@uids && $action =~ m/^undelete$/i) {
      $c->undeleteMessages($folder, $uidv, \@uids);
   } elsif(@uids && $action =~ m/^to:(.*)$/) {
      $destfolder = $1;
      if($folder eq $destfolder) {
         $msg = "That message is already in $destfolder. Please select a different destination folder before clicking on Move.";
      } else {
         $c->moveMessages($folder, $uidv, \@uids, $destfolder);
         $c->expungeFolder($folder);
      }
   } elsif($action eq 'expunge') {
      $c->expungeFolder($folder);
   } elsif(($action =~ m/^(move|undelete)$/ || $delete) && !@uids) {
      $msg = "Please select messages first.";
   } elsif($action eq 'report' && @uids) {
      eval {
         my $rv;
         my $date = $Time::Format::time{'Day, dd Mon yyyy hh:mm:ss tz'};
         my $reply_address = $user->getUsername() . "@" . $user->getAttribute('mx');
         my $spam_address = $config->get('spam_address', '');
         $msg = "System error: Spam reporting not configured!";
         $logger->logcroak('Spam address not set for reporting') if($spam_address !~ m/\@/);
         my $entity = MIME::Entity->build(Type    =>"multipart/mixed",
                                       'X-Mailer' => "AlphaMail $AlphaMail::VERSION",
                                       From    => $reply_address,
                                       To      => $spam_address,
                                       Date => $date,
                                       Subject => "Forwarded SPAM (webmail report)");

      ### Part #1: a simple text document:
         $entity->attach(Data=>"The attached message(s) were forwarded from the webmail Report Spam button.",
                         Type => 'text/plain',
                         Charset    => "us-ascii");
         my $parser = new MIME::Parser;
         $parser->output_under($dir);
         $parser->decode_headers(0);
         $parser->ignore_errors(1);

         for my $uid (@uids) {
            my $message = $c->getMessage($folder, $uid, $uidv);
            my $msg_entity = $parser->parse_open("<$message");
            $entity->add_part($msg_entity);
         }

         $rv = send_mail($config, $reply_address, $entity);
         die "$rv" if($rv != 0);
      };
      if($@) {
         $logger->error("Unable to forward spam: $@");
         $msg = "Could not report spam.";
      } else {
         $msg = "The message(s) were reported";
      }
   } elsif($action eq 'none') {
      $msg = "";
   } else {
      $msg = "Invalid request. Make sure you select messages first.";
   }
   $c->close;
};
if($@) {
   $logger->error("ERROR: $@");
   $msg = "Unable to complete the request.";
}
</%init>
<%once>
use Time::Format;
use MIME::Words;
use AlphaMail::MailTool qw(send_mail);
use AlphaMail;
</%once>




See more files for this project here

AlphaMail

AlphaMail is an accelerated web mail interface with a C++ middleware layer that is more effective than an IMAP proxy which is a highly scalable (10k+ users). The interface includes modern features, Section 508 compliance, and universal browser support.

Project homepage: http://sourceforge.net/projects/alphamail
Programming language(s): C++,Java,JavaScript,Perl
License: other

  addressbook/
    edit.mhtml
    import.mhtml
    import_alias.html
    import_complete.html
    import_csv.html
    import_csv_save.html
    import_fname.html
    import_imho.html
    import_lname.html
    index.html
    process_edit.html
    take.html
  settings/
    altfolder_update.html
    edit_folders.html
    folders.mhtml
    general.mhtml
    index.html
    share.mhtml
    sharing_agree.html
    signatures.mhtml
    update_folderlist.html
    update_general.html
    update_signatures.html
  viewers/
    excel.html
    html.html
    targz.html
    word.html
    zip.html
  address_mail.html
  addresslist.mhtml
  autohandler
  check_spelling.html
  compose.html
  filevault.html
  first_login.html
  fix_spelling.html
  folderlist.mhtml
  footer.mhtml
  get_attachment.html
  header.mhtml
  index.html
  logout.html
  menu.mhtml
  other_folders.html
  print.html
  process_compose.html
  process_first_login.html
  process_messages.html
  read.html
  remove_attachment.html
  renew_session.html
  share_options.html
  share_upload.html
  verify_password.html
  view_attachment.html