- }
- $header .= "\r\n"; // One blank line to separate header and body
-
- $headerlength = strlen($header);
- }
-
- // Write the header
- fputs ($fp, $header);
-
- return $headerlength;
- }
-
- 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;
- $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);
-
- $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);
- sqimap_append_done ($imap_stream);
- }
- sqimap_logout($imap_stream);
- if ($length)
- ClearAttachments();
- return $length;
+ }
+ $header .= "\r\n"; // One blank line to separate header and body
+
+ $headerlength = strlen($header);
+ }
+
+ /* Write the header */
+ fputs ($fp, $header);
+
+ 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,
+ $data_dir, $username, $domain, $key, $version, $sent_folder,
+ $imapServerAddress, $imapPort, $draft_folder, $attachment_dir;
+ $more_headers = Array();
+
+ $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
+
+ $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
+
+ $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
+ $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
+ while (file_exists($full_tmpDraftFile)){
+ $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
+ $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
+ }
+ $fp = fopen($full_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, TRUE);
+ writeBodyForDraft ($imap_stream, $body, TRUE);
+ sqimap_append_done ($imap_stream);
+ }
+ sqimap_logout($imap_stream);
+ if ($length){
+ ClearAttachments();
+ }
+ if (file_exists($full_tmpDraftFile)){
+ unlink ($full_tmpDraftFile);
+ }
+ return $length;