4) XSS in help.php:
[squirrelmail.git] / src / draft_actions.php
1 <?php
2
3 /**
4 * draft_actions.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * $Id$
10 */
11
12 /* Path for SquirrelMail required files. */
13 define('SM_PATH','../');
14
15 /* SquirrelMail required files. */
16 require_once(SM_PATH . 'include/validate.php');
17
18 /* Print all the needed RFC822 headers */
19 function write822HeaderForDraft ($fp, $t, $c, $b, $subject, $more_headers, $session) {
20 global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
21 global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
22 global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
23 global $REMOTE_HOST, $identity;
24
25 /* Storing the header to make sure the header is the same */
26 /* everytime the header is printed. */
27 static $header, $headerlength;
28
29 if ($header == '') {
30 if (isset($identity) && ($identity != 'default')) {
31 $reply_to = getPref($data_dir, $username, 'reply_to' . $identity);
32 $from = getPref($data_dir, $username, 'full_name' . $identity);
33 $from_addr = getPref($data_dir, $username, 'email_address' . $identity);
34 } else {
35 $reply_to = getPref($data_dir, $username, 'reply_to');
36 $from = getPref($data_dir, $username, 'full_name');
37 $from_addr = getPref($data_dir, $username, 'email_address');
38 }
39
40 if ($from_addr == '') {
41 $from_addr = $popuser.'@'.$domain;
42 }
43
44 /* Encoding 8-bit characters and making from line */
45 $subject = encodeHeader($subject);
46 if ($from == '') {
47 $from = "<$from_addr>";
48 } else {
49 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
50 }
51
52 /* This creates an RFC 822 date */
53 $date = date("D, j M Y H:i:s ", mktime()) . timezone();
54
55 /* Create a message-id */
56 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
57 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
58
59 /* Insert header fields */
60 $header = "Message-ID: $message_id\r\n";
61 $header .= "Date: $date\r\n";
62 $header .= "Subject: $subject\r\n";
63 $header .= "From: $from\r\n";
64 $header .= "To: $t\r\n"; // Who it's TO
65
66 /* Insert headers from the $more_headers array */
67 if(is_array($more_headers)) {
68 reset($more_headers);
69 while(list($h_name, $h_val) = each($more_headers)) {
70 $header .= sprintf("%s: %s\r\n", $h_name, $h_val);
71 }
72 }
73
74 if ($c) {
75 $header .= "Cc: $c\r\n"; // Who the CCs are
76 }
77
78 if ($b) {
79 $header .= "Bcc: $b\r\n"; // Who the BCCs are
80 }
81
82 if ($reply_to != '') {
83 $header .= "Reply-To: $reply_to\r\n";
84 }
85
86 $header .= "X-Mailer: SquirrelMail (version $version)\r\n"; // Identify SquirrelMail
87
88 /* Do the MIME-stuff */
89 $header .= "MIME-Version: 1.0\r\n";
90
91 if (isMultipart($session)) {
92 $header .= 'Content-Type: multipart/mixed; boundary="';
93 $header .= mimeBoundary();
94 $header .= "\"\r\n";
95 } else {
96 if ($default_charset != '')
97 $header .= "Content-Type: text/plain; charset=$default_charset\r\n";
98 else
99 $header .= "Content-Type: text/plain;\r\n";
100 $header .= "Content-Transfer-Encoding: 8bit\r\n";
101 }
102 $header .= "\r\n"; // One blank line to separate header and body
103
104 $headerlength = strlen($header);
105 }
106
107 /* Write the header */
108 fputs ($fp, $header);
109
110 return $headerlength;
111 }
112
113 /* Send the body */
114 function writeBodyForDraft ($fp, $passedBody, $session) {
115 global $default_charset;
116
117 $attachmentlength = 0;
118
119 if (isMultipart($session)) {
120 $body = '--'.mimeBoundary()."\r\n";
121
122 if ($default_charset != ""){
123 $body .= "Content-Type: text/plain; charset=$default_charset\r\n";
124 } else {
125 $body .= "Content-Type: text/plain\r\n";
126 }
127
128 $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
129 $body .= $passedBody . "\r\n\r\n";
130 fputs ($fp, $body);
131
132 $attachmentlength = attachFiles($fp, $session);
133
134 if (!isset($postbody)) $postbody = "";
135 $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
136 fputs ($fp, $postbody);
137 } else {
138 $body = $passedBody . "\r\n";
139 fputs ($fp, $body);
140 $postbody = "\r\n";
141 fputs ($fp, $postbody);
142 }
143
144 return (strlen($body) + strlen($postbody) + $attachmentlength);
145 }
146
147
148 function saveMessageAsDraft($t, $c, $b, $subject, $body, $reply_id, $prio = 3, $session) {
149 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
150 $data_dir, $username, $domain, $key, $version, $sent_folder,
151 $imapServerAddress, $imapPort, $draft_folder, $attachment_dir,
152 $default_use_priority;
153 $more_headers = Array();
154
155 if ($default_use_priority) {
156 $more_headers = array_merge($more_headers, createPriorityHeaders($prio));
157 }
158
159 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
160
161 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
162
163 $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
164 $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
165 while (file_exists($full_tmpDraftFile)){
166 $tmpDraftFile = "draft-" . GenerateRandomString(32, '', 7);
167 $full_tmpDraftFile = "$hashed_attachment_dir/$tmpDraftFile";
168 }
169 $fp = fopen($full_tmpDraftFile, 'wb');
170
171 $headerlength = write822HeaderForDraft
172 ($fp, $t, $c, $b, $subject, $more_headers, $session);
173 $bodylength = writeBodyForDraft ($fp, $body, $session);
174 fclose($fp);
175
176 $length = ($headerlength + $bodylength);
177
178 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
179 sqimap_append ($imap_stream, $draft_folder, $length);
180 write822HeaderForDraft
181 ($imap_stream, $t, $c, $b, $subject, $more_headers, $session);
182 writeBodyForDraft ($imap_stream, $body, $session);
183 sqimap_append_done ($imap_stream);
184 }
185 sqimap_logout($imap_stream);
186 if ($length){
187 ClearAttachments($session);
188 }
189 if (file_exists($full_tmpDraftFile)){
190 unlink ($full_tmpDraftFile);
191 }
192 return $length;
193 }
194
195 ?>