Prettied up hide/view unsafe images commands...
[squirrelmail.git] / src / compose.php
index e499efe815841ce8933874e428ba00f928d5c567..85e3376c6431f4338581b62de27ef83fb09de6d7 100644 (file)
@@ -36,6 +36,12 @@ if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
 
 if (isset($draft)) {
     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();
@@ -43,13 +49,20 @@ if (isset($draft)) {
         $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 {
-            Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
-                   "&startMessage=1&note=$draft_message");
+        }
+        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,8 +112,8 @@ 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,
@@ -114,20 +127,28 @@ if (isset($send)) {
             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);
@@ -137,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) {
@@ -164,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') {
@@ -178,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)) {
@@ -207,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;
 
@@ -420,7 +475,8 @@ 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, $default_use_mdn, $mdn_user_support;
+           $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
+           $saved_draft, $mail_sent;
 
     $subject = decodeHeader($subject, false);
     $reply_subj = decodeHeader($reply_subj, false);
@@ -440,7 +496,7 @@ function showInputForm () {
     echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
          'ENCTYPE="multipart/form-data"';
     do_hook("compose_form");
-  
+
     
     echo ">\n";
 
@@ -450,9 +506,16 @@ 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();
     }
@@ -558,14 +621,6 @@ function showInputForm () {
         showComposeButtonRow();
     } else {
         echo '   <TR><TD COLSPAN=2 ALIGN=LEFT>';
-
-        $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
-        if ($default_use_mdn) {
-            if ($mdn_user_support) {
-                echo _("Confirm reading:").
-                    "<input type=\"checkbox\" name=\"request_mdn\" value=1>";
-            }
-        }
         echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
     }
 
@@ -611,13 +666,33 @@ function showInputForm () {
 }
 
 
-function showComposeButtonRow()
-{
+function showComposeButtonRow() {
     global $use_javascript_addr_book, $save_as_draft,
-           $default_use_priority, $mailprio, $default_use_mdn,
-           $data_dir, $username;
+        $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(\"".
              "         <input type=button value=\\\""._("Addresses").
@@ -635,24 +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 _("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>";
-    }
 
     do_hook('compose_button_row');
 
     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