Added sent_subfolders plugin, tweaked config stuff, other stuff.
[squirrelmail.git] / src / compose.php
index f008aee0b042c2593df37c53ff1c0d94db8a2bd8..bc3ab0609dec480ad3a2297c50df8230a008d24e 100644 (file)
@@ -1,36 +1,51 @@
 <?php
-   /**
-    * compose.php
-    *
-    * Copyright (c) 1999-2000 The SquirrelMail development team
-    * Licensed under the GNU GPL. For full terms see the file COPYING.
-    *
-    * This code sends a mail.
-    *
-    * There are 4 modes of operation:
-    *    - Start new mail
-    *    - Add an attachment
-    *    - Send mail
-    *    - Save As Draft
-    *  
-    * $Id$
-    **/
-
-   require_once('../src/validate.php');
-   require_once('../functions/imap.php');
-   require_once('../functions/date.php');
-   require_once('../functions/mime.php');
-   require_once('../functions/smtp.php');
-   require_once('../functions/display_messages.php');
-   require_once('../functions/plugin.php');
-
-   if (!isset($attachments))
-   {
+
+/**
+ * compose.php
+ *
+ * Copyright (c) 1999-2001 The Squirrelmail Development Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This code sends a mail.
+ *
+ * There are 4 modes of operation:
+ *    - Start new mail
+ *    - Add an attachment
+ *    - Send mail
+ *    - Save As Draft
+ *
+ * $Id$
+ */
+
+/*****************************************************************/
+/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!!           ***/
+/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION.             ***/
+/***    + Base level indent should begin at left margin, as    ***/
+/***      the require_once below looks.                        ***/
+/***    + All identation should consist of four space blocks   ***/
+/***    + Tab characters are evil.                             ***/
+/***    + all comments should use "slash-star ... star-slash"  ***/
+/***      style -- no pound characters, no slash-slash style   ***/
+/***    + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD      ***/
+/***      ALWAYS USE { AND } CHARACTERS!!!                     ***/
+/***    + Please use ' instead of ", when possible. Note "     ***/
+/***      should always be used in _( ) function calls.        ***/
+/*** Thank you for your help making the SM code more readable. ***/
+/*****************************************************************/
+
+require_once('../src/validate.php');
+require_once('../functions/imap.php');
+require_once('../functions/date.php');
+require_once('../functions/mime.php');
+require_once('../functions/smtp.php');
+require_once('../functions/display_messages.php');
+require_once('../functions/plugin.php');
+
+   if (!isset($attachments)) {
        $attachments = array();
        session_register('attachments');
    }
 
-
    // This function is used when not sending or adding attachments
    function newMail () {
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
                     $body_ary[$i] = '> ' . $body_ary[$i];
                 }
             }
-            sqWordWrap($body_ary[$i], $editor_size - 1);
+            if (!$draft_id) {
+               sqWordWrap($body_ary[$i], $editor_size - 1);
+            }
             $body .= $body_ary[$i] . "\n";
             unset($body_ary[$i]);
          }
 
    function getAttachments($message) {
       global $mailbox, $attachments, $attachment_dir, $imapConnection,
-             $ent_num, $forward_id, $draft_id;
+             $ent_num, $forward_id, $draft_id, $username;
  
      if (isset($draft_id))
          $id = $draft_id;
                $mailbox);
       }
 
+      $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
       if (count($message->entities) == 0) {
           if ($message->header->entity_id != $ent_num) {
               $filename = decodeHeader($message->header->filename);
                   $filename = "untitled-".$message->header->entity_id;
 
               $localfilename = GenerateRandomString(32, '', 7);
-              while (file_exists($attachment_dir . $localfilename))
+              $full_localfilename = "$hashed_attachment_dir/$localfilename";
+              while (file_exists($full_localfilename)) {
                   $localfilename = GenerateRandomString(32, '', 7);
+                  $full_localfilename = "$hashed_attachment_dir/$localfilename";
+              }
 
               $newAttachment = array();
               $newAttachment['localfilename'] = $localfilename;
                  '/' . $message->header->type1);
 
               // Write Attachment to file
-              $fp = fopen ($attachment_dir.$localfilename, 'w');
+              $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
               fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
                   $id, $message->header->entity_id),
                   $message->header->encoding));
          $editor_size, $attachments, $subject, $newmail,
          $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
          $from_htmladdr_search, $location_of_buttons, $attachment_dir,
-         $username, $data_dir, $identity, $draft_id;
+         $username, $data_dir, $identity, $draft_id, $delete_draft,
+        $mailprio;
 
       $subject = decodeHeader($subject);
       $reply_subj = decodeHeader($reply_subj);
       if (isset($draft_id)) {
          echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$draft_id\">\n";
       }
+      if (isset($delete_draft)) {
+         echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$delete_draft\">\n";
+      }
 
       echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
 
 
       // This code is for attachments
       echo "   <tr>\n";
-      echo "     <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
-      echo "      <SMALL><BR></SMALL>"._("Attach:");
+      echo "     <TD BGCOLOR=\"$color[0]\" VALIGN=MIDDLE ALIGN=RIGHT>\n";
+      echo        _("Attach:");
       echo "      </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
       echo "      <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
       echo "      &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
       echo " value=\"" . _("Add") ."\">\n";
       echo "     </td>\n";
       echo "   </tr>\n";
-      if (count($attachments))
-      {
+      if (count($attachments)) {
+         $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
          echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
          echo "&nbsp;";
          echo "</td><td align=left bgcolor=\"$color[0]\">";
          foreach ($attachments as $key => $info) {
+            $attached_file = "$hashed_attachment_dir/$info[localfilename]";
             echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
             echo $info['remotefilename'] . " - " . $info['type'] . " (";
-            echo show_readable_size(filesize($attachment_dir .
-                $info['localfilename'])) . ")<br>\n";
+            echo show_readable_size(filesize($attached_file)) . ")<br>\n";
          }
 
          echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
       printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));      
       echo "</FORM>";
       do_hook("compose_bottom");
+      echo "</BODY></HTML>\n";
    }
 
    function showComposeButtonRow() {
-      global $use_javascript_addr_book, $save_as_draft;
+      global $use_javascript_addr_book, $save_as_draft, 
+             $default_use_priority, $mailprio;
 
       echo "   <TR><td>\n   </td><td>\n";
       if ($use_javascript_addr_book) {
       echo "\n    <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
 
       if ($save_as_draft) {
-          echo "<input type=\"submit\" name =\"draft\" value=\"Save Draft\">\n";
+          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");
 
    // True if FAILURE
    function saveAttachedFiles() {
-      global $HTTP_POST_FILES, $attachment_dir, $attachments;
-
+      global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
+      
+      $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
       $localfilename = GenerateRandomString(32, '', 7);
-      while (file_exists($attachment_dir . $localfilename))
+      $full_localfilename = "$hashed_attachment_dir/$localfilename";
+      while (file_exists($full_localfilename)) {
           $localfilename = GenerateRandomString(32, '', 7);
+          $full_localfilename = "$hashed_attachment_dir/$localfilename";
+      }
 
-      if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
-         if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
+      if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
+         if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
             return true;
          }
       }
       $attachments[] = $newAttachment;
     }
 
-   if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
+   if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None'))
       $mailbox = "INBOX";
 
    if (isset($draft)) {
          exit();
       } else {
          $draft_message = _("Draft Email Saved");
-         Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
-         exit();
+         /* 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");
+            exit();
+         } else {
+            Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
+            exit();
+         }
       }
    }
 
 
          do_hook("compose_send");
 
-         if (! sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
+         if (! isset($mailprio))
+           $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, 
+                                 $subject, $body, $reply_id);
+        else
+           $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
+                                 $subject, $body, $reply_id, $mailprio);
+         if (! $Result) {
             showInputForm();
             exit();
          }
    } else if (isset($do_delete)) {
       displayPageHeader($color, $mailbox);
 
-      if (isset($delete) && is_array($delete))
-      {
-         foreach($delete as $index)
-         {
-            unlink ($attachment_dir.$attachments[$index]['localfilename']);
+      $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+      if (isset($delete) && is_array($delete)) {
+         foreach($delete as $index) {
+            $attached_file = $hashed_attachment_dir . '/'
+                           . $attachments[$index]['localfilename'];
+            unlink ($attached_file);
             unset ($attachments[$index]);
          }
       }
    }
 
    function ClearAttachments() {
-       global $attachments, $attachment_dir;
+       global $username, $attachments, $attachment_dir;
+       $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
 
        foreach ($attachments as $info) {
-           if (file_exists($attachment_dir . $info['localfilename'])) {
-               unlink($attachment_dir . $info['localfilename']);
+           $attached_file = "$hashed_attachment_dir/$info[localfilename]";
+           if (file_exists($attached_file)) {
+               unlink($attached_file);
            }
        }