oops! typo!
[squirrelmail.git] / src / compose.php
index d4a669d8f72e702e19d7fe339388370864d25b17..bb877878e7e6be389f54b98838ae99b779b7dbef 100644 (file)
@@ -46,7 +46,7 @@ sqgetGlobalVar('composesession',    $composesession,    SQ_SESSION);
 sqgetGlobalVar('compose_messages',  $compose_messages,  SQ_SESSION);
 
 /** SESSION/POST/GET VARS */
-sqgetGlobalVar('action',$action);
+sqgetGlobalVar('smaction',$action);
 sqgetGlobalVar('session',$session);
 sqgetGlobalVar('mailbox',$mailbox);
 if(!sqgetGlobalVar('identity',$identity)) {
@@ -73,7 +73,7 @@ sqgetGlobalVar('draft_id',$draft_id);
 sqgetGlobalVar('ent_num',$ent_num);
 sqgetGlobalVar('saved_draft',$saved_draft);
 sqgetGlobalVar('delete_draft',$delete_draft);
-sqgetGlobalVar('startmessage',$startMessage);
+sqgetGlobalVar('startMessage',$startMessage);
 
 /** POST VARS */
 sqgetGlobalVar('sigappend',             $sigappend,             SQ_POST);
@@ -128,6 +128,11 @@ function replyAllString($header) {
    $url_replytoallcc = '';
    foreach( $url_replytoall_ar as $email => $personal) {
       if ($personal) {
+         // if personal name contains address separator then surround
+         // the personal name with double quotes.
+         if (strpos($personal,',') !== false) {
+             $personal = '"'.$personal.'"';
+         }
          $url_replytoallcc .= ", $personal <$email>";
       } else {
          $url_replytoallcc .= ', '. $email;
@@ -373,7 +378,7 @@ if ($send) {
             showInputForm($session);
             exit();
         }
-       unset($compose_messages[$session]);
+        unset($compose_messages[$session]);
         if ( isset($delete_draft)) {
             Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
                    "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
@@ -385,7 +390,7 @@ if ($send) {
         }
         else {
             Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
-                   "&startMessage=$startMessage");
+                   "&startMessage=$startMessage&mail_sent=yes");
         }
     } else {
         if ($compose_new_win == '1') {
@@ -541,6 +546,15 @@ exit();
 
 /**************** Only function definitions go below *************/
 
+function getforwardSubject($subject)
+{
+    if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
+        (substr(strtolower($subject), 0, 5) != '[fwd:') &&
+        (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
+        $subject = '[Fwd: ' . $subject . ']';
+    }
+    return $subject;
+}
 
 /* This function is used when not sending or adding attachments */
 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
@@ -548,7 +562,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
            $use_signature, $composesession, $data_dir, $username,
            $username, $key, $imapServerAddress, $imapPort, $compose_messages,
            $composeMessage;
-    global $languages, $squirrelmail_language;
+    global $languages, $squirrelmail_language, $default_charset;
 
     $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
     $mailprio = 3;
@@ -596,7 +610,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
             $bodypart = decodeBody($unencoded_bodypart,
             $body_part_entity->header->encoding);
             if ($type1 == 'html') {
-                $bodypart = str_replace(array('&nbsp;','&gt','&lt'),array(' ','<','>'),$bodypart);
+                $bodypart = str_replace(array('&nbsp;','&gt;','&lt;'),array(' ','<','>'),$bodypart);
                 $bodypart = strip_tags($bodypart);
             }
             if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
@@ -605,6 +619,12 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
                     $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
                 }
             }
+           
+           $actual = $body_part_entity->header->parameters['charset'];
+           if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
+               $bodypart = charset_decode($actual,$bodypart);
+           }
+           
             $body .= $bodypart;
         }
         if ($default_use_priority) {
@@ -678,32 +698,35 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
             break;
         case ('forward'):
             $send_to = '';
-            $subject = decodeHeader($orig_header->subject,false,true);
-            if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
-                (substr(strtolower($subject), 0, 5) != '[fwd:') &&
-                (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
-                $subject = '[Fwd: ' . $subject . ']';
-            }
+            $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true));
             $body = getforwardHeader($orig_header) . $body;
             sqUnWordWrap($body);
             $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
             $body = "\n" . $body;
             break;
         case ('forward_as_attachment'):
+            $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true));
             $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
             $body = '';
             break;
         case ('reply_all'):
-            $send_to_cc = replyAllString($orig_header);
-            $send_to_cc = decodeHeader($send_to_cc,false,true);
-        case ('reply'):
-            $send_to = $orig_header->reply_to;
-            if (is_array($send_to) && count($send_to)) {
-                $send_to = $orig_header->getAddr_s('reply_to');
-            } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
-                $send_to = $orig_header->getAddr_s('reply_to');
+            if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
+                $send_to = $orig_header->getAddr_s('mail_followup_to');
             } else {
-                $send_to = $orig_header->getAddr_s('from');
+                $send_to_cc = replyAllString($orig_header);
+                $send_to_cc = decodeHeader($send_to_cc,false,true);
+            }
+        case ('reply'):
+            // skip this if send_to was already set right above here
+            if(!$send_to) {
+                $send_to = $orig_header->reply_to;
+                if (is_array($send_to) && count($send_to)) {
+                    $send_to = $orig_header->getAddr_s('reply_to');
+                } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
+                    $send_to = $orig_header->getAddr_s('reply_to');
+                } else {
+                    $send_to = $orig_header->getAddr_s('from');
+                }
             }
             $send_to = decodeHeader($send_to,false,true);
             $subject = decodeHeader($orig_header->subject,false,true);
@@ -715,18 +738,20 @@ 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;
-            sqUnWordWrap($body);
+            sqUnWordWrap($body);       // unwrap and then reset it?!
             $body = '';
-            $cnt = count($rewrap_body);
-            for ($i=0;$i<$cnt;$i++) {
-              sqWordWrap($rewrap_body[$i], ($editor_size));
-                if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
+            $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
+            foreach ($rewrap_body as $line) {
+                if ($strip_sigs && substr($line,0,3) == '-- ') {
+                       break;
+                }
+                sqWordWrap($line, ($editor_size));
+                if (preg_match("/^(>+)/", $line, $matches)) {
                     $gt = $matches[1];
-                    $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
+                    $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
                 } else {
-                    $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
+                    $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
                 }
-                unset($rewrap_body[$i]);
             }
             $body = getReplyCitation($from) . $body;
             $composeMessage->reply_rfc822_header = $orig_header;
@@ -760,10 +785,11 @@ function getAttachments($message, &$composeMessage, $passed_id, $entities, $imap
            switch ($message->type0) {
            case 'message':
                 if ($message->type1 == 'rfc822') {
-                    $filename = $message->rfc822_header->subject.'.eml';
+                    $filename = $message->rfc822_header->subject;
                     if ($filename == "") {
-                        $filename = "untitled-".$message->entity_id.'.eml';
+                        $filename = "untitled-".$message->entity_id;
                     }
+                    $filename .= '.msg';
                  } else {
                    $filename = $message->getFilename();
                  }
@@ -775,7 +801,7 @@ function getAttachments($message, &$composeMessage, $passed_id, $entities, $imap
              $filename = $message->getFilename();
              break;
            }
-           $filename = decodeHeader($filename);
+           $filename = str_replace('&nbsp;', ' ', decodeHeader($filename));
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
                function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
                 $filename =  $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
@@ -833,7 +859,7 @@ function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
         $fp = fopen($full_localfilename, 'w');
         fwrite ($fp, $body);
         fclose($fp);
-        $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
+        $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
                          $full_localfilename);
     }
     return $composeMessage;
@@ -903,7 +929,7 @@ function showInputForm ($session, $values=false) {
         echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
     }
     if ($mail_sent == 'yes') {
-        echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
+        echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
     }
     echo '<table align="center" cellspacing="0" border="0">' . "\n";
     if ($compose_new_win == '1') {
@@ -975,13 +1001,13 @@ function showInputForm ($session, $values=false) {
     if ($compose_new_win == '1') {
         echo '   <TR>' . "\n" .
              '      <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
-             '         <TEXTAREA NAME=body ROWS=20 COLS="' .
+             '         <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
                        $editor_size . '" WRAP="VIRTUAL">';
     }
     else {
         echo '   <TR>' . "\n" .
             '      <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
-            '         &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
+            '         &nbsp;&nbsp;<TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
                       $editor_size . '" WRAP="VIRTUAL">';
     }
 
@@ -1105,7 +1131,7 @@ function showInputForm ($session, $values=false) {
 
     echo '</TABLE>' . "\n" .
          '<input type="hidden" name="username" value="'. $username . "\">\n" .
-         '<input type=hidden name=action value="' . $action . "\">\n" .
+         '<input type=hidden name=smaction value="' . $action . "\">\n" .
          '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
          "\">\n";
     /*
@@ -1494,7 +1520,7 @@ function deliverMessage($composeMessage, $draft=false) {
         ClearAttachments($composeMessage);
         if ($action == 'reply' || $action == 'reply_all') {
             sqimap_mailbox_select ($imap_stream, $mailbox);
-            sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
+            sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
         }
             sqimap_logout($imap_stream);
     }