removed old rcptaddress
[squirrelmail.git] / src / draft_actions.php
index a665ba5a3d35535f98eec790992965489389fc5e..4bfe3659aaffb092c654bdea70b11b54f2260ed3 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * draft_actions.php
  *
- * Copyright (c) 1999-2001 The Squirrelmail Development Team
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * $Id$
@@ -12,7 +12,7 @@
 require_once ('../src/validate.php');
 
 /* Print all the needed RFC822 headers */
-function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {
+function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, $session) {
     global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
     global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
     global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
@@ -84,7 +84,7 @@ function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {
         /* Do the MIME-stuff */
         $header .= "MIME-Version: 1.0\r\n";
 
-        if (isMultipart()) {
+        if (isMultipart($session)) {
             $header .= 'Content-Type: multipart/mixed; boundary="';
             $header .= mimeBoundary();
             $header .= "\"\r\n";
@@ -107,12 +107,12 @@ function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {
 }
 
 /* Send the body */
-function writeBodyForDraft ($fp, $passedBody) {
+function writeBodyForDraft ($fp, $passedBody, $session) {
     global $default_charset;
 
     $attachmentlength = 0;
 
-    if (isMultipart()) {
+    if (isMultipart($session)) {
         $body = '--'.mimeBoundary()."\r\n";
 
         if ($default_charset != ""){
@@ -125,7 +125,7 @@ function writeBodyForDraft ($fp, $passedBody) {
         $body .= $passedBody . "\r\n\r\n";
         fputs ($fp, $body);
 
-        $attachmentlength = attachFiles($fp);
+        $attachmentlength = attachFiles($fp, $session);
 
         if (!isset($postbody)) $postbody = "";
         $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
@@ -141,39 +141,51 @@ function writeBodyForDraft ($fp, $passedBody) {
 }
 
 
-function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id) {
-    global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad;
-    global $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, $imapPort;
-    global $draft_folder, $attachment_dir;
+function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $session) {
+    global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
+           $data_dir, $username, $domain, $key, $version, $sent_folder,
+           $imapServerAddress, $imapPort, $draft_folder, $attachment_dir,
+           $default_use_priority;
     $more_headers = Array();
 
+    if ($default_use_priority) {
+        $more_headers = array_merge($more_headers, createPriorityHeaders($prio));
+    }
+
     $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
 
+    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+
     $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
-    while ( file_exists($attachment_dir .$tmpDraftFile)){
+    $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
+    while (file_exists($full_tmpDraftFile)){
          $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
+         $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
     }
-    $fp = fopen($attachment_dir . $tmpDraftFile, 'w');
+    $fp = fopen($full_tmpDraftFile, 'w');
 
-    $headerlength = write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, FALSE);
-    $bodylength = writeBodyForDraft ($fp, $body, FALSE);
+    $headerlength = write822HeaderForDraft
+        ($fp, $t, $c, $b, $subject, $more_headers, $session);
+    $bodylength = writeBodyForDraft ($fp, $body, $session);
     fclose($fp);
 
     $length = ($headerlength + $bodylength);
 
     if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
         sqimap_append ($imap_stream, $draft_folder, $length);
-        write822HeaderForDraft ($imap_stream, $t, $c, $b, $subject, $more_headers, TRUE);
-        writeBodyForDraft ($imap_stream, $body, TRUE);
+        write822HeaderForDraft
+            ($imap_stream, $t, $c, $b, $subject, $more_headers, $session);
+        writeBodyForDraft ($imap_stream, $body, $session);
         sqimap_append_done ($imap_stream);
     }
     sqimap_logout($imap_stream);
     if ($length){
-        ClearAttachments();
+        ClearAttachments($session);
     }
-    if (file_exists($attachment_dir . $tmpDraftFile)){
-        unlink ($attachment_dir . $tmpDraftFile);
+    if (file_exists($full_tmpDraftFile)){
+        unlink ($full_tmpDraftFile);
     }
     return $length;
 }
-?>
+
+?>
\ No newline at end of file