bd9906cd |
1 | <?php |
2 | require_once ('../src/validate.php'); |
3 | |
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; |
10 | |
11 | // Storing the header to make sure the header is the same |
12 | // everytime the header is printed. |
13 | static $header, $headerlength; |
14 | |
15 | if ($header == '') { |
f7b1b3b1 |
16 | if (isset($identity) && ($identity != 'default')) { |
bd9906cd |
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); |
f7b1b3b1 |
20 | } else { |
bd9906cd |
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'); |
24 | } |
25 | |
f7b1b3b1 |
26 | if ($from_addr == '') { |
bd9906cd |
27 | $from_addr = $popuser.'@'.$domain; |
f7b1b3b1 |
28 | } |
bd9906cd |
29 | |
bd9906cd |
30 | /* Encoding 8-bit characters and making from line */ |
31 | $subject = encodeHeader($subject); |
f7b1b3b1 |
32 | if ($from == '') { |
bd9906cd |
33 | $from = "<$from_addr>"; |
f7b1b3b1 |
34 | } else { |
bd9906cd |
35 | $from = '"' . encodeHeader($from) . "\" <$from_addr>"; |
f7b1b3b1 |
36 | } |
bd9906cd |
37 | |
38 | /* This creates an RFC 822 date */ |
39 | $date = date("D, j M Y H:i:s ", mktime()) . timezone(); |
40 | |
41 | /* Create a message-id */ |
42 | $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.'; |
43 | $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>'; |
44 | |
1e000d2f |
45 | /* Insert header fields */ |
46 | $header = "Message-ID: $message_id\r\n"; |
bd9906cd |
47 | $header .= "Date: $date\r\n"; |
48 | $header .= "Subject: $subject\r\n"; |
49 | $header .= "From: $from\r\n"; |
1e000d2f |
50 | $header .= "To: $t\r\n"; // Who it's TO |
bd9906cd |
51 | |
52 | /* Insert headers from the $more_headers array */ |
53 | if(is_array($more_headers)) { |
54 | reset($more_headers); |
55 | while(list($h_name, $h_val) = each($more_headers)) { |
56 | $header .= sprintf("%s: %s\r\n", $h_name, $h_val); |
57 | } |
58 | } |
59 | |
1e000d2f |
60 | if ($c) { |
61 | $header .= "Cc: $c\r\n"; // Who the CCs are |
bd9906cd |
62 | } |
63 | |
1e000d2f |
64 | if ($b) { |
65 | $header .= "Bcc: $b\r\n"; // Who the BCCs are |
bd9906cd |
66 | } |
67 | |
68 | if ($reply_to != '') |
69 | $header .= "Reply-To: $reply_to\r\n"; |
70 | |
bd9906cd |
71 | $header .= "X-Mailer: SquirrelMail (version $version)\r\n"; // Identify SquirrelMail |
72 | |
f7b1b3b1 |
73 | /* Do the MIME-stuff */ |
bd9906cd |
74 | $header .= "MIME-Version: 1.0\r\n"; |
75 | |
76 | if (isMultipart()) { |
77 | $header .= 'Content-Type: multipart/mixed; boundary="'; |
78 | $header .= mimeBoundary(); |
79 | $header .= "\"\r\n"; |
80 | } else { |
81 | if ($default_charset != '') |
82 | $header .= "Content-Type: text/plain; charset=$default_charset\r\n"; |
83 | else |
84 | $header .= "Content-Type: text/plain;\r\n"; |
85 | $header .= "Content-Transfer-Encoding: 8bit\r\n"; |
86 | } |
87 | $header .= "\r\n"; // One blank line to separate header and body |
88 | |
89 | $headerlength = strlen($header); |
90 | } |
91 | |
92 | // Write the header |
93 | fputs ($fp, $header); |
94 | |
95 | return $headerlength; |
96 | } |
97 | |
f7b1b3b1 |
98 | function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id) { |
bd9906cd |
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(); |
103 | |
104 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1); |
105 | |
bd9906cd |
106 | $fp = fopen("/dev/null", a); |
107 | $headerlength = write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers); |
108 | $bodylength = writeBody ($fp, $body); |
109 | fclose ($fp); |
110 | |
111 | $length = ($headerlength + $bodylength); |
112 | |
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); |
118 | } |
119 | sqimap_logout($imap_stream); |
120 | if ($length) |
121 | ClearAttachments(); |
122 | return $length; |
123 | } |
124 | ?> |