do not special case a folder named 'None'. There's no reason
[squirrelmail.git] / src / compose.php
index 032c95f7534d2f0c37c2fccfaabe69702730cdcc..2da86907a31a37c39825073da31a4c9af906bf4b 100644 (file)
@@ -10,7 +10,7 @@
  *    - Send mail
  *    - Save As Draft
  *
- * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @copyright © 1999-2007 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -147,8 +147,8 @@ function replyAllString($header) {
     /**
      * 1) Remove the addresses we'll be sending the message 'to'
      */
-    if (isset($header->replyto)) {
-        $excl_ar = $header->getAddr_a('replyto');
+    if (isset($header->reply_to)) {
+        $excl_ar = $header->getAddr_a('reply_to');
     }
     /**
      * 2) Remove our identities from the CC list (they still can be in the
@@ -285,7 +285,7 @@ function getforwardHeader($orig_header) {
     $bodyTop =  sq_str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH,$default_charset) .
         "\n". $display[_("Subject")] . $subject . "\n" .
         $display[_("From")] . $from . "\n" .
-        $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
+        $display[_("Date")] . getLongDateString( $orig_header->date, $orig_header->date_unparsed ). "\n" .
         $display[_("To")] . $to . "\n";
     if ($orig_header->cc != array() && $orig_header->cc !='') {
         $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
@@ -322,7 +322,7 @@ if (sqsession_is_registered('session_expired_post')) {
 
         foreach ($compo_var_list as $var) {
             if ( isset($session_expired_post[$var]) && !isset($$var) ) {
-               $$var = $session_expired_post[$var];
+                $$var = $session_expired_post[$var];
             }
         }
 
@@ -383,7 +383,7 @@ if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)
     $composeMessage=$compose_messages[$session];
 }
 
-if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
+if (empty($mailbox)) {
     $mailbox = 'INBOX';
 }
 
@@ -398,7 +398,6 @@ if ($draft) {
         showInputForm($session);
         exit();
     } else {
-        $compose_messages[$session] = NULL;
         unset($compose_messages[$session]);
         $draft_message = _("Draft Email Saved");
         /* If this is a resumed draft, then delete the original */
@@ -478,10 +477,10 @@ if ($send) {
             if( $line <> '-- ' ) {
                 $line = rtrim($line);
             }
-            if (sq_strlen($line,$default_charset) <= $editor_size + 1) {
+            if (sq_strlen($line, $default_charset) <= $editor_size + 1) {
                 $newBody .= $line . "\n";
             } else {
-                sqWordWrap($line, $editor_size,$default_charset);
+                sqWordWrap($line, $editor_size, $default_charset);
                 $newBody .= $line . "\n";
 
             }
@@ -493,15 +492,19 @@ if ($send) {
 
         $Result = deliverMessage($composeMessage);
 
+        if ($Result)
+            $mail_sent = 'yes';
+        else
+            $mail_sent = 'no';
+
         // NOTE: this hook changed in 1.5.2 from sending $Result and
         //       $composeMessage as args #2 and #3 to being in an array
         //       under arg #2
-        do_hook('compose_send_after', $temp=array(&$Result, &$composeMessage));
+        do_hook('compose_send_after', $temp=array(&$Result, &$composeMessage, &$mail_sent));
         if (! $Result) {
             showInputForm($session);
             exit();
         }
-        $compose_messages[$session] = NULL;
         unset($compose_messages[$session]);
 
         /* if it is resumed draft, delete draft message */
@@ -525,21 +528,21 @@ if ($send) {
 
         if ($compose_new_win == '1') {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
-                Header("Location: $location/compose.php?mail_sent=yes");
+                Header("Location: $location/compose.php?mail_sent=$mail_sent");
             } else {
                 echo '   <br><br><div style="text-align: center;"><a href="' . $location
-                    . '/compose.php?mail_sent=yes">'
+                    . '/compose.php?mail_sent=$mail_sent">'
                     . _("Return") . '</a></div>';
             }
             exit();
         } else {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
                 Header("Location: $location/right_main.php?mailbox=$urlMailbox".
-                    "&startMessage=$startMessage&mail_sent=yes");
+                    "&startMessage=$startMessage&mail_sent=$mail_sent");
             } else {
                 echo '   <br><br><div style="text-align: center;"><a href="' . $location
                     . "/right_main.php?mailbox=$urlMailbox"
-                    . "&amp;startMessage=$startMessage&amp;mail_sent=yes\">"
+                    . "&amp;startMessage=$startMessage&amp;mail_sent=$mail_sent\">"
                     . _("Return") . '</a></div>';
             }
             exit();
@@ -925,7 +928,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
                 }
                 /* this corrects some wrapping/quoting problems on replies */
                 $rewrap_body = explode("\n", $body);
-                $from =  (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
+                $from = (is_array($orig_header->from) && !empty($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
                 $body = '';
                 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
                 foreach ($rewrap_body as $line) {
@@ -1153,11 +1156,11 @@ function showInputForm ($session, $values=false) {
     }
 
     if ($saved_draft == 'yes') {
-        $oTemplate->assign('note', _("Draft Saved"));
+        $oTemplate->assign('note', _("Your draft has been saved."));
         $oTemplate->display('note.tpl');
     }
     if ($mail_sent == 'yes') {
-        $oTemplate->assign('note', _("Your message has been sent."));
+        $oTemplate->assign('note', _("Your mail has been sent."));
         $oTemplate->display('note.tpl');
     }
     if ($compose_new_win == '1') {
@@ -1278,6 +1281,7 @@ function showInputForm ($session, $values=false) {
     } // End of file_uploads if-block
     /* End of attachment code */
 
+//FIXME: no direct echoing to browser, no HTML output in core!
     echo addHidden('username', $username).
          addHidden('smaction', $action).
          addHidden('mailbox', $mailbox);
@@ -1285,8 +1289,8 @@ function showInputForm ($session, $values=false) {
        store the complete ComposeMessages array in a hidden input value
        so we can restore them in case of a session timeout.
      */
-    //sm_print_r($compose_messages);
     sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER);
+//FIXME: no direct echoing to browser, no HTML output in core!
     echo addHidden('restoremessages', urlencode(serialize($compose_messages))).
         addHidden('composesession', $composesession).
         addHidden('querystring', $queryString).
@@ -1294,6 +1298,7 @@ function showInputForm ($session, $values=false) {
     if (!(bool) ini_get('file_uploads')) {
         /* File uploads are off, so we didn't show that part of the form.
            To avoid bogus bug reports, tell the user why. */
+//FIXME: no direct echoing to browser, no HTML output in core!
         echo '<p style="text-align:center">'
             . _("Because PHP file uploads are turned off, you can not attach files to this message. Please see your system administrator for details.")
             . "</p>\r\n";
@@ -1328,17 +1333,10 @@ function showComposeButtonRow() {
 
     $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
 
-    if ($use_javascript_addr_book) {
-        $addr_book = "         <script type=\"text/javascript\"><!--\n document.write(\"".
-            "            <input type=button value=\\\""._("Addresses").
-            "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
-            "            // --></script><noscript>\n".
-            '            <input type="submit" name="html_addr_search" value="'.
-            _("Addresses").'" />'.
-            "         </noscript>\n";
+    if ($use_javascript_addr_book && checkForJavascript()) {
+        $addr_book = addButton(_("Addresses"), null, array('onclick' => 'javascript:open_abook();'));
     } else {
-        $addr_book = '         <input type="submit" name="html_addr_search" value="'.
-            _("Addresses").'" />' . "\n";
+        $addr_book = addSubmit(_("Addresses"), 'html_addr_search');
     }
 
     $oTemplate->assign('allow_priority', $default_use_priority==1);
@@ -1651,7 +1649,6 @@ function deliverMessage($composeMessage, $draft=false) {
         global $passed_id, $mailbox, $action, $what, $iAccount,$startMessage;
 
         $composeMessage->purgeAttachments();
-        unset($composeMessage);
         if ($action=='reply' || $action=='reply_all' || $action=='forward' || $action=='forward_as_attachment') {
             require(SM_PATH . 'functions/mailbox_display.php');
             $aMailbox = sqm_api_mailbox_select($imap_stream, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());