Remove &amp usage from Location headers
[squirrelmail.git] / src / compose.php
index 55a53135f20eff24d3c15beba7e7dc67a56629c9..82fa2392e550dfd8fc52f2c79f6d14a55603b0c8 100644 (file)
@@ -35,21 +35,34 @@ if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
 }
 
 if (isset($draft)) {
-    require_once ('../src/draft_actions.php');
-    if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
+    include_once ('../src/draft_actions.php');
+    if (! isset($reply_id)) {
+         $reply_id = 0;
+    }
+    if (! isset($MDN)) {
+        $MDN = 'False';
+    }
+    if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN)) {
         showInputForm();
         exit();
     } else {
         $draft_message = _("Draft Email Saved");
         /* If this is a resumed draft, then delete the original */
         if(isset($delete_draft)) {
-            Header("Location: delete_message.php?mailbox=$draft_folder".
-                   "&message=$delete_draft&sort=$sort&startMessage=1");
+            Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
+                   "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
             exit();
-        } else {
+        }
+        else {
+            if ($compose_new_win == '1') {
+                Header("Location: compose.php?saved_draft=yes");
+            exit();
+            }
+            else {
             Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
                    "&startMessage=1&note=$draft_message");
             exit();
+            }
         }
     }
 }
@@ -67,13 +80,13 @@ if (isset($send)) {
         }
         /*
          * Set $default_charset to correspond with the user's selection
-         * of language interface. 
+         * of language interface.
          */
         set_my_charset();
 
         /*
          * This is to change all newlines to \n
-         * We'll change them to \r\n later (in the sendMessage function) 
+         * We'll change them to \r\n later (in the sendMessage function)
          */
         $body = str_replace("\r\n", "\n", $body);
         $body = str_replace("\r", "\n", $body);
@@ -82,7 +95,7 @@ if (isset($send)) {
          * Rewrap $body so that no line is bigger than $editor_size
          * This should only really kick in the sqWordWrap function
          * if the browser doesn't support "HARD" as the wrap type
-         * Or, in Opera's case, something goes wrong. 
+         * Or, in Opera's case, something goes wrong.
          */
         $body = explode("\n", $body);
         $newBody = '';
@@ -99,34 +112,43 @@ if (isset($send)) {
         }
         $body = $newBody;
 
-        do_hook("compose_send");
+        do_hook('compose_send');
 
+        $MDN = False;  // we are not sending a mdn response
         if (! isset($mailprio)) {
             $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
-                                  $subject, $body, $reply_id);
+                                  $subject, $body, $reply_id, $MDN);
         } else {
             $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
-                                  $subject, $body, $reply_id, $mailprio);
+                                  $subject, $body, $reply_id, $MDN, $mailprio);
         }
         if (! $Result) {
             showInputForm();
             exit();
         }
         if ( isset($delete_draft)) {
-            Header("Location: delete_message.php?mailbox=$draft_folder".
-                   "&message=$delete_draft&sort=$sort&startMessage=1");
+            Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
+                   "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
             exit();
         }
-
-        Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
-               "&startMessage=1");
+        if ($compose_new_win == '1') {
+            Header("Location: compose.php?mail_sent=yes");
+        }
+        else {
+            Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
+                   "&startMessage=1");
+        }
     } else {
         /*
          *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
          *                               $imapPort, 0);
          */
-        displayPageHeader($color, $mailbox);
-
+        if ($compose_new_win == '1') {
+            compose_Header($color, $mailbox);
+        }
+        else {
+            displayPageHeader($color, $mailbox);
+        }
         if (isset($AttachFailure)) {
              plain_error_message(_("Could not move/copy file. File not attached"),
                                  $color);
@@ -136,9 +158,13 @@ if (isset($send)) {
         showInputForm();
         /* sqimap_logout($imapConnection); */
     }
-}
-elseif (isset($html_addr_search_done)) {
-    displayPageHeader($color, $mailbox);
+} elseif (isset($html_addr_search_done)) {
+        if ($compose_new_win == '1') {
+            compose_Header($color, $mailbox);
+        }
+        else {
+            displayPageHeader($color, $mailbox);
+        }
 
     if (isset($send_to_search) && is_array($send_to_search)) {
         foreach ($send_to_search as $k => $v) {
@@ -163,8 +189,7 @@ elseif (isset($html_addr_search_done)) {
         }
     }
     showInputForm();
-}
-elseif (isset($html_addr_search)) {
+} elseif (isset($html_addr_search)) {
     if (isset($HTTP_POST_FILES['attachfile']) &&
         $HTTP_POST_FILES['attachfile']['tmp_name'] &&
         $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
@@ -177,16 +202,42 @@ elseif (isset($html_addr_search)) {
      * click.  If you can think of a better way, please implement it.
      */
     include_once('./addrbook_search_html.php');
-}
-elseif (isset($attach)) {
+} elseif (isset($attach)) {
     if (saveAttachedFiles()) {
         plain_error_message(_("Could not move/copy file. File not attached"), $color);
     }
-    displayPageHeader($color, $mailbox);
+        if ($compose_new_win == '1') {
+            compose_Header($color, $mailbox);
+        }
+        else {
+            displayPageHeader($color, $mailbox);
+        }
     showInputForm();
 }
-elseif (isset($do_delete)) {
-    displayPageHeader($color, $mailbox);
+elseif (isset($sigappend)) {
+    $idents = getPref($data_dir, $username, 'identities', 0);
+    if ($idents > 1) {
+       if ($identity == 'default') {
+          $no = 'g';
+       } else {
+          $no = $identity;
+       }
+       $signature = getSig($data_dir, $username, $no);
+    }
+    $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
+    if ($compose_new_win == '1') {
+         compose_Header($color, $mailbox);
+    } else {
+        displayPageHeader($color, $mailbox);
+    }
+    showInputForm();
+} elseif (isset($do_delete)) {
+        if ($compose_new_win == '1') {
+            compose_Header($color, $mailbox);
+        }
+        else {
+            displayPageHeader($color, $mailbox);
+        }
 
     $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
     if (isset($delete) && is_array($delete)) {
@@ -206,7 +257,12 @@ elseif (isset($do_delete)) {
      */
     $imapConnection = sqimap_login($username, $key, $imapServerAddress,
                                    $imapPort, 0);
-    displayPageHeader($color, $mailbox);
+        if ($compose_new_win == '1') {
+            compose_Header($color, $mailbox);
+        }
+        else {
+            displayPageHeader($color, $mailbox);
+        }
 
     $newmail = true;
 
@@ -237,9 +293,9 @@ function newMail () {
            $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
            $draft_id, $use_signature;
 
-    $send_to = decodeHeader($send_to);
-    $send_to_cc = decodeHeader($send_to_cc);
-    $send_to_bcc = decodeHeader($send_to_bcc);
+    $send_to = decodeHeader($send_to, false);
+    $send_to_cc = decodeHeader($send_to_cc, false);
+    $send_to_bcc = decodeHeader($send_to_bcc, false);
 
     if ($forward_id) {
         $id = $forward_id;
@@ -316,7 +372,7 @@ function newMail () {
             $body = $bodyTop . $body;
         }
         elseif ($reply_id) {
-            $orig_from = decodeHeader($orig_header->from);
+            $orig_from = decodeHeader($orig_header->from, false);
             $body = getReplyCitation($orig_from) . $body;
         }
 
@@ -330,7 +386,7 @@ function newMail () {
     /* This formats a CC string if they hit "reply all" */
     if ($send_to_cc != '') {
         $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
-        $send_to_cc = ereg_replace(';', ',', $send_to_cc);
+        $send_to_cc = str_replace(';', ',', $send_to_cc);
         $sendcc = explode(',', $send_to_cc);
         $send_to_cc = '';
 
@@ -419,11 +475,12 @@ function showInputForm () {
            $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
            $from_htmladdr_search, $location_of_buttons, $attachment_dir,
            $username, $data_dir, $identity, $draft_id, $delete_draft,
-           $mailprio;
+           $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
+           $saved_draft, $mail_sent;
 
-    $subject = decodeHeader($subject);
-    $reply_subj = decodeHeader($reply_subj);
-    $forward_subj = decodeHeader($forward_subj);
+    $subject = decodeHeader($subject, false);
+    $reply_subj = decodeHeader($reply_subj, false);
+    $forward_subj = decodeHeader($forward_subj, false);
 
     if ($use_javascript_addr_book) {
         echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
@@ -439,6 +496,8 @@ function showInputForm () {
     echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
          'ENCTYPE="multipart/form-data"';
     do_hook("compose_form");
+
+    
     echo ">\n";
 
     if (isset($draft_id)) {
@@ -447,15 +506,22 @@ function showInputForm () {
     if (isset($delete_draft)) {
         echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
     }
-
+    if ($saved_draft == 'yes') {
+        echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
+    }
+    if ($mail_sent == 'yes') {
+        echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
+    }
     echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
-
+    if ($compose_new_win == '1') {
+        echo '   <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
+    }
     if ($location_of_buttons == 'top') {
         showComposeButtonRow();
     }
 
-    $idents = getPref($data_dir, $username, 'identities');
-    if ($idents != '' && $idents > 1) {
+    $idents = getPref($data_dir, $username, 'identities', 0);
+    if ($idents > 1) {
         echo '   <TR>' . "\n" .
              '      <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
              "\n" .
@@ -479,6 +545,7 @@ function showInputForm () {
             if ($em != '') {
                 echo htmlspecialchars(' <' . $em . '>') . "\n";
             }
+            echo '</option>';
         }
         echo '</select>' . "\n" .
              '      </TD>' . "\n" .
@@ -544,11 +611,7 @@ function showInputForm () {
          '         &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
          $editor_size . '" WRAP=HARD>' . htmlspecialchars($body);
     if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
-        if ( $prefix_sig == true ) {
-            echo "\n\n-- \n" . htmlspecialchars($signature);
-        } else {
-            echo "\n\n" . htmlspecialchars($signature);
-        }
+        echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
     }
     echo '</TEXTAREA><BR>' . "\n" .
          '      </TD>' . "\n" .
@@ -557,10 +620,10 @@ function showInputForm () {
     if ($location_of_buttons == 'bottom') {
         showComposeButtonRow();
     } else {
-        echo '   <TR><TD>&nbsp;</TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT ' .
-             'NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
+        echo '   <TR><TD COLSPAN=2 ALIGN=LEFT>';
+        echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
     }
-    
+
     /* This code is for attachments */
     echo '   <TR>' . "\n" .
          '     <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
@@ -572,6 +635,7 @@ function showInputForm () {
          ' value="' . _("Add") .'">' . "\n" .
          '     </TD>' . "\n" .
          '   </TR>' . "\n";
+
     if (count($attachments)) {
         $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
         echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
@@ -597,25 +661,46 @@ function showInputForm () {
     echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
          "\">\n" .
          '</FORM>';
-    do_hook("compose_bottom");
+    do_hook('compose_bottom');
     echo '</BODY></HTML>' . "\n";
 }
 
 
-function showComposeButtonRow()
-{
+function showComposeButtonRow() {
     global $use_javascript_addr_book, $save_as_draft,
-        $default_use_priority, $mailprio;
+        $default_use_priority, $mailprio, $default_use_mdn,
+        $data_dir, $username;
+
+    echo "  <TR><TD>\n</TD><TD>\n";
+    if ($default_use_priority) {
+        if(!isset($mailprio)) {
+            $mailprio = "3";
+    }
+    echo _("Priority") .': <select name="mailprio">'.
+         '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
+         '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
+         '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
+         "</select>";
+    }
+    $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
+    if ($default_use_mdn) {
+        if ($mdn_user_support) {
+            echo "\n\t". _("Receipt") .': '.
+            '<input type="checkbox" name="request_mdn" value=1>'. _("On read").
+            ' <input type="checkbox" name="request_dr" value=1>'. _("On Delivery");
+        }
+    }
 
     echo "   <TR><td>\n   </td><td>\n";
+    echo "\n    <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
     if ($use_javascript_addr_book) {
-        echo "      <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
-        echo "         <input type=button value=\\\""._("Addresses").
-                              "\\\" onclick='javascript:open_abook();'>\");";
-        echo "         // --></SCRIPT><NOSCRIPT>\n";
-        echo "         <input type=submit name=\"html_addr_search\" value=\"".
-                              _("Addresses")."\">";
-        echo "      </NOSCRIPT>\n";
+        echo "      <SCRIPT LANGUAGE=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";
     } else {
         echo "      <input type=submit name=\"html_addr_search\" value=\"".
                               _("Addresses")."\">";
@@ -625,25 +710,13 @@ function showComposeButtonRow()
     if ($save_as_draft) {
         echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
     }
-    if ($default_use_priority) {
-        if(!isset($mailprio)) {
-            $mailprio = "3";
-        }
-        echo "\n\t". _("Priority") .':<select name="mailprio">'.
-            "\n\t\t<option value=1".($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
-            "\n\t\t<option value=3".($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
-            "\n\t\t<option value=5".($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
-            "\n\t</select>";
-    }
 
     do_hook('compose_button_row');
 
-    echo "   </TD>\n";
-    echo "   </TR>\n\n";
+    echo "   </TD></TR>\n\n";
 }
 
-function checkInput ($show)
-{
+function checkInput ($show) {
     /*
      * I implemented the $show variable because the error messages
      * were getting sent before the page header.  So, I check once
@@ -692,6 +765,8 @@ function saveAttachedFiles() {
 }
 
 
+
+
 function ClearAttachments()
 {
     global $username, $attachments, $attachment_dir;