Lots of changes to get closer to having save as draft working. Please, keep working...
[squirrelmail.git] / src / compose.php
index ae21388e95c088ef82c02df6c0d4501ad315ede5..f008aee0b042c2593df37c53ff1c0d94db8a2bd8 100644 (file)
@@ -1,18 +1,19 @@
 <?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 3 modes of operation:
-    **  - Start new mail
-    **  - Add an attachment
-    **  - Send mail
-    **
-    ** $Id$
+    * 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');
@@ -33,7 +34,8 @@
    // This function is used when not sending or adding attachments
    function newMail () {
       global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
-             $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size;
+             $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);
       elseif ($reply_id)
          $id = $reply_id;
 
+      if ($draft_id){
+         $id = $draft_id;
+         $use_signature = FALSE;
+      }
 
       if (isset($id)) {
          sqimap_mailbox_select($imapConnection, $mailbox);
@@ -73,7 +79,7 @@
          }
          $body = "";
          for ($i=0; isset($body_ary[$i]); $i++) {
-            if (! $forward_id)
+            if ($reply_id)
             {
                 if (ereg('^[ >]+', $body_ary[$i]))
                 {
 
    function getAttachments($message) {
       global $mailbox, $attachments, $attachment_dir, $imapConnection,
-             $ent_num, $forward_id;
+             $ent_num, $forward_id, $draft_id;
+     if (isset($draft_id))
+         $id = $draft_id;
+      else
+         $id = $forward_id;
 
       if (!$message) {
            sqimap_mailbox_select($imapConnection, $mailbox);
-           $message = sqimap_get_message($imapConnection, $forward_id,
+           $message = sqimap_get_message($imapConnection, $id,
                $mailbox);
       }
 
               // Write Attachment to file
               $fp = fopen ($attachment_dir.$localfilename, 'w');
               fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
-                  $forward_id, $message->header->entity_id),
+                  $id, $message->header->entity_id),
                   $message->header->encoding));
               fclose ($fp);
 
          $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;
+         $username, $data_dir, $identity, $draft_id;
 
       $subject = decodeHeader($subject);
       $reply_subj = decodeHeader($reply_subj);
       do_hook("compose_form");
           echo ">\n";
 
+      if (isset($draft_id)) {
+         echo "<input type=\"hidden\" name=\"delete_draft\" value=\"$draft_id\">\n";
+      }
+
       echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
 
       if ($location_of_buttons == 'top') showComposeButtonRow();
    }
 
    function showComposeButtonRow() {
-      global $use_javascript_addr_book;
+      global $use_javascript_addr_book, $save_as_draft;
 
       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";
+      }
+
       do_hook("compose_button_row");
 
       echo "   </TD>\n";
    if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
       $mailbox = "INBOX";
 
+   if (isset($draft)) {
+      require_once ('../src/draft_actions.php');
+      if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
+         showInputForm();
+         exit();
+      } else {
+         $draft_message = _("Draft Email Saved");
+         Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
+         exit();
+      }
+   }
+
    if (isset($send)) {
       if (isset($HTTP_POST_FILES['attachfile']) &&
           $HTTP_POST_FILES['attachfile']['tmp_name'] &&
             showInputForm();
             exit();
          }
+         if ( isset($delete_draft)) {
+            Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
+            exit();
+         }
+         
          Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
       } else {
          //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
       if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
           getAttachments(0);
 
+      if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num)
+          getAttachments(0);
+
       newMail();
       showInputForm();
       sqimap_logout($imapConnection);
       /* Build and return the citation string. */
       return ($start . $orig_from . $end . "\n");
    }
-?>
\ No newline at end of file
+?>