Allow for stripping sigs when replying, if enabled will drop everything
[squirrelmail.git] / src / compose.php
index 88ab70776a040a69bb62f2adb68e3eb1a8297641..7c25053b548290612bbf75830943ad0fda32a2db 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);
 
 /** POST VARS */
 sqgetGlobalVar('sigappend',             $sigappend,             SQ_POST);
@@ -373,7 +373,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 +385,7 @@ if ($send) {
         }
         else {
             Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
-                   "&startMessage=1");
+                   "&startMessage=$startMessage&mail_sent=yes");
         }
     } else {
         if ($compose_new_win == '1') {
@@ -694,16 +694,23 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
             $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 +722,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;
@@ -840,7 +849,7 @@ function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
 }
 
 function showInputForm ($session, $values=false) {
-    global $send_to, $send_to_cc, $body,
+    global $send_to, $send_to_cc, $body, $startMessage,
            $passed_body, $color, $use_signature, $signature, $prefix_sig,
            $editor_size, $attachments, $subject, $newmail,
            $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
@@ -877,12 +886,14 @@ function showInputForm ($session, $values=false) {
              "// -->\n</SCRIPT>\n\n";
     }
 
-    echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
-         'ENCTYPE="multipart/form-data"';
-    do_hook("compose_form");
+    echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
+         'enctype="multipart/form-data"';
+    do_hook('compose_form');
 
     echo ">\n";
 
+    echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
+
     if ($action == 'draft') {
         echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
     }
@@ -903,7 +914,7 @@ function showInputForm ($session, $values=false) {
     if ($mail_sent == 'yes') {
         echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
     }
-    echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
+    echo '<table align="center" cellspacing="0" border="0">' . "\n";
     if ($compose_new_win == '1') {
         echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
              '   <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
@@ -1103,7 +1114,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";
     /*