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 => 0
$bcc => 0
$attach => 0
$file => 0
$spellcheck => 0
$save => 0
$address => 0
$send => 0
$cancel => 0
$remove => 0
$attachment => 0
</%args>
% if($send && $prefs->get('skipsendreport') && !$error) {
%    $m->redirect(build_url("$base/mail/index.html", { message => "Your message was sent." }));
% } elsif($send) {
   <& /mail/header.mhtml, title => "Process compose", folder => 'none' &>
   <p>
      <a href="<% $base %>/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($sent_folder ne 'none' && !$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("$base/mail/index.html") if($cancel);
my $user = Apache2::SiteControl->getCurrentUser($r);
if(!$user || !$user->isa('Apache2::SiteControl::User')) {
   $logger->error("Unable to find a user for the given session key. r, m:" . Dumper($r, $m));
   $m->redirect("$base");
}
my $prefs;
my $username;
my $error = 0;
my $sent = 0;
my $saved = 0;
my $entity;
my $folder;
my $c;
my $dir;
my $book;
my $sent_folder;
my $delete_drafts;
my @sent_to = (); # Result of actual send
my $composition;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);

$subject = "(none)" if(!$subject);

eval { # Initialize variables
   $prefs = new AlphaMail::Preferences($user->getUsername(), 
                                      $user->getAttribute('mx'), $config);
   $username = $user->getUsername();
   $folder = $user->getAttribute('lastfolder') || 'inbox';
   $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
   $dir = $config->getComposeDir($user);
   $book = new AlphaMail::AddressBook($user->getUsername(), $user->getAttribute('mx'), $config);
   $sent_folder = $prefs->get('sent_folder', $config->get("default_sent", 'none'));
   $delete_drafts = $prefs->get('delete_drafts', 0);
   @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("$base/mail/compose.html", { message => 'Unable to process compose. Please try again. If it fails again, please contact support.'}));
}

# Fix up incoming parameters
eval {
   $logger->debug("Looking up address lists in to, cc, and bcc");
   $to = Encode::decode_utf8($to);
   $cc = Encode::decode_utf8($cc);
   $bcc = Encode::decode_utf8($bcc);
   $to = $book->dealias($to, $user->getAttribute('mx', ''));
   $cc = $book->dealias($cc, $user->getAttribute('mx', ''));
   $bcc = $book->dealias($bcc, $user->getAttribute('mx', ''));
   $composition->setAddresses($to, $cc, $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("$base/mail/compose.html", { message => 'Composition processing failed! Contact support.'}));
}

if($save) {
   eval {
      $composition->save_draft($c, $prefs->get('drafts_folder', $config->get("default_drafts", 'none')));
   };
   if($@) {
      $error = "Unable to save draft: $@";
      $logger->error("Unable to save draft: $@");
   } else {
      $m->redirect(build_url("$base/mail/index.html", { message => 'Saved. Go to Drafts and click on the message to resume composition.' }));
   }
} elsif($send) {
   # 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', "$base/mail/process_compose.html");
         $user->setAttribute($r, 'intended_args', [ %ARGS ]);
         $m->redirect("$base/mail/verify_password.html");
      }
   }
   $user->setAttribute($r, 'lasttime', [ gettimeofday ]);

   $logger->debug("Attempting to send a message.");
   if($to || $cc || $bcc) {
      eval {
         # Pass send the local file for temp dump, so we can save to sent folder
         $logger->debug("Sending. Saving tmp in $dir");
         @sent_to = $composition->send($config, "$dir/${username}_compose.msg");
         map { $_ = mimewords_to_utf8($_) } @sent_to;
         $sent = scalar(@sent_to);
      };
      if($@) {
         $logger->error("SEND FAILED: $@");
      } elsif($composition->{isresume}) { # Delete the draft
         $composition->remove_draft($user, $config) if($delete_drafts);
      }

      # 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($sent_folder ne 'none' && -r "$dir/${username}_compose.msg") {
         eval {
            $logger->debug("Saving to $sent_folder folder");
            $c->appendMessage($sent_folder, "$dir/${username}_compose.msg");
            $saved = 1;
         };
         if($@) {
            $logger->error("Message not saved in $sent_folder");
            $error = "Unable to save message to $sent_folder!";
         }
      } else {
         $logger->error("No tmp file to use for saving to Sent");
      }

      unlink("$dir/${username}_compose.msg");
      $composition->save();
   } else {
      # Pretend you didn't just try to send...makes error code easier in 
      # HTML section.
      $send = 0; 
      $error = "You must specify a recipient!";
   }
} elsif($attach) {
   eval {
      use Apache2::Upload;
      use Apache2::Request;
      $logger->debug("Creating request object");
      my $req = Apache2::Request->new($r);
      # Get the file
      $logger->debug("Doing upload");
      my $upload = $req->upload('file');
      $logger->debug("Getting filename");
      my $filename = Encode::decode_utf8($upload->filename);
      $logger->debug("got $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;
      $logger->debug("Saving in $tmploc");
      
      if(-f $tmploc) {
         unlink $tmploc;
      }
      $upload->link($tmploc);
      $logger->debug("Adding $filename at $tmploc as attachment.");
      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("$base/mail/check_spelling.html");
} elsif($address) {
   $m->redirect("$base/mail/addresslist.html");
}

</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Time::HiRes qw( gettimeofday tv_interval );
use Encode;
use AlphaMail::MailTool qw(encode_utf8addresses encode_utf8address encode_utf8mimewords mimewords_to_utf8);
our $VERSION = $AlphaMail::VERSION;
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
    index.html
    show_stats.mhtml
    test.mhtml
  docs/
    faq/
      colors.gif
      dates1.gif
      drafts.gif
      filter.gif
      general.html
      index.html
      notrash1.gif
      notrash2.gif
      notrash3.gif
      other.html
      sort.gif
      timeout.gif
    new_features.html
  settings/
    add_filter.html
    altfolder_update.html
    altprefix_update.html
    edit_folders.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
  error.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