return $headerlength;
}
+ // Send the body
+ function writeBodyForDraft ($fp, $passedBody) {
+ global $default_charset;
+
+ $attachmentlength = 0;
+
+ if (isMultipart()) {
+ $body = '--'.mimeBoundary()."\r\n";
+
+ if ($default_charset != "")
+ $body .= "Content-Type: text/plain; charset=$default_charset\r\n";
+ else
+ $body .= "Content-Type: text/plain\r\n";
+
+ $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
+ $body .= $passedBody . "\r\n\r\n";
+ fputs ($fp, $body);
+
+ $attachmentlength = attachFiles($fp);
+
+ if (!isset($postbody)) $postbody = "";
+ $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
+ fputs ($fp, $postbody);
+ } else {
+ $body = $passedBody . "\r\n";
+ fputs ($fp, $body);
+ $postbody = "\r\n";
+ fputs ($fp, $postbody);
+ }
+
+ return (strlen($body) + strlen($postbody) + $attachmentlength);
+ }
+
+
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);
- $fp = fopen("/dev/null", a);
- $headerlength = write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers);
- $bodylength = writeBody ($fp, $body);
- fclose ($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);
+ 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);
- writeBody ($imap_stream, $body);
+ write822HeaderForDraft ($imap_stream, $t, $c, $b, $subject, $more_headers, TRUE);
+ writeBodyForDraft ($imap_stream, $body, TRUE);
sqimap_append_done ($imap_stream);
}
sqimap_logout($imap_stream);
if ($length)
ClearAttachments();
+ if (file_exists($attachment_dir . $tmpDraftFile) )
+ unlink ($attachment_dir . $tmpDraftFile);
return $length;
}
?>