Eliminated an error when saving attachments for a draft.
authorfallas <fallas@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 1 Nov 2001 09:56:33 +0000 (09:56 +0000)
committerfallas <fallas@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 1 Nov 2001 09:56:33 +0000 (09:56 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1673 7612ce4b-ef26-0410-bec9-ea0150e637f0

src/draft_actions.php

index 8fb8251c7f128701a308480adc37ddf6fcb0047a..dff29f790c9727e6d13739475b1fc6a512864a70 100644 (file)
@@ -2,7 +2,7 @@
 require_once ('../src/validate.php');
 
    /* Print all the needed RFC822 headers */
 require_once ('../src/validate.php');
 
    /* Print all the needed RFC822 headers */
-   function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, $send_it) {
+   function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {
       global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
       global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
       global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
       global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
       global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
       global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
@@ -90,15 +90,13 @@ require_once ('../src/validate.php');
       }
 
       // Write the header
       }
 
       // Write the header
-      if ($send_it) {
-         fputs ($fp, $header);
-      }
+      fputs ($fp, $header);
 
       return $headerlength;
    }
 
    // Send the body
 
       return $headerlength;
    }
 
    // Send the body
-   function writeBodyForDraft ($fp, $passedBody, $send_it) {
+   function writeBodyForDraft ($fp, $passedBody) {
       global $default_charset;
 
       $attachmentlength = 0;
       global $default_charset;
 
       $attachmentlength = 0;
@@ -113,26 +111,18 @@ require_once ('../src/validate.php');
 
          $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
          $body .= $passedBody . "\r\n\r\n";
 
          $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
          $body .= $passedBody . "\r\n\r\n";
-         if ($send_it) {
-            fputs ($fp, $body);
-         }
+         fputs ($fp, $body);
 
          $attachmentlength = attachFiles($fp);
 
          if (!isset($postbody)) $postbody = "";
          $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
 
          $attachmentlength = attachFiles($fp);
 
          if (!isset($postbody)) $postbody = "";
          $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
-         if ($send_it) {
-            fputs ($fp, $postbody);
-         }
+         fputs ($fp, $postbody);
       } else {
          $body = $passedBody . "\r\n";
       } else {
          $body = $passedBody . "\r\n";
-         if ($send_it) {
-            fputs ($fp, $body);
-         }
+         fputs ($fp, $body);
          $postbody = "\r\n";
          $postbody = "\r\n";
-         if ($send_it) {
-            fputs ($fp, $postbody);
-         }
+         fputs ($fp, $postbody);
       }
 
       return (strlen($body) + strlen($postbody) + $attachmentlength);
       }
 
       return (strlen($body) + strlen($postbody) + $attachmentlength);
@@ -142,14 +132,19 @@ require_once ('../src/validate.php');
    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;
    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;
+      global $draft_folder, $attachment_dir;
       $more_headers = Array();
 
       $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
 
       $more_headers = Array();
 
       $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
 
-      $fp = "";
+      $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
+      while ( file_exists($attachment_dir .$tmpDraftFile) )
+         $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
+      $fp = fopen($attachment_dir . $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, FALSE);
       $bodylength = writeBodyForDraft ($fp, $body, FALSE);
+      fclose($fp);
 
       $length = ($headerlength + $bodylength);
 
 
       $length = ($headerlength + $bodylength);
 
@@ -162,6 +157,8 @@ require_once ('../src/validate.php');
       sqimap_logout($imap_stream);
       if ($length)
          ClearAttachments();
       sqimap_logout($imap_stream);
       if ($length)
          ClearAttachments();
+         if (file_exists($attachment_dir . $tmpDraftFile) )
+            unlink ($attachment_dir . $tmpDraftFile);
       return $length;
 }
 ?>
       return $length;
 }
 ?>