Code Search for Developers
 
 
  

process_compose.html from AlphaMail at Krugle


Show process_compose.html syntax highlighted

% # vim:set syntax=mason:
<%args>
$subject => ''
$body => ''
$to => 0
$cc => ''
$bcc => ''
$attach => 0
$file => 0
$spellcheck => 0
$address => 0
$save => 0
$send => 0
$cancel => 0
$remove => 0
$attachment => 0
</%args>
% if($send && $subject eq '') {
   <& /mail/compose.html, message => "Please supply a subject." &>
% } elsif($send && $to eq '') {
   <& /mail/compose.html, message => "Please supply a destination." &>
% } elsif($send && $prefs->get('skipsendreport') && !$error) {
%    $m->redirect(build_url("/mail/index.html", { message => "Your message was sent." }));
% } elsif($send) {
   <& /mail/header.mhtml, title => "Process compose", folder => 'none' &>
   <p>
      <a href="/mail/index.html">Return to message index</a>
   </p>
%    if($error) {
%       if($sent) {
      <p>Your message was sent to <% @sent_to |h %></p>
%       } else {
      <p>Your message was <b>not</b> sent due to an error. Contact Help.</p>
%       }
%       if(!$saved) {
      <p>A copy of your message was <b>not</b> saved in your sent folder due to an error. Contact help.</p>
%       }
%    } else {
%       local $" = ", ";
      <p>Your message has been sent to the following addresses:</p>
      <p><% "@sent_to" |h %></p>
%    }
   <& /mail/footer.mhtml &>
% } else {
   <& /mail/compose.html, message => $error &>
% } 
<%init>
$m->redirect("/mail/index.html") if($cancel);
my $logger = Log::Log4perl->get_logger('alphamail');

my $user = Apache::SiteControl->getCurrentUser($r);
if(!$user || !$user->isa('Apache::SiteControl::User')) {
   $logger->error("Unable to find a user for the given session key. r, m:" . Dumper($r, $m));
   $m->redirect("/");
}
my $prefs;
my $username;
my $reply_address;
my $error = 0;
my $sent = 0;
my $saved = 0;
my $entity;
my $folder;
my $c;
my $dir;
my $book;
my $sent_folder;
my @sent_to = (); # Result of actual send
my $composition;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);

eval { # Initialize variables
   $prefs = new AlphaMail::Preferences($user->getUsername(), 
                                      $user->getAttribute('imap'), $config);
   $username = $user->getUsername();
   $folder = $user->getAttribute('lastfolder') || 'inbox';
   $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
   $dir = $config->get('message_tmpdir', '/tmp');
   $book = new AlphaMail::AddressBook($user->getUsername(), $user->getAttribute('imap'), $config);
   $sent_folder = $prefs->get('sent_folder', $config->get("default_sent", 'none'));
   @sent_to = (); # Result of actual send
   $composition = new AlphaMail::Message($user, $config);
   $composition->load();
   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
}; 
if($@) {
   $logger->error("Compose processing failed: $@");
   $m->redirect(build_url('/mail/compose.html', { message => 'Unable to process compose. Please try again. If it fails again, please contact support.'}));
}

eval {
   $reply_address = $username . "@" . $user->getAttribute('mx');
   if($prefs->get('replyto', 0) =~ m/\@/) {
      my $a = Email::Address->new('"'.mimewords_to_utf8($prefs->get('fullname')).'"', $prefs->get('replyto'));
      $reply_address = $a->format;
   }
   $logger->debug("Reply address is: $reply_address");
};
if($@) {
   $logger->error("Unable to properly create reply_to address: $@.\nDefaulted to: $reply_address");
}

# Fix up incoming parameters
eval {
   $composition->setAddresses($to = Encode::decode_utf8($to),
                              $cc = Encode::decode_utf8($cc),
                              $bcc = Encode::decode_utf8($bcc));
   $composition->setSubject($subject = Encode::decode_utf8($subject));
   $composition->setBody($body = Encode::decode_utf8($body));
   $composition->save();
};
if($@) {
   $logger->error("Unable to properly save composition.");
   $m->redirect(build_url("/mail/compose.html", { message => 'Composition processing failed! Contact support.'}));
}

if($send && $subject) {
   # Check session timeout first.
   my $timeout = $config->get('session_timeout', 300);
   my $lasttime = $user->getAttribute('lasttime');
   if(defined($lasttime)) {
      if(tv_interval( $lasttime, [gettimeofday]) > $timeout) {
         $user->setAttribute($r, 'intended_dest', '/mail/process_compose.html');
         $user->setAttribute($r, 'intended_args', [ %ARGS ]);
         $m->redirect('/mail/verify_password.html');
      }
   }
   $user->setAttribute($r, 'lasttime', [ gettimeofday ]);

   $logger->debug("Attempting to send a message.");
   $logger->debug("Looking up address lists in to, cc, and bcc");
   $to = $book->dealias($to, $config->get('default_domain', ''));
   $cc = $book->dealias($cc, $config->get('default_domain', ''));
   $bcc = $book->dealias($bcc, $config->get('default_domain', ''));
   if($to) {
      eval {
         $composition->setAddresses($to, $cc, $bcc);

         # Pass send the local file for temp dump, so we can save to sent folder
         @sent_to = $composition->send($config, "$dir/${username}_compose.msg");
         map { $_ = mimewords_to_utf8($_) } @sent_to;
         $sent = scalar(@sent_to);
      };
      if($@) {
         $logger->error("SEND FAILED: $@");
      }

      # Mark message as replied or forwarded...
      if($composition->isReply() || $composition->isForward()) {
         eval {
            my ($m, $n, $o) = $composition->getMsgref;
            if($composition->isReply()) {
               $logger->debug("marking message answered: $m, $n, $o");
               $c->markReplied($m, $n, $o);
            } else {
               $logger->debug("marking message fowarded: $m, $n, $o");
               $c->setFlag($m, $n, $o, 'W', 1);
            }
         };
         if($@) {
            $logger->error("Problem marking message: $@");
            # Reconnect
            $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
         }
      }

      if(-r "$dir/${username}_compose.msg") {
         eval {
            $c->appendMessage($sent_folder, "$dir/${username}_compose.msg");
            $saved = 1;
         };
      }

      unlink("$dir/${username}_compose.msg");
      $composition->save();
   } else {
      $error = "You must specify a recipient!";
   }
} elsif($attach) {
   eval {
      # Get the file
      my $upload = $r->upload;
      my $filename = Encode::decode_utf8($upload->filename);
      my $tmploc;
      my $size;

      if($filename =~ m/^\s*$/) {
         $error = "Attachment failed: No file provided.";
         die $error;
      }

      # sanitize the filename
      $filename =~ s!^.*[/\\]([^\\/]*)$!$1!;
      $filename =~ s/^\.+//g;
      $filename = encode_utf8mimewords($filename);
      $tmploc = "$dir/" . $username . "_attachment_" . $filename;
      
      if(-f $tmploc) {
         unlink $tmploc;
      }
      $upload->link($tmploc);
      my $cnt = $composition->addAttachment($filename, $tmploc);
      if($cnt && $composition->getSize > $config->get('max_message_size')) {
         $error = "Attachment failed. Maximum message size would be exceeded. Try using file sharing instead."; 
         $composition->removeAttachment($cnt-1);
         die $error; 
      }
      $logger->debug("Added $filename at $tmploc to active composition");
   };
   if($@) {
      $logger->error("Unable to get attachment: $@");
   }
} elsif($remove) { # Remove an attachment
   eval {
      $composition->removeAttachment($attachment);
   };
   if($@) {
      $logger->error("Attachment removal failed: $@");
   }
}

eval {
   $composition->save();
}; 
if($@) {
   $logger->error("SAVE FAILED: $@");
}

if($spellcheck) {
   $m->redirect('/mail/check_spelling.html');
} elsif($address) {
   $m->redirect('/mail/addresslist.html');
}

</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Time::HiRes qw( gettimeofday tv_interval );
use MIME::Words;
use AlphaMail;
use Encode;
use AlphaMail::MailTool qw(encode_utf8addresses encode_utf8address encode_utf8mimewords mimewords_to_utf8);
use AlphaMail::Message;
our $VERSION = $AlphaMail::VERSION;
</%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
  settings/
    altfolder_update.html
    altprefix_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
    text.html
    word.html
    zip.html
  address_mail.html
  addresslist.html
  autohandler
  check_spelling.html
  compose.html
  error.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
  quota.html
  quota_graph.html
  raw.html
  read.html
  remove_attachment.html
  renew_session.html
  sanitized.html
  share_options.html
  share_upload.html
  show_stats.html
  verify_password.html
  view_attachment.html