Source for file compose.php

Documentation is available at compose.php

  1. <?php
  2.  
  3. /**
  4.  * compose.php
  5.  *
  6.  * This code sends a mail.
  7.  *
  8.  * There are 4 modes of operation:
  9.  *    - Start new mail
  10.  *    - Add an attachment
  11.  *    - Send mail
  12.  *    - Save As Draft
  13.  *
  14.  * @copyright 1999-2014 The SquirrelMail Project Team
  15.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  16.  * @version $Id: compose.php 14459 2014-04-23 19:22:25Z pdontthink $
  17.  * @package squirrelmail
  18.  */
  19.  
  20. /** This is the compose page */
  21. define('PAGE_NAME''compose');
  22.  
  23. /**
  24.  * Path for SquirrelMail required files.
  25.  * @ignore
  26.  */
  27. define('SM_PATH','../');
  28.  
  29. /* SquirrelMail required files. */
  30. require_once(SM_PATH 'include/validate.php');
  31. require_once(SM_PATH 'functions/global.php');
  32. require_once(SM_PATH 'functions/imap.php');
  33. require_once(SM_PATH 'functions/date.php');
  34. require_once(SM_PATH 'functions/mime.php');
  35. require_once(SM_PATH 'functions/plugin.php');
  36. require_once(SM_PATH 'functions/display_messages.php');
  37. require_once(SM_PATH 'class/deliver/Deliver.class.php');
  38. require_once(SM_PATH 'functions/addressbook.php');
  39. require_once(SM_PATH 'functions/forms.php');
  40. require_once(SM_PATH 'functions/identity.php');
  41.  
  42. /* --------------------- Get globals ------------------------------------- */
  43. /** COOKIE VARS */
  44. sqgetGlobalVar('key',       $key,           SQ_COOKIE);
  45.  
  46. /** SESSION VARS */
  47. sqgetGlobalVar('username',  $username,      SQ_SESSION);
  48. sqgetGlobalVar('onetimepad',$onetimepad,    SQ_SESSION);
  49. sqgetGlobalVar('base_uri',  $base_uri,      SQ_SESSION);
  50. sqgetGlobalVar('delimiter'$delimiter,     SQ_SESSION);
  51.  
  52. sqgetGlobalVar('composesession',    $composesession,    SQ_SESSION);
  53. sqgetGlobalVar('compose_messages',  $compose_messages,  SQ_SESSION);
  54.  
  55. // compose_messages only useful in SESSION when a forward-as-attachment 
  56. // has been preconstructed for us and passed in via that mechanism; once 
  57. // we have it, we can clear it from the SESSION
  58. sqsession_unregister('compose_messages');
  59.  
  60. /** SESSION/POST/GET VARS */
  61. sqgetGlobalVar('send'$sendSQ_POST);
  62. // Send can only be achieved by setting $_POST var. If Send = true then
  63. // retrieve other form fields from $_POST
  64. if (isset($send&& $send{
  65.     $SQ_GLOBAL SQ_POST;
  66. else {
  67.     $SQ_GLOBAL SQ_FORM;
  68. }
  69. sqgetGlobalVar('smaction',$action$SQ_GLOBAL);
  70. if (!sqgetGlobalVar('smtoken',$submitted_token$SQ_GLOBAL)) {
  71.     $submitted_token '';
  72. }
  73. sqgetGlobalVar('session',$session$SQ_GLOBAL);
  74. sqgetGlobalVar('mailbox',$mailbox$SQ_GLOBAL);
  75. if !sqgetGlobalVar('identity',$identity$SQ_GLOBAL) ) {
  76.     $identity 0;
  77. }
  78. sqgetGlobalVar('send_to',$send_to$SQ_GLOBAL);
  79. sqgetGlobalVar('send_to_cc',$send_to_cc$SQ_GLOBAL);
  80. sqgetGlobalVar('send_to_bcc',$send_to_bcc$SQ_GLOBAL);
  81. sqgetGlobalVar('subject',$subject$SQ_GLOBAL);
  82. sqgetGlobalVar('body',$body$SQ_GLOBAL);
  83. sqgetGlobalVar('mailprio',$mailprio$SQ_GLOBAL);
  84. sqgetGlobalVar('request_mdn',$request_mdn$SQ_GLOBAL);
  85. sqgetGlobalVar('request_dr',$request_dr$SQ_GLOBAL);
  86. sqgetGlobalVar('html_addr_search',$html_addr_searchSQ_FORM);
  87. sqgetGlobalVar('mail_sent',$mail_sentSQ_FORM);
  88. sqgetGlobalVar('passed_id',$passed_id$SQ_GLOBAL);
  89. sqgetGlobalVar('passed_ent_id',$passed_ent_id$SQ_GLOBAL);
  90.  
  91. sqgetGlobalVar('attach',$attachSQ_POST);
  92. sqgetGlobalVar('draft',$draftSQ_POST);
  93. sqgetGlobalVar('draft_id',$draft_id$SQ_GLOBAL);
  94. sqgetGlobalVar('ent_num',$ent_num$SQ_GLOBAL);
  95. sqgetGlobalVar('saved_draft',$saved_draftSQ_FORM);
  96.  
  97. if sqgetGlobalVar('delete_draft',$delete_draft) ) {
  98.     $delete_draft = (int)$delete_draft;
  99. }
  100.  
  101. if sqgetGlobalVar('startMessage',$startMessage) ) {
  102.     $startMessage = (int)$startMessage;
  103. else {
  104.     $startMessage 1;
  105. }
  106.  
  107. /** POST VARS */
  108. sqgetGlobalVar('sigappend',             $sigappend,             SQ_POST);
  109. sqgetGlobalVar('from_htmladdr_search',  $from_htmladdr_search,  SQ_POST);
  110. sqgetGlobalVar('addr_search_done',      $html_addr_search_doneSQ_POST);
  111. sqgetGlobalVar('send_to_search',        $send_to_search,        SQ_POST);
  112. sqgetGlobalVar('do_delete',             $do_delete,             SQ_POST);
  113. sqgetGlobalVar('delete',                $delete,                SQ_POST);
  114. sqgetGlobalVar('attachments',           $attachments,           SQ_POST);
  115. // Not used any more, but left for posterity
  116. //sqgetGlobalVar('restoremessages',       $restoremessages,       SQ_POST);
  117. if sqgetGlobalVar('return'$tempSQ_POST) ) {
  118.     $html_addr_search_done 'Use Addresses';
  119. }
  120.  
  121. /** GET VARS */
  122. // (none)
  123.  
  124. /**
  125.  * Here we decode the data passed in from mailto.php.
  126.  */
  127. if sqgetGlobalVar('mailtodata'$mailtodataSQ_GET) ) {
  128.     $trtable array('to'       => 'send_to',
  129.                  'cc'           => 'send_to_cc',
  130.                  'bcc'          => 'send_to_bcc',
  131.                  'body'         => 'body',
  132.                  'subject'      => 'subject');
  133.     $mtdata unserialize($mailtodata);
  134.  
  135.     foreach ($trtable as $f => $t{
  136.         if !empty($mtdata[$f]) ) {
  137.             $$t $mtdata[$f];
  138.         }
  139.     }
  140.     unset($mailtodata,$mtdata$trtable);
  141. }
  142.  
  143. /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
  144. $location get_location();
  145. /* Identities (fetch only once) */
  146. $idents get_identities();
  147.  
  148. /* --------------------- Specific Functions ------------------------------ */
  149.  
  150. function replyAllString($header{
  151.     global $include_self_reply_all$username$data_dir;
  152.     $excl_ar array();
  153.     /**
  154.      * 1) Remove the addresses we'll be sending the message 'to'
  155.      */
  156.     $url_replytoall_avoid_addrs '';
  157.     if (isset($header->reply_to)) {
  158.         $excl_ar $header->getAddr_a('reply_to');
  159.     }
  160.     /**
  161.      * 2) Remove our identities from the CC list (they still can be in the
  162.      * TO list) only if $include_self_reply_all is turned off
  163.      */
  164.     if (!$include_self_reply_all{
  165.         global $idents;
  166.         foreach($idents as $id{
  167.             $excl_ar[strtolower(trim($id['email_address']))'';
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * 3) get the addresses.
  173.      */
  174.     $url_replytoall_ar $header->getAddr_a(array('to','cc')$excl_ar);
  175.  
  176.     /**
  177.      * 4) generate the string.
  178.      */
  179.     $url_replytoallcc '';
  180.     foreach$url_replytoall_ar as $email => $personal{
  181.         if ($personal{
  182.             // always quote personal name (can't just quote it if
  183.             // it contains a comma separator, since it might still
  184.             // be encoded)
  185.             $url_replytoallcc .= ", \"$personal\" <$email>";
  186.         else {
  187.             $url_replytoallcc .= ', '$email;
  188.         }
  189.     }
  190.     $url_replytoallcc substr($url_replytoallcc,2);
  191.  
  192.     return $url_replytoallcc;
  193. }
  194.  
  195. function getReplyCitation($orig_from$orig_date{
  196.     global $reply_citation_style$reply_citation_start$reply_citation_end;
  197.  
  198.     // FIXME: why object is rewritten with string.
  199.  
  200.     if (!is_object($orig_from)) {
  201.         $orig_from '';
  202.     else {
  203.         $orig_from decodeHeader($orig_from->getAddress(false),false,false,true);
  204.     }
  205.  
  206.     /* First, return an empty string when no citation style selected. */
  207.     if (($reply_citation_style == ''|| ($reply_citation_style == 'none')) {
  208.         return '';
  209.     }
  210.  
  211.     /* Make sure our final value isn't an empty string. */
  212.     if ($orig_from == ''{
  213.         return '';
  214.     }
  215.  
  216.     /* Otherwise, try to select the desired citation style. */
  217.     switch ($reply_citation_style{
  218.     case 'author_said':
  219.         /**
  220.          * To translators: %s is for author's name
  221.          */
  222.         $full_reply_citation sprintf(_("%s wrote:"),$orig_from);
  223.         break;
  224.     case 'quote_who':
  225.         $start '<' _("quote"' ' _("who"'="';
  226.         $end   '">';
  227.         $full_reply_citation $start $orig_from $end;
  228.         break;
  229.     case 'date_time_author':
  230.         /**
  231.          * To translators:
  232.          *  first %s is for date string, second %s is for author's name. Date uses
  233.          *  formating from "D, F j, Y g:i a" and "D, F j, Y H:i" translations.
  234.          * Example string:
  235.          *  "On Sat, December 24, 2004 23:59, Santa wrote:"
  236.          * If you have to put author's name in front of date string, check comments about
  237.          * argument swapping at http://www.php.net/sprintf
  238.          */
  239.         $full_reply_citation sprintf(_("On %s, %s wrote:")getLongDateString($orig_date)$orig_from);
  240.         break;
  241.     case 'user-defined':
  242.         $start $reply_citation_start .
  243.             ($reply_citation_start == '' '' ' ');
  244.         $end   $reply_citation_end;
  245.         $full_reply_citation $start $orig_from $end;
  246.         break;
  247.     default:
  248.         return '';
  249.     }
  250.  
  251.     /* Add line feed and return the citation string. */
  252.     return ($full_reply_citation "\n");
  253. }
  254.  
  255. function getforwardHeader($orig_header{
  256.     global $editor_size;
  257.  
  258.     $display array_("Subject"=> strlen(_("Subject")),
  259.             _("From")    => strlen(_("From")),
  260.             _("Date")    => strlen(_("Date")),
  261.             _("To")      => strlen(_("To")),
  262.             _("Cc")      => strlen(_("Cc")) );
  263.     $maxsize max($display);
  264.     $indent str_pad('',$maxsize+2);
  265.     foreach($display as $key => $val{
  266.         $display[$key$key .': 'str_pad(''$maxsize $val);
  267.     }
  268.     $from decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
  269.     $from str_replace('&nbsp;',' ',$from);
  270.     $to decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
  271.     $to str_replace('&nbsp;',' ',$to);
  272.     $subject decodeHeader($orig_header->subject,false,false,true);
  273.     $subject str_replace('&nbsp;',' ',$subject);
  274.     $bodyTop =  str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH.
  275.         "\n"$display[_("Subject")$subject "\n" .
  276.         $display[_("From")$from "\n" .
  277.         $display[_("Date")getLongDateString$orig_header->date$orig_header->date_unparsed )"\n" .
  278.         $display[_("To")$to "\n";
  279.     if ($orig_header->cc != array(&& $orig_header->cc !=''{
  280.         $cc decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
  281.         $cc str_replace('&nbsp;',' ',$cc);
  282.         $bodyTop .= $display[_("Cc").$cc "\n";
  283.     }
  284.     $bodyTop .= str_pad(''$editor_size -'-'.
  285.         "\n\n";
  286.     return $bodyTop;
  287. }
  288. /* ----------------------------------------------------------------------- */
  289.  
  290. /*
  291.  * If the session is expired during a post this restores the compose session
  292.  * vars.
  293.  */
  294. $session_expired false;
  295. if (sqsession_is_registered('session_expired_post')) {
  296.     sqgetGlobalVar('session_expired_post'$session_expired_postSQ_SESSION);
  297.     /*
  298.      * extra check for username so we don't display previous post data from
  299.      * another user during this session.
  300.      */
  301.     if ($session_expired_post['username'!= $username{
  302.         unset($session_expired_post);
  303.         sqsession_unregister('session_expired_post');
  304.         session_write_close();
  305.     else {
  306.         // these are the vars that we can set from the expired composed session
  307.         $compo_var_list array ('send_to''send_to_cc''body''mailbox',
  308.             'startMessage''passed_body''use_signature''signature',
  309.             'attachments''subject''newmail''send_to_bcc''passed_id'
  310.             'from_htmladdr_search''identity''draft_id''delete_draft'
  311.             'mailprio''edit_as_new''request_mdn''request_dr'
  312.             'composesession'/* Not used any more: 'compose_messsages', */);
  313.  
  314.         foreach ($compo_var_list as $var{
  315.             if isset($session_expired_post[$var]&& !isset($$var) ) {
  316.                 $$var $session_expired_post[$var];
  317.             }
  318.         }
  319.  
  320.         if (!empty($attachments)) 
  321.             $attachments unserialize($attachments);
  322.  
  323.         sqsession_register($composesession,'composesession');
  324.  
  325.         if (isset($send)) {
  326.             unset($send);
  327.         }
  328.         $session_expired true;
  329.     }
  330.     unset($session_expired_post);
  331.     sqsession_unregister('session_expired_post');
  332.     if (!isset($mailbox)) {
  333.         $mailbox '';
  334.     }
  335.     if ($compose_new_win == '1'{
  336.         compose_Header($color$mailbox);
  337.     else {
  338.         displayPageHeader($color$mailbox);
  339.     }
  340.     showInputForm($sessionfalse);
  341.     exit();
  342. }
  343.  
  344. if (!isset($composesession)) {
  345.     $composesession 0;
  346.     sqsession_register(0,'composesession');
  347. else {
  348.     $composesession = (int)$composesession;
  349. }
  350.  
  351. if (!isset($session|| (isset($newmessage&& $newmessage)) {
  352.     sqsession_unregister('composesession');
  353.     $session "$composesession+1;
  354.     $composesession $session;
  355.     sqsession_register($composesession,'composesession');
  356. }
  357. if (!empty($compose_messages[$session])) {
  358.     $composeMessage $compose_messages[$session];
  359. else {
  360.     $composeMessage new Message();
  361.     $rfc822_header new Rfc822Header();
  362.     $composeMessage->rfc822_header $rfc822_header;
  363.     $composeMessage->reply_rfc822_header '';
  364. }
  365.  
  366. // re-add attachments that were already in this message
  367. // FIXME: note that technically this is very bad form - 
  368. // should never directly manipulate an object like this
  369. if (!empty($attachments)) {
  370.     $attachments unserialize($attachments);
  371.     if (!empty($attachments&& is_array($attachments))
  372.         $composeMessage->entities $attachments;
  373. }
  374.  
  375. if (!isset($mailbox|| $mailbox == '' || ($mailbox == 'None')) {
  376.     $mailbox 'INBOX';
  377. }
  378.  
  379. if ($draft{
  380.  
  381.     // validate security token
  382.     //
  383.     sm_validate_security_token($submitted_token-1TRUE);
  384.  
  385.     /*
  386.      * Set $default_charset to correspond with the user's selection
  387.      * of language interface.
  388.      */
  389.     set_my_charset();
  390.     if (deliverMessage($composeMessagetrue)) {
  391.         showInputForm($session);
  392.         exit();
  393.     else {
  394.         $draft_message _("Draft Email Saved");
  395.         /* If this is a resumed draft, then delete the original */
  396.         if(isset($delete_draft)) {
  397.             if !isset($pageheader_sent|| !$pageheader_sent {
  398.                 Header("Location: $location/delete_message.php?mailbox=urlencode($draft_folder.
  399.                         "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes&smtoken=sm_generate_security_token());
  400.             else {
  401.                 echo '   <br><br><center><a href="' $location
  402.                     . "/delete_message.php?mailbox=" urlencode($draft_folder)
  403.                     . "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes&smtoken=sm_generate_security_token("\">"
  404.                     . _("Return"'</a></center>';
  405.             }
  406.             exit();
  407.         }
  408.         else {
  409.             if ($compose_new_win == '1'{
  410.                 if !isset($pageheader_sent|| !$pageheader_sent {
  411.                     Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
  412.                 else {
  413.                     echo '   <br><br><center><a href="' $location
  414.                         . "/compose.php?saved_draft=yes&session=$composesession\">"
  415.                         . _("Return"'</a></center>';
  416.                 }
  417.                 exit();
  418.             }
  419.             else {
  420.                 if !isset($pageheader_sent|| !$pageheader_sent {
  421.                     Header("Location: $location/right_main.php?mailbox=urlencode($draft_folder.
  422.                         "&sort=$sort&startMessage=1&note=".urlencode($draft_message));
  423.                 else {
  424.                     echo '   <br><br><center><a href="' $location
  425.                         . "/right_main.php?mailbox=" urlencode($draft_folder)
  426.                         . "&sort=$sort&startMessage=1&note=".urlencode($draft_message)
  427.                         . "\">" _("Return"'</a></center>';
  428.                 }
  429.                 exit();
  430.             }
  431.         }
  432.     }
  433. }
  434.  
  435. if ($send{
  436.  
  437.     // validate security token
  438.     //
  439.     sm_validate_security_token($submitted_token-1TRUE);
  440.  
  441.     if (isset($_FILES['attachfile']&&
  442.             $_FILES['attachfile']['tmp_name'&&
  443.             $_FILES['attachfile']['tmp_name'!= 'none'{
  444.         $AttachFailure saveAttachedFiles($session);
  445.     }
  446.     if (checkInput(false&& !isset($AttachFailure)) {
  447.         if ($mailbox == "All Folders"{
  448.             /* We entered compose via the search results page */
  449.             $mailbox 'INBOX'/* Send 'em to INBOX, that's safe enough */
  450.         }
  451.         $urlMailbox urlencode($mailbox);
  452.         if (isset($passed_id)) {
  453.             $passed_id 0;
  454.         }
  455.         /**
  456.          * Set $default_charset to correspond with the user's selection
  457.          * of language interface.
  458.          */
  459.         set_my_charset();
  460.         /**
  461.          * This is to change all newlines to \n
  462.          * We'll change them to \r\n later (in the sendMessage function)
  463.          */
  464.         $body str_replace("\r\n""\n"$body);
  465.         $body str_replace("\r""\n"$body);
  466.  
  467.         /**
  468.          * Rewrap $body so that no line is bigger than $editor_size
  469.          * This should only really kick in the sqWordWrap function
  470.          * if the browser doesn't support "VIRTUAL" as the wrap type.
  471.          */
  472.         $body explode("\n"$body);
  473.         $newBody '';
  474.         foreach ($body as $line{
  475.             if$line <> '-- ' {
  476.                 $line rtrim($line);
  477.             }
  478.             if (sq_strlen($line$default_charset<= $editor_size 1{
  479.                 $newBody .= $line "\n";
  480.             else {
  481.                 sqWordWrap($line$editor_size$default_charset);
  482.                 $newBody .= $line "\n";
  483.  
  484.             }
  485.  
  486.         }
  487.         $body $newBody;
  488.  
  489.         $Result deliverMessage($composeMessage);
  490.         do_hook('compose_send_after'$Result$composeMessage);
  491.         if ($Result{
  492.             showInputForm($session);
  493.             exit();
  494.         }
  495.  
  496.         /* if it is resumed draft, delete draft message */
  497.         if isset($delete_draft)) {
  498.             Header("Location: $location/delete_message.php?mailbox=urlencode$draft_folder ).
  499.                     "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes&smtoken=sm_generate_security_token());
  500.             exit();
  501.         }
  502.         if ($compose_new_win == '1'{
  503.  
  504.             Header("Location: $location/compose.php?mail_sent=yes");
  505.         }
  506.         else {
  507.             Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
  508.                     "&startMessage=$startMessage");
  509.         }
  510.     else {
  511.         if ($compose_new_win == '1'{
  512.             compose_Header($color$mailbox);
  513.         }
  514.         else {
  515.             displayPageHeader($color$mailbox);
  516.         }
  517.         if (isset($AttachFailure)) {
  518.             plain_error_message(_("Could not move/copy file. File not attached"),
  519.                     $color);
  520.         }
  521.         checkInput(true);
  522.         showInputForm($session);
  523.         /* sqimap_logout($imapConnection); */
  524.     }
  525. elseif (isset($html_addr_search_done)) {
  526.  
  527.     // validate security token
  528.     //
  529.     sm_validate_security_token($submitted_token-1TRUE);
  530.  
  531.     if ($compose_new_win == '1'{
  532.         compose_Header($color$mailbox);
  533.     }
  534.     else {
  535.         displayPageHeader($color$mailbox);
  536.     }
  537.  
  538.     if (isset($send_to_search&& is_array($send_to_search)) {
  539.         foreach ($send_to_search as $k => $v{
  540.             if (substr($k01== 'T'{
  541.                 if ($send_to{
  542.                     $send_to .= ', ';
  543.                 }
  544.                 $send_to .= $v;
  545.             }
  546.             elseif (substr($k01== 'C'{
  547.                 if ($send_to_cc{
  548.                     $send_to_cc .= ', ';
  549.                 }
  550.                 $send_to_cc .= $v;
  551.             }
  552.             elseif (substr($k01== 'B'{
  553.                 if ($send_to_bcc{
  554.                     $send_to_bcc .= ', ';
  555.                 }
  556.                 $send_to_bcc .= $v;
  557.             }
  558.         }
  559.     }
  560.     showInputForm($session);
  561. elseif (isset($html_addr_search)) {
  562.     if (isset($_FILES['attachfile']&&
  563.             $_FILES['attachfile']['tmp_name'&&
  564.             $_FILES['attachfile']['tmp_name'!= 'none'{
  565.         if(saveAttachedFiles($session)) {
  566.             plain_error_message(_("Could not move/copy file. File not attached")$color);
  567.         }
  568.     }
  569.     /*
  570.      * I am using an include so as to elminiate an extra unnecessary
  571.      * click.  If you can think of a better way, please implement it.
  572.      */
  573.     include_once('./addrbook_search_html.php');
  574. elseif (isset($attach)) {
  575.  
  576.     // validate security token
  577.     //
  578.     sm_validate_security_token($submitted_token-1TRUE);
  579.  
  580.     if (saveAttachedFiles($session)) {
  581.         plain_error_message(_("Could not move/copy file. File not attached")$color);
  582.     }
  583.     if ($compose_new_win == '1'{
  584.         compose_Header($color$mailbox);
  585.     else {
  586.         displayPageHeader($color$mailbox);
  587.     }
  588.     showInputForm($session);
  589. }
  590. elseif (isset($sigappend)) {
  591.  
  592.     // validate security token
  593.     //
  594.     sm_validate_security_token($submitted_token-1TRUE);
  595.  
  596.     $signature $idents[$identity]['signature'];
  597.     
  598.     $body .= "\n\n".($prefix_sig==true"-- \n":'').$signature;
  599.     if ($compose_new_win == '1'{
  600.         compose_Header($color$mailbox);
  601.     else {
  602.         displayPageHeader($color$mailbox);
  603.     }
  604.     showInputForm($session);
  605. elseif (isset($do_delete)) {
  606.  
  607.     // validate security token
  608.     //
  609.     sm_validate_security_token($submitted_token-1TRUE);
  610.  
  611.     if ($compose_new_win == '1'{
  612.         compose_Header($color$mailbox);
  613.     else {
  614.         displayPageHeader($color$mailbox);
  615.     }
  616.  
  617.     if (isset($delete&& is_array($delete)) {
  618.         foreach($delete as $index{
  619.             if (!empty($composeMessage->entities&& isset($composeMessage->entities[$index])) {
  620.                 $composeMessage->entities[$index]->purgeAttachments();
  621.                 // FIXME: one person reported that unset() didn't do anything at all here, so this is a work-around... but it triggers PHP notices if the unset() doesn't work, which should be fixed... but bigger question is if unset() doesn't work here, what about everywhere else?  Anyway, uncomment this if you think you need it
  622.                 //$composeMessage->entities[$index] = NULL;
  623.                 unset ($composeMessage->entities[$index]);
  624.             }
  625.         }
  626.         $new_entities array();
  627.         foreach ($composeMessage->entities as $entity{
  628.             $new_entities[$entity;
  629.         }
  630.         $composeMessage->entities $new_entities;
  631.     }
  632.     showInputForm($session);
  633. else {
  634.     /*
  635.      * This handles the default case as well as the error case
  636.      * (they had the same code) --> if (isset($smtpErrors))
  637.      */
  638.  
  639.     if ($compose_new_win == '1'{
  640.         compose_Header($color$mailbox);
  641.     else {
  642.         displayPageHeader($color$mailbox);
  643.     }
  644.  
  645.     $newmail true;
  646.  
  647.     if (!isset($passed_ent_id)) {
  648.         $passed_ent_id '';
  649.     }
  650.     if (!isset($passed_id)) {
  651.         $passed_id '';
  652.     }
  653.     if (!isset($mailbox)) {
  654.         $mailbox '';
  655.     }
  656.     if (!isset($action)) {
  657.         $action '';
  658.     }
  659.  
  660.     $values newMail($mailbox,$passed_id,$passed_ent_id$action$session);
  661.  
  662.     // forward as attachment - subject is in the message in session
  663.     //
  664.     if (sqgetGlobalVar('forward_as_attachment_init'$forward_as_attachment_initSQ_GET)
  665.      && $forward_as_attachment_init)
  666.         $subject $composeMessage->rfc822_header->subject;
  667.  
  668.     /* in case the origin is not read_body.php */
  669.     if (isset($send_to)) {
  670.         $values['send_to'$send_to;
  671.     }
  672.     if (isset($send_to_cc)) {
  673.         $values['send_to_cc'$send_to_cc;
  674.     }
  675.     if (isset($send_to_bcc)) {
  676.         $values['send_to_bcc'$send_to_bcc;
  677.     }
  678.     if (isset($subject)) {
  679.         $values['subject'$subject;
  680.     }
  681.     showInputForm($session$values);
  682. }
  683.  
  684. exit();
  685.  
  686. /**************** Only function definitions go below *************/
  687.  
  688.  
  689. /* This function is used when not sending or adding attachments */
  690. function newMail ($mailbox=''$passed_id=''$passed_ent_id=''$action=''$session=''{
  691.     global $editor_size$default_use_priority$body$idents,
  692.         $use_signature$composesession$data_dir$username,
  693.         $username$key$imapServerAddress$imapPort$imap_stream_options,
  694.         $composeMessage$body_quote$strip_sigs$do_not_reply_to_self;
  695.     global $languages$squirrelmail_language$default_charset;
  696.  
  697.     /*
  698.      * Set $default_charset to correspond with the user's selection
  699.      * of language interface. $default_charset global is not correct,
  700.      * if message is composed in new window.
  701.      */
  702.     set_my_charset();
  703.  
  704.     $send_to $send_to_cc $send_to_bcc $subject $identity '';
  705.     $mailprio 3;
  706.  
  707.     if ($passed_id{
  708.         $imapConnection sqimap_login($username$key$imapServerAddress,
  709.                 $imapPort0$imap_stream_options);
  710.  
  711.         sqimap_mailbox_select($imapConnection$mailbox);
  712.         $message sqimap_get_message($imapConnection$passed_id$mailbox);
  713.  
  714.         $body '';
  715.         if ($passed_ent_id{
  716.             /* redefine the messsage in case of message/rfc822 */
  717.             $message $message->getEntity($passed_ent_id);
  718.             /* message is an entity which contains the envelope and type0=message
  719.              * and type1=rfc822. The actual entities are childs from
  720.              * $message->entities[0]. That's where the encoding and is located
  721.              */
  722.  
  723.             $entities $message->entities[0]->findDisplayEntity
  724.                 (array()$alt_order array('text/plain'));
  725.             if (!count($entities)) {
  726.                 $entities $message->entities[0]->findDisplayEntity
  727.                     (array()$alt_order array('text/plain','text/html'));
  728.             }
  729.             $orig_header $message->rfc822_header/* here is the envelope located */
  730.             /* redefine the message for picking up the attachments */
  731.             $message $message->entities[0];
  732.  
  733.         else {
  734.             $entities $message->findDisplayEntity (array()$alt_order array('text/plain'));
  735.             if (!count($entities)) {
  736.                 $entities $message->findDisplayEntity (array()$alt_order array('text/plain','text/html'));
  737.             }
  738.             $orig_header $message->rfc822_header;
  739.         }
  740.  
  741.         $encoding $message->header->encoding;
  742.         $type0 $message->type0;
  743.         $type1 $message->type1;
  744.         foreach ($entities as $ent{
  745.             $unencoded_bodypart mime_fetch_body($imapConnection$passed_id$ent);
  746.             $body_part_entity $message->getEntity($ent);
  747.             $bodypart decodeBody($unencoded_bodypart,
  748.                     $body_part_entity->header->encoding);
  749.             if ($type1 == 'html'{
  750.                 $bodypart str_replace("\n"' '$bodypart);
  751.                 $bodypart preg_replace(array('/<p>/i','/<br\s*(\/)*>/i')"\n"$bodypart);
  752.                 $bodypart str_replace(array('&nbsp;','&gt;','&lt;'),array(' ','>','<'),$bodypart);
  753.                 $bodypart strip_tags($bodypart);
  754.             }
  755.             if (isset($languages[$squirrelmail_language]['XTRA_CODE']&&
  756.                     function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  757.                 if (mb_detect_encoding($bodypart!= 'ASCII'{
  758.                     $bodypart $languages[$squirrelmail_language]['XTRA_CODE']('decode'$bodypart);
  759.                 }
  760.             }
  761.  
  762.             // charset encoding in compose form stuff
  763.             if (isset($body_part_entity->header->parameters['charset'])) {
  764.                 $actual $body_part_entity->header->parameters['charset'];
  765.             else {
  766.                 $actual 'us-ascii';
  767.             }
  768.  
  769.             if $actual && is_conversion_safe($actual&& $actual != $default_charset){
  770.                 $bodypart charset_convert($actual,$bodypart,$default_charset,false);
  771.             }
  772.             // end of charset encoding in compose
  773.  
  774.             $body .= $bodypart;
  775.         }
  776.         if ($default_use_priority{
  777.             $mailprio substr($orig_header->priority,0,1);
  778.             if (!$mailprio{
  779.                 $mailprio 3;
  780.             }
  781.         else {
  782.             $mailprio '';
  783.         }
  784.  
  785.         $identity '';
  786.         $from_o $orig_header->from;
  787.         if (is_array($from_o)) {
  788.             if (isset($from_o[0])) {
  789.                 $from_o $from_o[0];
  790.             }
  791.         }
  792.         if (is_object($from_o)) {
  793.             $orig_from $from_o->getAddress();
  794.         else {
  795.             $orig_from '';
  796.         }
  797.  
  798.         $identities array();
  799.         if (count($idents1{
  800.             foreach($idents as $nr=>$data{
  801.                 $enc_from_name '"'.$data['full_name'].'" <'$data['email_address'].'>';
  802.                 $identities[$enc_from_name;
  803.             }
  804.  
  805.             $identity_match $orig_header->findAddress($identities);
  806.             if ($identity_match !== FALSE{
  807.                 $identity $identity_match;
  808.             }
  809.         }
  810.  
  811.         switch ($action{
  812.             case ('draft'):
  813.                 $use_signature FALSE;
  814.                 $composeMessage->rfc822_header $orig_header;
  815.                 $send_to decodeHeader($orig_header->getAddr_s('to'),false,false,true);
  816.                 $send_to_cc decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
  817.                 $send_to_bcc decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
  818.                 $identity 0;
  819.                 if (count($idents1{
  820.                     $identity_match $orig_header->findAddress($identitiesTRUE);
  821.                     if ($identity_match !== FALSE{
  822.                         $identity $identity_match;
  823.                     }
  824.                 }
  825.                 $subject decodeHeader($orig_header->subject,false,false,true);
  826.                 /* remember the references and in-reply-to headers in case of an reply */
  827.                 $composeMessage->rfc822_header->more_headers['References'$orig_header->references;
  828.                 $composeMessage->rfc822_header->more_headers['In-Reply-To'$orig_header->in_reply_to;
  829.                 $body_ary explode("\n"$body);
  830.                 $cnt count($body_ary;
  831.                 $body '';
  832.                 for ($i=0$i $cnt$i++{
  833.                     if (!preg_match('/^[>\s]*$/'$body_ary[$i])  || !$body_ary[$i]{
  834.                         sqWordWrap($body_ary[$i]$editor_size$default_charset );
  835.                         $body .= $body_ary[$i"\n";
  836.                     }
  837.                     unset($body_ary[$i]);
  838.                 }
  839.                 sqUnWordWrap($body);
  840.                 $composeMessage getAttachments($message$composeMessage$passed_id$entities$imapConnection);
  841.                 break;
  842.             case ('edit_as_new'):
  843.                 $send_to decodeHeader($orig_header->getAddr_s('to'),false,false,true);
  844.                 $send_to_cc decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
  845.                 $send_to_bcc decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
  846.                 $subject decodeHeader($orig_header->subject,false,false,true);
  847.                 $mailprio $orig_header->priority;
  848.                 $orig_from '';
  849.                 $composeMessage getAttachments($message$composeMessage$passed_id$entities$imapConnection);
  850.                 sqUnWordWrap($body);
  851.                 break;
  852.             case ('forward'):
  853.                 $send_to '';
  854.                 $subject decodeHeader($orig_header->subject,false,false,true);
  855.                 if ((substr(strtolower($subject)04!= 'fwd:'&&
  856.                     (substr(strtolower($subject)05!= '[fwd:'&&
  857.                     (substr(strtolower($subject)06!= '[ fwd:')) {
  858.                     $subject '[Fwd: ' $subject ']';
  859.                 }
  860.                 $body getforwardHeader($orig_header$body;
  861.                 $composeMessage getAttachments($message$composeMessage$passed_id$entities$imapConnection);
  862.                 $body "\n" $body;
  863.                 break;
  864.             case ('forward_as_attachment'):
  865.                 $subject decodeHeader($orig_header->subject,false,false,true);
  866.                 $subject trim($subject);
  867.                 if (substr(strtolower($subject)04!= 'fwd:'{
  868.                     $subject 'Fwd: ' $subject;
  869.                 }
  870.                 $composeMessage getMessage_RFC822_Attachment($message$composeMessage$passed_id$passed_ent_id$imapConnection);
  871.                 $body '';
  872.                 break;
  873.             case ('reply_all'):
  874.                 if(isset($orig_header->mail_followup_to&& $orig_header->mail_followup_to{
  875.                     $send_to $orig_header->getAddr_s('mail_followup_to');
  876.                 else {
  877.                     $send_to_cc replyAllString($orig_header);
  878.                     $send_to_cc decodeHeader($send_to_cc,false,false,true);
  879.                     $send_to_cc str_replace('""''"'$send_to_cc);
  880.                 }
  881.             case ('reply'):
  882.                 if (!$send_to{
  883.                     $send_to $orig_header->reply_to;
  884.                     if (is_array($send_to&& count($send_to)) {
  885.                         $send_to $orig_header->getAddr_s('reply_to'','FALSETRUE);
  886.                     else if (is_object($send_to)) /* unneccesarry, just for failsafe purpose */
  887.                         $send_to $orig_header->getAddr_s('reply_to'','FALSETRUE);
  888.                     else {
  889.                         $send_to $orig_header->getAddr_s('from'','FALSETRUE);
  890.                     }
  891.                 }
  892.                 $send_to decodeHeader($send_to,false,false,true);
  893.                 $send_to str_replace('""''"'$send_to);
  894.  
  895.  
  896.                 // If user doesn't want replies to her own messages
  897.                 // going back to herself (instead send again to the
  898.                 // original recipient of the message being replied to),
  899.                 // then iterate through identities, checking if the TO
  900.                 // field is one of them (if the reply is to ourselves)
  901.                 //
  902.                 // Note we don't bother if the original message doesn't
  903.                 // have anything in the TO field itself (because that's
  904.                 // what we use if we change the recipient to be that of
  905.                 // the previous message)
  906.                 //
  907.                 if ($do_not_reply_to_self && !empty($orig_header->to)) {
  908.  
  909.                     $orig_to '';
  910.  
  911.                     foreach($idents as $id{
  912.  
  913.                         if (!empty($id['email_address'])
  914.                          && strpos($send_to$id['email_address']!== FALSE{
  915.  
  916.                             // if this is a reply-all, the original recipient
  917.                             // is already in the CC field, so we can just blank
  918.                             // the recipient (TO field) (as long as the CC field
  919.                             // isn't empty that is)... but then move the CC into
  920.                             // the TO, so TO isn't empty
  921.                             //
  922.                             if ($action == 'reply_all' && !empty($send_to_cc)) {
  923.                                 $orig_to $send_to_cc;
  924.                                 $send_to_cc '';
  925.                                 break;
  926.                             }
  927.  
  928.                             $orig_to $orig_header->to;
  929.                             if (is_array($orig_to&& count($orig_to)) {
  930.                                 $orig_to $orig_header->getAddr_s('to'','FALSETRUE);
  931.                             else if (is_object($orig_to)) /* unneccesarry, just for failsafe purpose */
  932.                                 $orig_to $orig_header->getAddr_s('to'','FALSETRUE);
  933.                             else {
  934.                                 $orig_to '';
  935.                             }
  936.                             $orig_to decodeHeader($orig_to,false,false,true);
  937.                             $orig_to str_replace('""''"'$orig_to);
  938.  
  939.                             break;
  940.                         }
  941.                     }
  942.  
  943.                     // if the reply was addressed back to ourselves,
  944.                     // we will send it to the TO of the previous message
  945.                     //
  946.                     if (!empty($orig_to)) {
  947.  
  948.                         $send_to $orig_to;
  949.  
  950.                         // in this case, we also want to reset the FROM
  951.                         // identity as well (it should match the original
  952.                         // *FROM* header instead of TO or CC)
  953.                         //
  954.                         if (count($idents1{
  955.                             $identity '';
  956.                             foreach($idents as $i => $id{
  957.                                 if (!empty($id['email_address'])
  958.                                  && strpos($orig_from$id['email_address']!== FALSE{
  959.                                     $identity $i;
  960.                                     break;
  961.                                 }
  962.                             }
  963.                         }
  964.  
  965.                     }
  966.  
  967.                 }
  968.  
  969.  
  970.                 $subject decodeHeader($orig_header->subject,false,false,true);
  971.                 $subject trim($subject);
  972.                 if (substr(strtolower($subject)03!= 're:'{
  973.                     $subject 'Re: ' $subject;
  974.                 }
  975.                 /* this corrects some wrapping/quoting problems on replies */
  976.                 $rewrap_body explode("\n"$body);
  977.                 $from (is_array($orig_header->from&& !empty($orig_header->from)) $orig_header->from[0$orig_header->from;
  978.                 sqUnWordWrap($body);
  979.                 $body '';
  980.                 $cnt count($rewrap_body);
  981.                 for ($i=0;$i<$cnt;$i++{
  982.                     if ($strip_sigs && $rewrap_body[$i== '-- '{
  983.                         break;
  984.                     }
  985.                     sqWordWrap($rewrap_body[$i]$editor_size$default_charset);
  986.                     if (preg_match("/^(>+)/"$rewrap_body[$i]$matches)) {
  987.                         $gt $matches[1];
  988.                         $body .= $body_quote str_replace("\n""\n" $body_quote
  989.                               . "$gt "rtrim($rewrap_body[$i])) ."\n";
  990.                     else {
  991.                         $body .= $body_quote (!empty($body_quote' ' ''str_replace("\n""\n" $body_quote (!empty($body_quote' ' '')rtrim($rewrap_body[$i])) "\n";
  992.                     }
  993.                     unset($rewrap_body[$i]);
  994.                 }
  995.                 $body getReplyCitation($from $orig_header->date$body;
  996.                 $composeMessage->reply_rfc822_header $orig_header;
  997.  
  998.                 break;
  999.             default:
  1000.                 break;
  1001.         }
  1002.         session_write_close();
  1003.         sqimap_logout($imapConnection);
  1004.     }
  1005.     $ret array'send_to' => $send_to,
  1006.             'send_to_cc' => $send_to_cc,
  1007.             'send_to_bcc' => $send_to_bcc,
  1008.             'subject' => $subject,
  1009.             'mailprio' => $mailprio,
  1010.             'body' => $body,
  1011.             'identity' => $identity );
  1012.  
  1013.     return ($ret);
  1014. /* function newMail() */
  1015.  
  1016. function getAttachments($message&$composeMessage$passed_id$entities$imapConnection{
  1017.     global $attachment_dir$username$data_dir$squirrelmail_language$languages;
  1018.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  1019.     if (!count($message->entities||
  1020.             ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
  1021.         if !in_array($message->entity_id$entities&& $message->entity_id{
  1022.             switch ($message->type0{
  1023.                 case 'message':
  1024.                     if ($message->type1 == 'rfc822'{
  1025.                         $filename $message->rfc822_header->subject;
  1026.                         if ($filename == ""{
  1027.                             $filename "untitled-".$message->entity_id;
  1028.                         }
  1029.                         $filename .= '.eml';
  1030.                     else {
  1031.                         $filename $message->getFilename();
  1032.                     }
  1033.                     break;
  1034.                 default:
  1035.                     if (!$message->mime_header/* temporary hack */
  1036.                         $message->mime_header $message->header;
  1037.                     }
  1038.                     $filename $message->getFilename();
  1039.                     break;
  1040.             }
  1041.  
  1042.             $filename decodeHeader($filenamefalsefalsetrue);
  1043.             if (isset($languages[$squirrelmail_language]['XTRA_CODE']&&
  1044.                     function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  1045.                 $filename =  $languages[$squirrelmail_language]['XTRA_CODE']('encode'$filename);
  1046.             }
  1047.             $localfilename GenerateRandomString(32''7);
  1048.             $full_localfilename "$hashed_attachment_dir/$localfilename";
  1049.             while (file_exists($full_localfilename)) {
  1050.                 $localfilename GenerateRandomString(32''7);
  1051.                 $full_localfilename "$hashed_attachment_dir/$localfilename";
  1052.             }
  1053.             $fp fopen ("$hashed_attachment_dir/$localfilename"'wb');
  1054.  
  1055.             $message->att_local_name $localfilename;
  1056.  
  1057.             $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
  1058.                     $localfilename);
  1059.  
  1060.             /* Write Attachment to file 
  1061.                The function mime_print_body_lines writes directly to the 
  1062.                provided resource $fp. That prohibits large memory consumption in
  1063.                case of forwarding mail with large attachments.
  1064.             */
  1065.             mime_print_body_lines ($imapConnection$passed_id$message->entity_id$message->header->encoding$fp);
  1066.             fclose ($fp);
  1067.         }
  1068.     else {
  1069.         for ($i=0$entCount=count($message->entities)$i<$entCount;$i++{
  1070.             $composeMessage=getAttachments($message->entities[$i]$composeMessage$passed_id$entities$imapConnection);
  1071.         }
  1072.     }
  1073.     return $composeMessage;
  1074. }
  1075.  
  1076. function getMessage_RFC822_Attachment($message$composeMessage$passed_id,
  1077.         $passed_ent_id=''$imapConnection{
  1078.     global $attachment_dir$username$data_dir$uid_support;
  1079.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  1080.     if (!$passed_ent_id{
  1081.         $body_a sqimap_run_command($imapConnection,
  1082.                 'FETCH '.$passed_id.' RFC822',
  1083.                 TRUE$response$readmessage,
  1084.                 $uid_support);
  1085.     else {
  1086.         $body_a sqimap_run_command($imapConnection,
  1087.                 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
  1088.                 TRUE$response$readmessage$uid_support);
  1089.         $message $message->parent;
  1090.     }
  1091.     if ($response == 'OK'{
  1092.         $subject encodeHeader($message->rfc822_header->subject);
  1093.         array_shift($body_a);
  1094.         array_pop($body_a);
  1095.         $body implode(''$body_a"\r\n";
  1096.  
  1097.         $localfilename GenerateRandomString(32'FILE'7);
  1098.         $full_localfilename "$hashed_attachment_dir/$localfilename";
  1099.  
  1100.         $fp fopen($full_localfilename'w');
  1101.         fwrite ($fp$body);
  1102.         fclose($fp);
  1103.         $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
  1104.                 $localfilename);
  1105.     }
  1106.     return $composeMessage;
  1107. }
  1108.  
  1109. function showInputForm ($session$values=false{
  1110.     global $send_to$send_to_cc$body$startMessage$attachments,
  1111.         $session_expired,
  1112.         $passed_body$color$use_signature$signature$prefix_sig,
  1113.         $editor_size$editor_height$subject$newmail,
  1114.         $use_javascript_addr_book$send_to_bcc$passed_id$mailbox,
  1115.         $from_htmladdr_search$location_of_buttons$attachment_dir,
  1116.         $username$data_dir$identity$idents$draft_id$delete_draft,
  1117.         $mailprio$default_use_mdn$mdn_user_support$compose_new_win,
  1118.         $saved_draft$mail_sent$sig_first$edit_as_new$action,
  1119.         $username$composesession$default_charset$composeMessage,
  1120.         $javascript_on$compose_onsubmit;
  1121.  
  1122.     if ($javascript_on)
  1123.         $onfocus ' onfocus="alreadyFocused=true;"';
  1124.     else
  1125.         $onfocus '';
  1126.     
  1127.     if ($values{
  1128.         $send_to $values['send_to'];
  1129.         $send_to_cc $values['send_to_cc'];
  1130.         $send_to_bcc $values['send_to_bcc'];
  1131.         $subject $values['subject'];
  1132.         $mailprio $values['mailprio'];
  1133.         $body $values['body'];
  1134.         $identity = (int) $values['identity'];
  1135.     else {
  1136.         $send_to decodeHeader($send_totruefalse);
  1137.         $send_to_cc decodeHeader($send_to_cctruefalse);
  1138.         $send_to_bcc decodeHeader($send_to_bcctruefalse);
  1139.     }
  1140.  
  1141.     if ($use_javascript_addr_book{
  1142.         echo "\n"'<script language="JavaScript">'."\n<!--\n" .
  1143.             'function open_abook() { ' "\n" .
  1144.             '  var nwin = window.open("addrbook_popup.php","abookpopup",' .
  1145.             '"width=670,height=300,resizable=yes,scrollbars=yes");' "\n" .
  1146.             '  if((!nwin.opener) && (document.windows != null))' "\n" .
  1147.             '    nwin.opener = document.windows;' "\n" .
  1148.             "}\n" .
  1149.             "// -->\n</script>\n\n";
  1150.     }
  1151.  
  1152.     echo "\n" '<form name="compose" action="compose.php" method="post" ' .
  1153.         'enctype="multipart/form-data"';
  1154.  
  1155.     $compose_onsubmit array();
  1156.     do_hook('compose_form');
  1157.  
  1158.     // Plugins that use compose_form hook can add an array entry
  1159.     // to the globally scoped $compose_onsubmit; we add them up
  1160.     // here and format the form tag's full onsubmit handler.
  1161.     // Each plugin should use "return false" if they need to
  1162.     // stop form submission but otherwise should NOT use "return
  1163.     // true" to give other plugins the chance to do what they need
  1164.     // to do; SquirrelMail itself will add the final "return true".
  1165.     // Onsubmit text is enclosed inside of double quotes, so plugins
  1166.     // need to quote accordingly.
  1167.     //
  1168.     // Also, plugin authors should try to retain compatibility with
  1169.     // the Compose Extras plugin by resetting its compose submit
  1170.     // counter when preventing form submit.  Use this code:
  1171.     // if (your-code-here) { submit_count = 0; return false; }
  1172.     //
  1173.     if ($javascript_on{
  1174.         if (empty($compose_onsubmit))
  1175.             $compose_onsubmit array();
  1176.         else if (!is_array($compose_onsubmit))
  1177.             $compose_onsubmit array($compose_onsubmit);
  1178.  
  1179.         $onsubmit_text '';
  1180.         foreach ($compose_onsubmit as $text{
  1181.             $text trim($text);
  1182.             if (!empty($text)) {
  1183.                 if (substr($text-1!= ';' && substr($text-1!= '}')
  1184.                     $text .= '; ';
  1185.                 $onsubmit_text .= $text;
  1186.             }
  1187.         }
  1188.  
  1189.         if (!empty($onsubmit_text))
  1190.             echo ' onsubmit="' $onsubmit_text ' return true;"';
  1191.     }
  1192.  
  1193.     echo ">\n";
  1194.  
  1195.     echo addHidden('smtoken'sm_generate_security_token());
  1196.     echo addHidden('startMessage'$startMessage);
  1197.  
  1198.     if ($action == 'draft'{
  1199.         echo addHidden('delete_draft'$passed_id);
  1200.     }
  1201.     if (isset($delete_draft)) {
  1202.         echo addHidden('delete_draft'$delete_draft);
  1203.     }
  1204.     if (isset($session)) {
  1205.         echo addHidden('session'$session);
  1206.     }
  1207.  
  1208.     if (isset($passed_id)) {
  1209.         echo addHidden('passed_id'$passed_id);
  1210.     }
  1211.  
  1212.     if ($saved_draft == 'yes'{
  1213.         echo '<br /><center><b>'_("Your draft has been saved.").'</center></b>';
  1214.     }
  1215.     if ($mail_sent == 'yes'{
  1216.         echo '<br /><center><b>'_("Your mail has been sent.").'</center></b>';
  1217.     }
  1218.     if ($compose_new_win == '1'{
  1219.         echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
  1220.             '   <tr><td></td>'.html_tag'td''''right' ).
  1221.             '<input type="button" name="Close" onclick="return self.close()" value="'.
  1222.             _("Close").'" /></td></tr>'."\n";
  1223.     else {
  1224.         echo '<table align="center" cellspacing="0" border="0">' "\n";
  1225.     }
  1226.     if ($location_of_buttons == 'top'{
  1227.         showComposeButtonRow();
  1228.     }
  1229.     
  1230.     /* display select list for identities */
  1231.     if (count($idents1{
  1232.         echo '   <tr>' "\n" .
  1233.             html_tag'td''''right'$color[4]'width="10%"' .
  1234.             _("From:"'</td>' "\n" .
  1235.             html_tag'td''''left'$color[4]'width="90%"' .
  1236.             '         <select name="identity">' "\n";
  1237.  
  1238.         foreach($idents as $nr => $data{
  1239.             echo '<option value="' $nr '"';
  1240.             if (isset($identity&& $identity == $nr{
  1241.                 echo ' selected="selected"';
  1242.             }
  1243.             echo '>' sm_encode_html_special_chars(
  1244.                     $data['full_name'' <' .
  1245.                     $data['email_address''>'.
  1246.                 "</option>\n";
  1247.         }
  1248.  
  1249.         echo '</select>' "\n" .
  1250.             '      </td>' "\n" .
  1251.             '   </tr>' "\n";
  1252.     }
  1253.  
  1254.     echo '   <tr>' "\n" .
  1255.         html_tag'td''''right'$color[4]'width="10%"' .
  1256.         _("To:"'</td>' "\n" .
  1257.         html_tag'td''''left'$color[4]'width="90%"' .
  1258.         substr(addInput('send_to'$send_to60)0-3)$onfocus ' /><br />' "\n" .
  1259.         '      </td>' "\n" .
  1260.         '   </tr>' "\n" .
  1261.         '   <tr>' "\n" .
  1262.         html_tag'td''''right'$color[4.
  1263.         _("Cc:"'</td>' "\n" .
  1264.         html_tag'td''''left'$color[4.
  1265.         substr(addInput('send_to_cc'$send_to_cc60)0-3)$onfocus ' /><br />' "\n" .
  1266.         '      </td>' "\n" .
  1267.         '   </tr>' "\n" .
  1268.         '   <tr>' "\n" .
  1269.         html_tag'td''''right'$color[4.
  1270.         _("Bcc:"'</td>' "\n" .
  1271.         html_tag'td''''left'$color[4.
  1272.         substr(addInput('send_to_bcc'$send_to_bcc60)0-3)$onfocus ' /><br />' "\n" .
  1273.         '      </td>' "\n" .
  1274.         '   </tr>' "\n" .
  1275.         '   <tr>' "\n" .
  1276.         html_tag'td''''right'$color[4.
  1277.         _("Subject:"'</td>' "\n" .
  1278.         html_tag'td''''left'$color[4"\n";
  1279.     echo '         '.substr(addInput('subject'$subject60)0-3)$onfocus .
  1280.         ' />      </td>' "\n" .
  1281.         '   </tr>' "\n\n";
  1282.  
  1283.     if ($location_of_buttons == 'between'{
  1284.         showComposeButtonRow();
  1285.     }
  1286.  
  1287.     /* why this distinction? */
  1288.     if ($compose_new_win == '1'{
  1289.         echo '   <tr>' "\n" .
  1290.             '      <td bgcolor="' $color[0'" colspan="2" align="center">' "\n" .
  1291.             '         <textarea name="body" id="body" rows="' . (int)$editor_height .
  1292.             '" cols="' . (int)$editor_size '" wrap="virtual"' $onfocus '>';
  1293.     }
  1294.     else {
  1295.         echo '   <tr>' "\n" .
  1296.             '      <td bgcolor="' $color[4'" colspan="2">' "\n" .
  1297.             '         &nbsp;&nbsp;<textarea name="body" id="body" rows="' . (int)$editor_height .
  1298.             '" cols="' . (int)$editor_size '" wrap="virtual"' $onfocus '>';
  1299.     }
  1300.  
  1301.     if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
  1302.         $signature $idents[$identity]['signature'];
  1303.  
  1304.         if ($sig_first == '1'{
  1305.             if ($default_charset == 'iso-2022-jp'{
  1306.                 echo "\n\n".($prefix_sig==true"-- \n":'').mb_convert_encoding($signature'EUC-JP');
  1307.             else {
  1308.                 echo "\n\n".($prefix_sig==true"-- \n":'').decodeHeader($signature,false,false,true);
  1309.             }
  1310.             echo "\n\n".sm_encode_html_special_chars(decodeHeader($body,false,false,true));
  1311.         }
  1312.         else {
  1313.             echo "\n\n".sm_encode_html_special_chars(decodeHeader($body,false,false,true));
  1314.             if ($default_charset == 'iso-2022-jp'{
  1315.                 echo "\n\n".($prefix_sig==true"-- \n":'').mb_convert_encoding($signature'EUC-JP');
  1316.             }else{
  1317.                 echo "\n\n".($prefix_sig==true"-- \n":'').decodeHeader($signature,false,false,true);
  1318.             }
  1319.         }
  1320.     else {
  1321.         echo sm_encode_html_special_chars(decodeHeader($body,false,false,true));
  1322.     }
  1323.     echo '</textarea><br />' "\n" .
  1324.         '      </td>' "\n" .
  1325.         '   </tr>' "\n";
  1326.  
  1327.  
  1328.     if ($location_of_buttons == 'bottom'{
  1329.         showComposeButtonRow();
  1330.     else {
  1331.         echo '   <tr>' "\n" .
  1332.             html_tag'td''''right''''colspan="2"' "\n" .
  1333.             '         ' addSubmit(_("Send")'send').
  1334.             '         &nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' "\n" .
  1335.             '      </td>' "\n" .
  1336.             '   </tr>' "\n";
  1337.     }
  1338.  
  1339.     // composeMessage can be empty when coming from a restored session
  1340.     if (is_object($composeMessage&& $composeMessage->entities
  1341.         $attach_array $composeMessage->entities;
  1342.     if ($session_expired && !empty($attachments&& is_array($attachments))
  1343.         $attach_array $attachments;
  1344.  
  1345.     /* This code is for attachments */
  1346.     if ((bool) ini_get('file_uploads')) {
  1347.  
  1348.         /* Calculate the max size for an uploaded file.
  1349.          * This is advisory for the user because we can't actually prevent
  1350.          * people to upload too large files. */
  1351.         $sizes array();
  1352.         /* php.ini vars which influence the max for uploads */
  1353.         $configvars array('post_max_size''memory_limit''upload_max_filesize');
  1354.         foreach($configvars as $var{
  1355.             /* skip 0 or empty values, and -1 which means 'unlimited' */
  1356.             if$size getByteSize(ini_get($var)) ) {
  1357.                 if $size != '-1' {
  1358.                     $sizes[$size;
  1359.                 }
  1360.             }
  1361.         }
  1362.  
  1363.         if(count($sizes0{
  1364.             $maxsize_text '(max.&nbsp;' show_readable_sizemin$sizes ) ) ')';
  1365.             $maxsize_input addHidden('MAX_FILE_SIZE'min$sizes ));
  1366.         else {
  1367.             $maxsize_text $maxsize_input '';
  1368.         }
  1369.         echo '   <tr>' "\n" .
  1370.             '      <td colspan="2">' "\n" .
  1371.             '         <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
  1372.             ' border="0" bgcolor="'.$color[9].'">' "\n" .
  1373.             '            <tr>' "\n" .
  1374.             '               <td>' "\n" .
  1375.             '                 <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
  1376.             ' border="0">' "\n" .
  1377.             '                    <tr>' "\n" .
  1378.             html_tag'td''''right''''valign="middle"' .
  1379.             _("Attach:"'</td>' "\n" .
  1380.             html_tag'td''''left''''valign="middle"' .
  1381.             $maxsize_input .
  1382.             '                          <input name="attachfile" size="48" type="file" />' "\n" .
  1383.             '                          &nbsp;&nbsp;<input type="submit" name="attach"' .
  1384.             ' value="' _("Add".'" />' "\n" .
  1385.             $maxsize_text .
  1386.             '                       </td>' "\n" .
  1387.             '                    </tr>' "\n";
  1388.  
  1389.         $s_a array();
  1390.         global $username$attachment_dir;
  1391.         $hashed_attachment_dir getHashedDir($username$attachment_dir);
  1392.         if (!empty($attach_array)) {
  1393.             $attachment_count 0;
  1394.             foreach ($attach_array as $key => $attachment{
  1395.                 $attached_file $attachment->att_local_name;
  1396.                 if ($attachment->att_local_name || $attachment->body_part{
  1397.                     $attached_filename decodeHeader($attachment->mime_header->getParameter('name'));
  1398.                     $type $attachment->mime_header->type0.'/'.
  1399.                         $attachment->mime_header->type1;
  1400.  
  1401.                     $s_a['<table bgcolor="'.$color[0].
  1402.                         '" border="0"><tr><td>'.
  1403.                         addCheckBox('delete[]'FALSE$key'id="delete' . ++$attachment_count '"').
  1404.                         "</td><td><label for='delete" $attachment_count "'>\n" $attached_filename .
  1405.                         '</label></td><td><label for="delete' $attachment_count '">-</label></td><td><label for="delete' $attachment_count '"> ' $type '</label></td><td><label for="delete' $attachment_count '">('.
  1406.                         show_readable_sizefilesize$hashed_attachment_dir '/' $attached_file ) ) .
  1407.                         ')</label></td></tr></table>'."\n";
  1408.                 }
  1409.             }
  1410.         }
  1411.         if (count($s_a)) {
  1412.             foreach ($s_a as $s{
  1413.                 echo '<tr>' html_tag'td''''left'$color[0]'colspan="2"' $s .'</td></tr>';
  1414.             }
  1415.             echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
  1416.                 _("Delete selected attachments""\" />\n" .
  1417.                 '</td></tr>';
  1418.         }
  1419.         echo '                  </table>' "\n" .
  1420.             '               </td>' "\n" .
  1421.             '            </tr>' "\n" .
  1422.             '         </table>' "\n" .
  1423.             '      </td>' "\n" .
  1424.             '   </tr>' "\n";
  1425.     // End of file_uploads if-block
  1426.     /* End of attachment code */
  1427.     echo '</table>' "\n" .
  1428.         addHidden('username'$username).
  1429.         addHidden('smaction'$action).
  1430.         addHidden('mailbox'$mailbox);
  1431.     sqgetGlobalVar('QUERY_STRING'$queryStringSQ_SERVER);
  1432.     /*
  1433.        store the complete ComposeMessages array in a hidden input value
  1434.        so we can restore them in case of a session timeout.
  1435.      */
  1436.     echo addHidden('composesession'$composesession).
  1437.         addHidden('querystring'$queryString).
  1438.         (!empty($attach_array?
  1439.         addHidden('attachments'serialize($attach_array)) '').
  1440.         "</form>\n";
  1441.     if (!(bool) ini_get('file_uploads')) {
  1442.         /* File uploads are off, so we didn't show that part of the form.
  1443.            To avoid bogus bug reports, tell the user why. */
  1444.         echo '<p style="text-align:center">'
  1445.             . _("Because PHP file uploads are turned off, you can not attach files to this message. Please see your system administrator for details.")
  1446.             . "</p>\r\n";
  1447.     }
  1448.  
  1449.     do_hook('compose_bottom');
  1450.     echo '</body></html>' "\n";
  1451. }
  1452.  
  1453.  
  1454. function showComposeButtonRow({
  1455.     global $use_javascript_addr_book$save_as_draft,
  1456.         $default_use_priority$mailprio$default_use_mdn,
  1457.         $request_mdn$request_dr,
  1458.         $data_dir$username;
  1459.  
  1460.     echo '   <tr>' "\n" .
  1461.         '      <td></td>' "\n" .
  1462.         '      <td>' "\n";
  1463.     if ($default_use_priority{
  1464.         if(!isset($mailprio)) {
  1465.             $mailprio '3';
  1466.         }
  1467.         echo '          ' _("Priority".
  1468.             addSelect('mailprio'array(
  1469.                         '1' => _("High"),
  1470.                         '3' => _("Normal"),
  1471.                         '5' => _("Low") )$mailprioTRUE);
  1472.     }
  1473.     $mdn_user_support=getPref($data_dir$username'mdn_user_support',$default_use_mdn);
  1474.     if ($default_use_mdn{
  1475.         if ($mdn_user_support{
  1476.             echo '          ' _("Receipt".': '.
  1477.                 addCheckBox('request_mdn'$request_mdn == '1''1''id="request_mdn"''<label for="request_mdn">' _("On Read"'</label>' .
  1478.                 addCheckBox('request_dr',  $request_dr  == '1''1''id="request_dr"''<label for="request_dr">' _("On Delivery"'</label>';
  1479.         }
  1480.     }
  1481.  
  1482.     echo '      </td>' "\n" .
  1483.         '   </tr>' "\n" .
  1484.         '   <tr>'  "\n" .
  1485.         '      <td></td>' "\n" .
  1486.         '      <td>' "\n" .
  1487.         '         <input type="submit" name="sigappend" value="' _("Signature"'" />' "\n";
  1488.     if ($use_javascript_addr_book{
  1489.         echo "         <script language=\"JavaScript\"><!--\n document.write(\"".
  1490.             "            <input type=button value=\\\""._("Addresses").
  1491.             "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
  1492.             "            // --></script><noscript>\n".
  1493.             '            <input type="submit" name="html_addr_search" value="'.
  1494.             _("Addresses").'" />'.
  1495.             "         </noscript>\n";
  1496.     else {
  1497.         echo '         <input type="submit" name="html_addr_search" value="'.
  1498.             _("Addresses").'" />' "\n";
  1499.     }
  1500.  
  1501.     if ($save_as_draft{
  1502.         echo '         <input type="submit" name ="draft" value="' _("Save Draft""\" />\n";
  1503.     }
  1504.  
  1505.     echo '         <input type="submit" name="send" value="'_("Send"'" />' "\n";
  1506.     do_hook('compose_button_row');
  1507.  
  1508.     echo '      </td>' "\n" .
  1509.         '   </tr>' "\n\n";
  1510. }
  1511.  
  1512. function checkInput ($show{
  1513.     /*
  1514.      * I implemented the $show variable because the error messages
  1515.      * were getting sent before the page header.  So, I check once
  1516.      * using $show=false, and then when i'm ready to display the error
  1517.      * message, show=true
  1518.      */
  1519.     global $body$send_to$send_to_cc$send_to_bcc$subject$color;
  1520.  
  1521.     $send_to trim($send_to);
  1522.     $send_to_cc trim($send_to_cc);
  1523.     $send_to_bcc trim($send_to_bcc);
  1524.     if (empty($send_to&& empty($send_to_cc&& empty($send_to_bcc)) {
  1525.         if ($show{
  1526.             plain_error_message(_("You have not filled in the \"To:\" field.")$color);
  1527.         }
  1528.         return false;
  1529.     }
  1530.     return true;
  1531. /* function checkInput() */
  1532.  
  1533.  
  1534. /* True if FAILURE */
  1535. function saveAttachedFiles($session{
  1536.     global $_FILES$attachment_dir$username,
  1537.         $data_dir$composeMessage;
  1538.  
  1539.     /* get out of here if no file was attached at all */
  1540.     if (is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
  1541.         return true;
  1542.     }
  1543.  
  1544.     $hashed_attachment_dir getHashedDir($username$attachment_dir);
  1545.     $localfilename GenerateRandomString(32''7);
  1546.     $full_localfilename "$hashed_attachment_dir/$localfilename";
  1547.     while (file_exists($full_localfilename)) {
  1548.         $localfilename GenerateRandomString(32''7);
  1549.         $full_localfilename "$hashed_attachment_dir/$localfilename";
  1550.     }
  1551.  
  1552.     // FIXME: we SHOULD prefer move_uploaded_file over rename because
  1553.     // m_u_f works better with restricted PHP installs (safe_mode, open_basedir)
  1554.     if (!@rename($_FILES['attachfile']['tmp_name']$full_localfilename)) {
  1555.         if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
  1556.             return true;
  1557.         }
  1558.     }
  1559.     $type strtolower($_FILES['attachfile']['type']);
  1560.     $name $_FILES['attachfile']['name'];
  1561.     $composeMessage->initAttachment($type$name$localfilename);
  1562. }
  1563.  
  1564. /* parse values like 8M and 2k into bytes */
  1565. function getByteSize($ini_size{
  1566.  
  1567.     if(!$ini_size{
  1568.         return FALSE;
  1569.     }
  1570.  
  1571.     $ini_size trim($ini_size);
  1572.  
  1573.     // if there's some kind of letter at the end of the string we need to multiply.
  1574.     if(!is_numeric(substr($ini_size-1))) {
  1575.  
  1576.         switch(strtoupper(substr($ini_size-1))) {
  1577.             case 'G':
  1578.                 $bytesize 1073741824;
  1579.                 break;
  1580.             case 'M':
  1581.                 $bytesize 1048576;
  1582.                 break;
  1583.             case 'K':
  1584.                 $bytesize 1024;
  1585.                 break;
  1586.         }
  1587.  
  1588.         return ($bytesize * (int)substr($ini_size0-1));
  1589.     }
  1590.  
  1591.     return $ini_size;
  1592. }
  1593.  
  1594.  
  1595. /**
  1596.  * temporary function to make use of the deliver class.
  1597.  * In the future the responsible backend should be automaticly loaded
  1598.  * and conf.pl should show a list of available backends.
  1599.  * The message also should be constructed by the message class.
  1600.  *
  1601.  * @param object $composeMessage The message being sent.  Please note
  1602.  *                                that it is passed by reference and
  1603.  *                                will be returned modified, with additional
  1604.  *                                headers, such as Message-ID, Date, In-Reply-To,
  1605.  *                                References, and so forth.
  1606.  *
  1607.  * @return boolean FALSE if delivery failed, or some non-FALSE value
  1608.  *                  upon success.
  1609.  *
  1610.  */
  1611. function deliverMessage(&$composeMessage$draft=false{
  1612.     global $send_to$send_to_cc$send_to_bcc$mailprio$subject$body,
  1613.         $username$popuser$usernamedata$identity$idents$data_dir,
  1614.         $request_mdn$request_dr$default_charset$color$useSendmail,
  1615.         $domain$action$default_move_to_sent$move_to_sent;
  1616.     global $imapServerAddress$imapPort$imap_stream_options$sent_folder$key;
  1617.  
  1618.     $rfc822_header $composeMessage->rfc822_header;
  1619.  
  1620.     $abook addressbook_init(falsetrue);
  1621.     $rfc822_header->to $rfc822_header->parseAddress($send_to,truearray()''$domainarray(&$abook,'lookup'));
  1622.     $rfc822_header->cc $rfc822_header->parseAddress($send_to_cc,true,array()'',$domainarray(&$abook,'lookup'));
  1623.     $rfc822_header->bcc $rfc822_header->parseAddress($send_to_bcc,truearray()'',$domainarray(&$abook,'lookup'));
  1624.     $rfc822_header->priority $mailprio;
  1625.     $rfc822_header->subject $subject;
  1626.  
  1627.     $special_encoding='';
  1628.     if (strtolower($default_charset== 'iso-2022-jp'{
  1629.         if (mb_detect_encoding($body== 'ASCII'{
  1630.             $special_encoding '8bit';
  1631.         else {
  1632.             $body mb_convert_encoding($body'JIS');
  1633.             $special_encoding '7bit';
  1634.         }
  1635.     }
  1636.     $composeMessage->setBody($body);
  1637.  
  1638.     if (preg_match('|^([^@%/]+)[@%/](.+)$|'$username$usernamedata)) {
  1639.         $popuser $usernamedata[1];
  1640.         $domain  $usernamedata[2];
  1641.         unset($usernamedata);
  1642.     else {
  1643.         $popuser $username;
  1644.     }
  1645.     $reply_to '';
  1646.     $from_mail $idents[$identity]['email_address'];
  1647.     $full_name $idents[$identity]['full_name'];
  1648.     $reply_to  $idents[$identity]['reply_to'];
  1649.     if (!$from_mail{
  1650.         $from_mail "$popuser@$domain";
  1651.     }
  1652.     $rfc822_header->from $rfc822_header->parseAddress($from_mail,true);
  1653.     if (!$rfc822_header->from[0]->host$rfc822_header->from[0]->host $domain;
  1654.     if ($full_name{
  1655.         $from $rfc822_header->from[0];
  1656.         $full_name_encoded encodeHeader('"' $full_name '"');
  1657.         if ($full_name_encoded != $full_name{
  1658.             $from_addr $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>';
  1659.         else {
  1660.             $from_addr '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>';
  1661.         }
  1662.         $rfc822_header->from $rfc822_header->parseAddress($from_addr,true);
  1663.     }
  1664.     if ($reply_to{
  1665.         $rfc822_header->reply_to $rfc822_header->parseAddress($reply_to,true);
  1666.         if (!$rfc822_header->reply_to[0]->host$rfc822_header->reply_to[0]->host $domain;
  1667.     }
  1668.     /* Receipt: On Read */
  1669.     if (isset($request_mdn&& $request_mdn{
  1670.         $rfc822_header->dnt $rfc822_header->parseAddress($from_mail,true);
  1671.     }
  1672.  
  1673.     /* Receipt: On Delivery */
  1674.     if (isset($request_dr&& $request_dr{
  1675.         $rfc822_header->more_headers['Return-Receipt-To'$from_mail;
  1676.     }
  1677.  
  1678.     /* multipart messages */
  1679.     if (count($composeMessage->entities)) {
  1680.         $message_body new Message();
  1681.         $message_body->body_part $composeMessage->body_part;
  1682.         $composeMessage->body_part '';
  1683.         $mime_header new MessageHeader;
  1684.         $mime_header->type0 'text';
  1685.         $mime_header->type1 'plain';
  1686.         if ($special_encoding{
  1687.             $mime_header->encoding $special_encoding;
  1688.         else {
  1689.             $mime_header->encoding '8bit';
  1690.         }
  1691.         if ($default_charset{
  1692.             $mime_header->parameters['charset'$default_charset;
  1693.         }
  1694.         $message_body->mime_header $mime_header;
  1695.         array_unshift($composeMessage->entities$message_body);
  1696.         $content_type new ContentType('multipart/mixed');
  1697.     else {
  1698.         $content_type new ContentType('text/plain');
  1699.         if ($special_encoding{
  1700.             $rfc822_header->encoding $special_encoding;
  1701.         else {
  1702.             $rfc822_header->encoding '8bit';
  1703.         }
  1704.         if ($default_charset{
  1705.             $content_type->properties['charset']=$default_charset;
  1706.         }
  1707.     }
  1708.  
  1709.     $rfc822_header->content_type $content_type;
  1710.     $composeMessage->rfc822_header $rfc822_header;
  1711.     if ($action == 'reply' || $action == 'reply_all'{
  1712.         global $passed_id$passed_ent_id;
  1713.         $reply_id $passed_id;
  1714.         $reply_ent_id $passed_ent_id;
  1715.     else {
  1716.         $reply_id '';
  1717.         $reply_ent_id '';
  1718.     }
  1719.  
  1720.     /* Here you can modify the message structure just before we hand
  1721.        it over to deliver */
  1722.     $hookReturn do_hook('compose_send'$composeMessage);
  1723.     /* Get any changes made by plugins to $composeMessage. */
  1724.     if is_object($hookReturn[1]) ) {
  1725.         $composeMessage $hookReturn[1];
  1726.     }
  1727.  
  1728.     if (!$useSendmail && !$draft{
  1729.         require_once(SM_PATH 'class/deliver/Deliver_SMTP.class.php');
  1730.         $deliver new Deliver_SMTP();
  1731.         global $smtpServerAddress$smtpPort$smtp_stream_options,
  1732.                $pop_before_smtp$pop_before_smtp_host;
  1733.  
  1734.         $authPop (isset($pop_before_smtp&& $pop_before_smtptrue false;
  1735.         
  1736.         $user '';
  1737.         $pass '';
  1738.         if (empty($pop_before_smtp_host))
  1739.             $pop_before_smtp_host $smtpServerAddress;
  1740.         
  1741.         get_smtp_user($user$pass);
  1742.  
  1743.         $stream $deliver->initStream($composeMessage,$domain,0,
  1744.                 $smtpServerAddress$smtpPort$user$pass$authPop$pop_before_smtp_host$smtp_stream_options);
  1745.     elseif (!$draft{
  1746.         require_once(SM_PATH 'class/deliver/Deliver_SendMail.class.php');
  1747.         global $sendmail_path$sendmail_args;
  1748.         // Check for outdated configuration
  1749.         if (!isset($sendmail_args)) {
  1750.             if ($sendmail_path=='/var/qmail/bin/qmail-inject'{
  1751.                 $sendmail_args '';
  1752.             else {
  1753.                 $sendmail_args '-i -t';
  1754.             }
  1755.         }
  1756.         $deliver new Deliver_SendMail(array('sendmail_args'=>$sendmail_args));
  1757.         $stream $deliver->initStream($composeMessage,$sendmail_path);
  1758.     elseif ($draft{
  1759.         global $draft_folder;
  1760.         $imap_stream sqimap_login($username$key$imapServerAddress,
  1761.                 $imapPort0$imap_stream_options);
  1762.         if (sqimap_mailbox_exists ($imap_stream$draft_folder)) {
  1763.             require_once(SM_PATH 'class/deliver/Deliver_IMAP.class.php');
  1764.             $imap_deliver new Deliver_IMAP();
  1765.             $succes $imap_deliver->mail($composeMessage$imap_stream$reply_id$reply_ent_id$imap_stream$draft_folder);
  1766.             sqimap_logout($imap_stream);
  1767.             unset ($imap_deliver);
  1768.             $composeMessage->purgeAttachments();
  1769.             return $succes;
  1770.         else {
  1771.             $msg  '<br />'.sprintf(_("Error: Draft folder %s does not exist."),
  1772.                 sm_encode_html_special_chars($draft_folder));
  1773.             plain_error_message($msg$color);
  1774.             return false;
  1775.         }
  1776.     }
  1777.     $succes false;
  1778.     if ($stream{
  1779.         $deliver->mail($composeMessage$stream$reply_id$reply_ent_id);
  1780.         $succes $deliver->finalizeStream($stream);
  1781.     }
  1782.     if (!$succes{
  1783.         $msg _("Message not sent."' ' _("Server replied:")
  1784.              . "\n<blockquote>\n"
  1785.              . (isset($deliver->dlv_msg$deliver->dlv_msg '')
  1786.              . '<br />'
  1787.              . (isset($deliver->dlv_ret_nr$deliver->dlv_ret_nr ' ' '')
  1788.              . (isset($deliver->dlv_server_msg$deliver->dlv_server_msg '')
  1789.              . "</blockquote>\n\n";
  1790.         plain_error_message($msg$color);
  1791.     else {
  1792.         unset ($deliver);
  1793.         $imap_stream sqimap_login($username$key$imapServerAddress$imapPort0$imap_stream_options);
  1794.  
  1795.  
  1796.         // mark original message as having been replied to if applicable
  1797.         global $passed_id$mailbox$action;
  1798.         if ($action == 'reply' || $action == 'reply_all'{
  1799.             sqimap_mailbox_select ($imap_stream$mailbox);
  1800.             sqimap_messages_flag ($imap_stream$passed_id$passed_id'Answered'false);
  1801.         }
  1802.  
  1803.  
  1804.         // copy message to sent folder
  1805.         $move_to_sent getPref($data_dir,$username,'move_to_sent');
  1806.         if (isset($default_move_to_sent&& ($default_move_to_sent != 0)) {
  1807.             $svr_allow_sent true;
  1808.         else {
  1809.             $svr_allow_sent false;
  1810.         }
  1811.  
  1812.         if (isset($sent_folder&& (($sent_folder != ''|| ($sent_folder != 'none'))
  1813.                 && sqimap_mailbox_exists$imap_stream$sent_folder)) {
  1814.             $fld_sent true;
  1815.         else {
  1816.             $fld_sent false;
  1817.         }
  1818.  
  1819.         if ((isset($move_to_sent&& ($move_to_sent != 0)) || (!isset($move_to_sent))) {
  1820.             $lcl_allow_sent true;
  1821.         else {
  1822.             $lcl_allow_sent false;
  1823.         }
  1824.  
  1825.         if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent|| ($fld_sent && $lcl_allow_sent)) {
  1826.             require_once(SM_PATH 'class/deliver/Deliver_IMAP.class.php');
  1827.             $imap_deliver new Deliver_IMAP();
  1828.             $imap_deliver->mail($composeMessage$imap_stream$reply_id$reply_ent_id$imap_stream$sent_folder);
  1829.             unset ($imap_deliver);
  1830.         }
  1831.         $composeMessage->purgeAttachments();
  1832.         sqimap_logout($imap_stream);
  1833.     }
  1834.     return $succes;
  1835. }

Documentation generated on Thu, 18 Sep 2014 04:20:32 +0200 by phpDocumentor 1.4.3