Code Search for Developers
 
 
  

process_compose.html from AlphaMail at Krugle


Show process_compose.html syntax highlighted

% # vim:set syntax=mason:
<%args>
$subject => ''
$message => ''
$to => 0
$cc => ''
$bcc => ''
$attach => 0
$file => 0
$spellcheck => 0
$address => 0
$save => 0
$send => 0
$cancel => 0
$forward => 0
$ref => 0
@attachments => ()
@sizes => ()
$reply => 0
$remove => 0
$attachment => 0
$richtext => 0
</%args>
% if($send && $subject eq '') {
   <& /mail/compose.html, error => "Please supply a subject." &>
% } elsif($send && $to eq '') {
   <& /mail/compose.html, error => "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; however, there was an error: <% $error %></p>
%       } else {
      <p>Your message was not sent due to the following error: <% $error %></p>
%       }
%       if(!$saved) {
      <p>A copy of your message was not saved in your sent folder.</p>
%       }
%    } else {
      <p>Your message has been sent to the following addresses:</p>
      <p>To: <% $to |h %></p>
%       if($cc ne '') {
      <p>Cc: <% $cc |h %></p>
%       }
%       if($bcc ne '') {
      <p>Bcc: <% $bcc |h %></p>
%       }
%    }
   <& /mail/footer.mhtml &>
% } elsif($error) {
   <& /mail/compose.html, error => $error &>
% } elsif($spellcheck) {
   <& /mail/check_spelling.html &>
% } elsif($address) {
   <& /mail/addresslist.mhtml &>
% } else {
   <& /mail/compose.html &>
% }
<%init>
# If the user is submitting a compose, the we will have parameters. No need
# to restore from session.
#   - If the request is a send, then check session timeout before sending.
#      - On timeout, verify password, and have the redirect re-send the
#      "send" parameter.
#   - Else do all that was asked, and let compose.html check session timeout
my $user = Apache::SiteControl->getCurrentUser($r);
my $prefs = new AlphaMail::Preferences($user->getUsername(), 
                                   $user->getAttribute('imap'), $config);
my $username = $user->getUsername();
my $reply_address;
my $error = 0;
my $sent = 0;
my $saved = 0;
my $entity;
my $folder = $user->getAttribute('lastfolder') || 'inbox';
my $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
my $logger = Log::Log4perl->get_logger('alphamail');
my $dir = $config->get('message_tmpdir', '/tmp');
my $book = new AlphaMail::AddressBook($user->getUsername(), $user->getAttribute('imap'), $config);
my $sent_folder = $prefs->get('sent_folder', $config->get("default_sent", 'none'));

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $date = $Time::Format::time{'Day, dd Mon yyyy hh:mm:ss tz'};

$reply_address = $username . "@" . $user->getAttribute('mx');

# Fix up incoming parameters
$to = Encode::decode_utf8($to);
$cc = Encode::decode_utf8($cc);
$bcc = Encode::decode_utf8($bcc);
$subject = Encode::decode_utf8($subject);
$message = Encode::decode_utf8($message);
my @a = ();
for my $a (@attachments) {
   push @a, Encode::decode_utf8($a);
}
@attachments = @a;

$logger->debug("reply is $reply, forward is $forward, ref is ->$ref<-");
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) {
         save_composition($r, $user, $to, $cc, $bcc, $subject, $message, $reply, $forward, $ref, \@attachments, \@sizes, $richtext);
         $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 book aliases 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) {
      if($forward || @attachments) {
         my $s = MIME::Words::encode_mimewords($subject, Charset => 'UTF-8');
         $entity = MIME::Entity->build(Type    =>"multipart/mixed",
                                       'X-Mailer' => "AlphaMail $VERSION",
                                       From    => $reply_address,
                                       To      => $to,
                                       Cc      => $cc,
                                       Bcc      =>$bcc,
                                       Date => $date,
                                       Subject => $s);

         ### Part #1: a simple text document:
         $entity->attach(Data=>$message,
                         Type => ($richtext ? 'text/html':'text/plain'),
                         Charset    => "UTF-8");

         ### Other attachments
         for my $a (@attachments) {
            my $fileloc = "$dir/" . $username . "_attachment_" . $a;
            my $type = `/usr/bin/file -i $fileloc`;
            chomp $type;
            $type =~ s/.*: //;
            $logger->debug("Adding attachment $a");
            $entity->attach(Path=>$fileloc,
                            Type => ($type ? $type:'application/octet-stream'),
                            Filename => $a, 
                            Encoding    => "base64");
         }

         if($forward && $ref =~ m/^(.*)\|(\d+)\|(\d+)$/) {
            $logger->debug("Attempting to attach forwarded message from $1 with uid $2 and validity of $3");
            eval {
               my $message = $c->getMessage($1, $2, $3);
               my $parser = new MIME::Parser;
               $parser->output_under($dir);
               $parser->decode_headers(0);
               $parser->ignore_errors(1);
               my $msg_entity = $parser->parse_open("<$message");
               $entity->add_part($msg_entity);
            };
            if($@) {
               $logger->error("Unable to attach forwarding message: $@");
            }
         }
      } else {
         my $s = MIME::Words::encode_mimewords($subject, Charset => 'UTF-8');
         $entity = MIME::Entity->build(From    => $reply_address,
                                       'X-Mailer' => "AlphaMail $VERSION",
                                       To      => $to,
                                       Cc      => $cc,
                                       Bcc      =>$bcc,
                                       Subject => $s,
                                       Date => $date,
                                       Data => $message,
                                       Type => ($richtext ? 'text/html':'text/plain'),
                                       Charset => 'UTF-8');
      }
      ### Send it:
      eval {
         open DATA, ">$dir/${username}_compose.msg";
         $entity->print(\*DATA);
         close DATA;

         $logger->debug("sending message using reply address: $reply_address.");
         my $rv = send_mail($config, $reply_address, $entity);
         die "$rv" if($rv);
         $sent = 1;

         # Mark message as replied...
         if($reply) {
            eval {
               if($ref =~ m/^(.*)\|(\d+)\|(\d+)$/) {
                  $logger->debug("marking message answered: $1, $2, $3");
                  $c->markReplied($1, $2, $3);
               } else {
                  $logger->error("wanted to mark message answered, but ref $ref was incorrect and did not match the regex.");
               }
            };
            if($@) {
               $logger->error("Problem marking message answered: $@");
               # Reconnect
               $c = new AlphaMail::Middleware($user->getAttribute('imap'), $user->getUsername(), $user->getAttribute('password'), $config);
            }
         }

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

         unlink("$dir/${username}_compose.msg");
         clear_composition($r, $user, $config);
      };
      $error = $@ if($@);
   } else {
      $error = "You must specify a recipient! Use your browser back button.";
   }
} elsif($attach) {
   eval {
      # Get the file
      my $upload = $r->upload;
      my $filename = $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 =~ s/[^a-z0-9.]/_/ig;
      $tmploc = "$dir/" . $username . "_attachment_" . $filename;
      
      if(-f $tmploc) {
         unlink $tmploc;
      }
      $upload->link($tmploc);
      $size = (stat($tmploc))[7];
      if($size == 0) {
         $error = "Attachment failed. No (or empty) file provided!";
         die $error;
      }
      my $total = 0;
      map { $total += $_ } @sizes;
      if($total + $size > $config->get('max_message_size')) {
         $error = "Attachment failed. Maximum message size would be exceeded. Try using file sharing instead."; 
         die $error; 
      }
      push @attachments, $filename;
      push @sizes, (stat($tmploc))[7];
      $logger->debug("Added $filename at $tmploc to active composition");
   };
   if($@) {
      $logger->error("$@");
   }
} elsif($remove) { # Remove an attachment
   my @ta = ();
   my @s = ();
   
   for(my $i=0; $i <= $#attachments; $i++) {
      next if($attachment == $i);
      push @ta, $attachments[$i];
      push @s, $sizes[$i];
   }
   @attachments = @ta;
   @sizes = @s;
}

# Save the incoming composition to the session
save_composition($r, $user, $to, $cc, $bcc, $subject, $message, $reply, $forward, $ref, \@attachments, \@sizes, $richtext);

</%init>
<%once>
use AlphaMail::HTMLHelper qw(build_url);
use Time::HiRes qw( gettimeofday tv_interval );
use MIME::Words;
use Time::Format;
use AlphaMail;
use AlphaMail::MailTool qw(send_mail);
use AlphaMail::SessionUtil qw(save_composition clear_composition);
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_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