Code Search for Developers
 
 
  

process_read_message.html from AlphaMail at Krugle


Show process_read_message.html syntax highlighted

% # vim: set syntax=mason:
<%args>
$folder => 'none'
$uid => 0
$nextuid => 0
$uidv => 0
$sorted_offset => 0
$n => 0
$sortby => 0
$fullheaders => 0
$action => 'none'
$delete => 0
$undelete => 0
$reply => 0
$replyall => 0
$forward => 0
</%args>
<%init>
if($folder eq 'none' || $uidv == 0) {
   $logger->error("User attempted to run process_read_message without passing a folder:" . Dumper($m));
   $m->redirect(build_url("$base/mail/index.html", { folder => 'inbox', message => 'unable to process the request. Please try again.' }));
}
my $user = Apache2::SiteControl->getCurrentUser($r);
if(!$user || !$user->isa('Apache2::SiteControl::User')) {
   $logger->error($user->getUsername() . ": Unable to find a user for the given session key. r, m:" . Dumper($r, $m));
   $m->redirect("$base");
}
my $c;
my $msg = "";
my $prefs = new AlphaMail::Preferences($user, 
                                   $user->getAttribute('mx'), $config);
my $trash = $prefs->get('trash_folder', 'none');
my $dir = $config->getScratchDir($user);
my $destfolder;
my $reply_address;
my $sigs = new AlphaMail::Signature($user->getUsername(), $user->getAttribute('mx'), $config);
my $other_to = "";
my $message;
my $date = Email::Date::format_date;

$logger->debug($user->getUsername() . ": action is $action");

if($prefs->get('replyto') =~ m/\@/) {
   $reply_address = $prefs->get('replyto');
} else {
   $reply_address = $user->getUsername() . '@' . $user->getAttribute('mx');
}

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

   if($uid && $delete) {
      if($folder eq $trash) { # We are in the trash folder
         $c->deleteMessages($folder, $uidv, [ $uid ]);
         $c->expungeFolder($folder);
         $msg = "Message discarded";
      } elsif($trash eq 'none') { # Wait for purge request to expunge
         $c->deleteMessages($folder, $uidv, [ $uid ]);
         $msg = "Message marked for deletion";
      } else {
         eval {
            $c->moveMessages($folder, $uidv, [ $uid ], $trash);
            $c->expungeFolder($folder);
            $msg = "Message moved to $trash";
         };
         if($@) {
            # Failure...probably over quota. Switch to no trash and mark
            # deleted.
            $logger->error($user->getUsername() . ': 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, [ $uid ]);
         }
      }
   } elsif($uid && $undelete) {
      $c->undeleteMessages($folder, $uidv, [ $uid ]);
      $msg = "Message undeleted";
   } elsif($uid && $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, [ $uid ], $destfolder);
         $c->expungeFolder($folder);
         $msg = "Message moved to $destfolder";
      }
   } elsif($action eq 'report' && $uid) {
      eval {
         my $rv;
         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 was forwarded from the webmail Report Spam button.",
                         Type => 'text/plain',
                         Charset    => "us-ascii");
         my $parser = new MIME::Parser;
         $parser->output_dir($dir);
         $parser->decode_headers(0);
         $parser->ignore_errors(1);

         my $message = $c->getMessage($folder, $uid, $uidv, $config->getScratchDir($user));
         my $msg_entity = $parser->parse_open("<$message");
         $entity->add_part($msg_entity);

         $rv = send_mail($config, $reply_address, $entity);
         die "Send failed" if($rv->{error});
         # Delete the crap:
         if($folder eq $trash) { # We are in the trash folder
            eval {
               $c->deleteMessages($folder, $uidv, [ $uid ]);
               $c->expungeFolder($folder);
            };
         } elsif($trash eq 'none') { # Wait for purge request to expunge
            eval { $c->deleteMessages($folder, $uidv, [ $uid ]); };
         } else {
            eval {
               $c->moveMessages($folder, $uidv, [ $uid ], $trash);
               $c->expungeFolder($folder);
            };
            if($@) {
               # Failure...probably over quota. Switch to no trash and mark
               # deleted.
               $logger->error($user->getUsername() . ': Unable to move messages to trash. User probably over quota.');
               $prefs->set('trash_folder', 'none');
               eval { $c->deleteMessages($folder, $uidv, [ $uid ]); };
            }
         }
      };
      if($@) {
         $logger->error($user->getUsername() . ": Unable to forward spam: $@");
         $msg = "Could not report spam.";
      } else {
         $msg = "The message was reported.";
      }
   } elsif($reply || $replyall || $forward) {
      my $mime_file = $c->getMessage($folder, $uid, $uidv, $config->getScratchDir($user));
      my $message = new AlphaMail::Message($user, $config);
      if($forward) {
         $message->forward($mime_file, $folder, $uid, $uidv, $fullheaders);
      } elsif($reply) {
         $message->reply($mime_file, $folder, $uid, $uidv);
      } else { # reply all
         $message->replyall($mime_file, $folder, $uid, $uidv);
      }
      $message->save();
   } elsif($action =~ m/^(un)?mark$/) {
      my $on = $action eq 'mark';
      $c->setFlag($folder, $uid, $uidv, 'F', $on);
      $msg = "Message " . ($on ? "Flagged.":"Unflagged.");
   } else {
      $msg = "Invalid request.";
   }
   $c->close;
};
if($@) {
   $logger->error($user->getUsername() . ": ERROR: $@. user, r, m: ". Dumper($user, $r, $m));
   $msg = "Unable to complete the request.";
} 

if($reply || $replyall || $forward) {
   $m->redirect(build_url("$base/mail/compose.html", { message => $msg }));
} elsif($nextuid) { # display next message
   # The next message depends on whether or not we actually expunged the
   # message we were just reading...
   $sorted_offset++ if($undelete || $action =~ m/^(report|(un)?mark)$/ || ($delete && $trash eq 'none'));
   $m->redirect(
      build_url("$base/mail/read.html", 
         { folder => $folder, uidv => $uidv, uid => $nextuid, 
           sorted_offset => $sorted_offset, n => $n, sortby => $sortby,
           msg => $msg
         }));
} else { # return to index
   $m->redirect(build_url("$base/mail/index.html", { message => $msg }));
}
</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Data::Dumper;
our $logger = Log::Log4perl->get_logger('alphamail');
our $base = $config->get('base_uri');
</%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_complete.html
    import_csv.html
    import_csv_save.html
    import_fname.html
    import_imho.html
    import_lname.html
    index.html
    lists.mhtml
    process_edit.html
    process_lists.html
    process_take.html
    take.html
  admin/
    autohandler
    guide.html
    index.html
    quotas.jpg
    show_stats.mhtml
    test.mhtml
  docs/
    faq/
      attach1.gif
      attach2.gif
      attach3.gif
      colors.gif
      dates1.gif
      drafts.gif
      filter.gif
      index.html
      notrash1.gif
      notrash2.gif
      notrash3.gif
      other.html
      sort.gif
      timeout.gif
    index.html
    new_features.html
  settings/
    add_filter.html
    altfolder_update.html
    altprefix_update.html
    edit_folders.html
    export.mhtml
    export_mail.html
    filters.mhtml
    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
    text.html
    word.html
    zip.html
  address_mail.html
  addresslist.html
  autohandler
  check_spelling.html
  compose.html
  feedback.html
  first_login.html
  fix_spelling.html
  folderlist.mhtml
  footer.mhtml
  get_attachment.html
  header.mhtml
  help.html
  index.html
  logout.html
  menu.mhtml
  other_folders.html
  process_compose.html
  process_first_login.html
  process_messages.html
  process_read_message.html
  process_search.html
  quota.html
  quota_graph.html
  raw.html
  read.html
  remove_attachment.html
  renew_session.html
  resume_compose.html
  sanitized.html
  share_options.html
  share_upload.html
  verify_password.html
  view_attachment.html