2 require_once ('../src/validate.php');
4 /* Print all the needed RFC822 headers */
5 function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, $send_it) {
6 global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
7 global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
8 global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
9 global $REMOTE_HOST, $identity;
11 // Storing the header to make sure the header is the same
12 // everytime the header is printed.
13 static $header, $headerlength;
16 if (isset($identity) && ($identity != 'default')) {
17 $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
18 $from = getPref($data_dir, $username, 'full_name' . $identity);
19 $from_addr = getPref($data_dir, $username, 'email_address' . $identity);
21 $reply_to = getPref($data_dir, $username, 'reply_to');
22 $from = getPref($data_dir, $username, 'full_name');
23 $from_addr = getPref($data_dir, $username, 'email_address');
26 if ($from_addr == '') {
27 $from_addr = $popuser.'@'.$domain;
30 /* Encoding 8-bit characters and making from line */
31 $subject = encodeHeader($subject);
33 $from = "<$from_addr>";
35 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
38 /* This creates an RFC 822 date */
39 $date = date("D, j M Y H:i:s ", mktime()) . timezone();
41 /* Create a message-id */
42 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
43 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
45 /* Insert header fields */
46 $header = "Message-ID: $message_id\r\n";
47 $header .= "Date: $date\r\n";
48 $header .= "Subject: $subject\r\n";
49 $header .= "From: $from\r\n";
50 $header .= "To: $t\r\n"; // Who it's TO
52 /* Insert headers from the $more_headers array */
53 if(is_array($more_headers)) {
55 while(list($h_name, $h_val) = each($more_headers)) {
56 $header .= sprintf("%s: %s\r\n", $h_name, $h_val);
61 $header .= "Cc: $c\r\n"; // Who the CCs are
65 $header .= "Bcc: $b\r\n"; // Who the BCCs are
69 $header .= "Reply-To: $reply_to\r\n";
71 $header .= "X-Mailer: SquirrelMail (version $version)\r\n"; // Identify SquirrelMail
73 /* Do the MIME-stuff */
74 $header .= "MIME-Version: 1.0\r\n";
77 $header .= 'Content-Type: multipart/mixed; boundary="';
78 $header .= mimeBoundary();
81 if ($default_charset != '')
82 $header .= "Content-Type: text/plain; charset=$default_charset\r\n";
84 $header .= "Content-Type: text/plain;\r\n";
85 $header .= "Content-Transfer-Encoding: 8bit\r\n";
87 $header .= "\r\n"; // One blank line to separate header and body
89 $headerlength = strlen($header);
101 function writeBodyForDraft ($fp, $passedBody, $send_it) {
102 global $default_charset;
104 $attachmentlength = 0;
107 $body = '--'.mimeBoundary()."\r\n";
109 if ($default_charset != "")
110 $body .= "Content-Type: text/plain; charset=$default_charset\r\n";
112 $body .= "Content-Type: text/plain\r\n";
114 $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
115 $body .= $passedBody . "\r\n\r\n";
120 $attachmentlength = attachFiles($fp);
122 if (!isset($postbody)) $postbody = "";
123 $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
125 fputs ($fp, $postbody);
128 $body = $passedBody . "\r\n";
134 fputs ($fp, $postbody);
138 return (strlen($body) +
strlen($postbody) +
$attachmentlength);
142 function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id) {
143 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad;
144 global $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, $imapPort;
145 global $draft_folder;
146 $more_headers = Array();
148 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
151 $headerlength = write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, FALSE);
152 $bodylength = writeBodyForDraft ($fp, $body, FALSE);
154 $length = ($headerlength +
$bodylength);
156 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
157 sqimap_append ($imap_stream, $draft_folder, $length);
158 write822HeaderForDraft ($imap_stream, $t, $c, $b, $subject, $more_headers, TRUE);
159 writeBodyForDraft ($imap_stream, $body, TRUE);
160 sqimap_append_done ($imap_stream);
162 sqimap_logout($imap_stream);