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

Documentation generated on Sat, 07 Oct 2006 16:30:19 +0300 by phpDocumentor 1.3.0RC6