2 require_once ('../src/validate.php');
4 /* Print all the needed RFC822 headers */
5 function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers) {
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);
98 function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id) {
99 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad;
100 global $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, $imapPort;
101 global $draft_folder;
102 $more_headers = Array();
104 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
106 $fp = fopen("/dev/null", a
);
107 $headerlength = write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers);
108 $bodylength = writeBody ($fp, $body);
111 $length = ($headerlength +
$bodylength);
113 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
114 sqimap_append ($imap_stream, $draft_folder, $length);
115 write822HeaderForDraft ($imap_stream, $t, $c, $b, $subject, $more_headers);
116 writeBody ($imap_stream, $body);
117 sqimap_append_done ($imap_stream);
119 sqimap_logout($imap_stream);