+
+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);
+ $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, $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, $session);
+ writeBodyForDraft ($imap_stream, $body, $session);
+ sqimap_append_done ($imap_stream);
+ }
+ sqimap_logout($imap_stream);
+ if ($length){
+ ClearAttachments($session);
+ }
+ if (file_exists($full_tmpDraftFile)){
+ unlink ($full_tmpDraftFile);
+ }
+ return $length;
+}
+?>
\ No newline at end of file