commit | author | age
|
4e17e6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
+-----------------------------------------------------------------------+ |
|
5 |
| program/steps/mail/sendmail.inc | |
|
6 |
| | |
|
7 |
| This file is part of the RoundCube Webmail client | |
cbbef3
|
8 |
| Copyright (C) 2005-2009, RoundCube Dev. - Switzerland | |
30233b
|
9 |
| Licensed under the GNU GPL | |
4e17e6
|
10 |
| | |
T |
11 |
| PURPOSE: | |
|
12 |
| Compose a new mail message with all headers and attachments | |
e8f8fe
|
13 |
| and send it using the PEAR::Net_SMTP class or with PHP mail() | |
4e17e6
|
14 |
| | |
T |
15 |
+-----------------------------------------------------------------------+ |
|
16 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
17 |
+-----------------------------------------------------------------------+ |
|
18 |
|
|
19 |
$Id$ |
|
20 |
|
|
21 |
*/ |
|
22 |
|
|
23 |
|
0b6c1c
|
24 |
// remove all scripts and act as called in frame |
T |
25 |
$OUTPUT->reset(); |
|
26 |
$OUTPUT->framed = TRUE; |
|
27 |
|
acb08f
|
28 |
$savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; |
A |
29 |
|
|
30 |
/****** checks ********/ |
0b6c1c
|
31 |
|
T |
32 |
if (!isset($_SESSION['compose']['id'])) { |
6710a6
|
33 |
raise_error(array('code' => 500, 'type' => 'smtp', 'file' => __FILE__, 'message' => "Invalid compose ID"), true, false); |
0b6c1c
|
34 |
console("Sendmail error", $_SESSION['compose']); |
T |
35 |
$OUTPUT->show_message("An internal error occured. Please try again.", 'error'); |
|
36 |
$OUTPUT->send('iframe'); |
|
37 |
} |
4e17e6
|
38 |
|
4b60fa
|
39 |
if (!$savedraft) { |
A |
40 |
if (empty($_POST['_to']) && empty($_POST['_cc']) && empty($_POST['_bcc']) |
|
41 |
&& empty($_POST['_subject']) && $_POST['_message']) { |
|
42 |
$OUTPUT->show_message('sendingfailed', 'error'); |
acb08f
|
43 |
$OUTPUT->send('iframe'); |
4b60fa
|
44 |
} |
A |
45 |
|
|
46 |
if(!empty($CONFIG['sendmail_delay'])) { |
|
47 |
$wait_sec = time() - intval($CONFIG['sendmail_delay']) - intval($CONFIG['last_message_time']); |
|
48 |
if($wait_sec < 0) { |
|
49 |
$OUTPUT->show_message('senttooquickly', 'error', array('sec' => $wait_sec * -1)); |
|
50 |
$OUTPUT->send('iframe'); |
acb08f
|
51 |
} |
4b60fa
|
52 |
} |
acb08f
|
53 |
} |
A |
54 |
|
4e17e6
|
55 |
|
T |
56 |
/****** message sending functions ********/ |
|
57 |
|
2471d3
|
58 |
// encrypt parts of the header |
A |
59 |
function rcmail_encrypt_header($what) |
|
60 |
{ |
|
61 |
global $CONFIG, $RCMAIL; |
|
62 |
if (!$CONFIG['http_received_header_encrypt']) |
|
63 |
{ |
|
64 |
return $what; |
|
65 |
} |
|
66 |
return $RCMAIL->encrypt($what); |
|
67 |
} |
|
68 |
|
fba1f5
|
69 |
// get identity record |
4e17e6
|
70 |
function rcmail_get_identity($id) |
T |
71 |
{ |
fba1f5
|
72 |
global $USER, $OUTPUT; |
4e17e6
|
73 |
|
fba1f5
|
74 |
if ($sql_arr = $USER->get_identity($id)) |
4e17e6
|
75 |
{ |
T |
76 |
$out = $sql_arr; |
fba1f5
|
77 |
$out['mailto'] = $sql_arr['email']; |
a1733f
|
78 |
|
A |
79 |
// Special chars as defined by RFC 822 need to in quoted string (or escaped). |
|
80 |
if (preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $sql_arr['name'])) |
|
81 |
$name = '"' . addcslashes($sql_arr['name'], '"') . '"'; |
|
82 |
else |
|
83 |
$name = $sql_arr['name']; |
|
84 |
|
fd51e0
|
85 |
$out['string'] = rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset()); |
A |
86 |
if ($sql_arr['email']) |
|
87 |
$out['string'] .= ' <' . $sql_arr['email'] . '>'; |
|
88 |
|
4e17e6
|
89 |
return $out; |
T |
90 |
} |
|
91 |
|
|
92 |
return FALSE; |
|
93 |
} |
|
94 |
|
a0109c
|
95 |
/** |
S |
96 |
* go from this: |
|
97 |
* <img src=".../tiny_mce/plugins/emotions/images/smiley-cool.gif" border="0" alt="Cool" title="Cool" /> |
|
98 |
* |
|
99 |
* to this: |
|
100 |
* |
|
101 |
* <IMG src="cid:smiley-cool.gif"/> |
|
102 |
* ... |
|
103 |
* ------part... |
|
104 |
* Content-Type: image/gif |
|
105 |
* Content-Transfer-Encoding: base64 |
|
106 |
* Content-ID: <smiley-cool.gif> |
|
107 |
*/ |
|
108 |
function rcmail_attach_emoticons(&$mime_message) |
|
109 |
{ |
47124c
|
110 |
global $CONFIG; |
a0109c
|
111 |
|
24ed41
|
112 |
$body = $mime_message->getHtmlBody(); |
a0109c
|
113 |
|
S |
114 |
// remove any null-byte characters before parsing |
24ed41
|
115 |
$body = preg_replace('/\x00/', '', $body); |
a0109c
|
116 |
|
33ca14
|
117 |
$searchstr = 'program/js/tiny_mce/plugins/emotions/img/'; |
24ed41
|
118 |
$offset = 0; |
a0109c
|
119 |
|
ed6592
|
120 |
// keep track of added images, so they're only added once |
S |
121 |
$included_images = array(); |
|
122 |
|
24ed41
|
123 |
if (preg_match_all('# src=[\'"]([^\'"]+)#', $body, $matches, PREG_OFFSET_CAPTURE)) { |
A |
124 |
foreach ($matches[1] as $m) { |
|
125 |
// find emoticon image tags |
|
126 |
if (preg_match('#'.$searchstr.'(.*)$#', $m[0], $imatches)) { |
|
127 |
$image_name = $imatches[1]; |
99f2b3
|
128 |
|
24ed41
|
129 |
// sanitize image name so resulting attachment doesn't leave images dir |
A |
130 |
$image_name = preg_replace('/[^a-zA-Z0-9_\.\-]/i', '', $image_name); |
|
131 |
$img_file = INSTALL_PATH . '/' . $searchstr . $image_name; |
99f2b3
|
132 |
|
24ed41
|
133 |
if (! in_array($image_name, $included_images)) { |
A |
134 |
// add the image to the MIME message |
|
135 |
if(! $mime_message->addHTMLImage($img_file, 'image/gif', '', true, $image_name)) |
|
136 |
$OUTPUT->show_message("emoticonerror", 'error'); |
|
137 |
array_push($included_images, $image_name); |
|
138 |
} |
4e6eb1
|
139 |
|
24ed41
|
140 |
$body = substr_replace($body, $img_file, $m[1] + $offset, strlen($m[0])); |
A |
141 |
$offset += strlen($img_file) - strlen($m[0]); |
ed6592
|
142 |
} |
a0109c
|
143 |
} |
24ed41
|
144 |
} |
99f2b3
|
145 |
|
a0109c
|
146 |
$mime_message->setHTMLBody($body); |
24ed41
|
147 |
|
A |
148 |
return $body; |
a0109c
|
149 |
} |
41fa0b
|
150 |
|
c58c0a
|
151 |
// parse email address input |
8f9ab3
|
152 |
function rcmail_email_input_format($mailto) |
c58c0a
|
153 |
{ |
A |
154 |
$regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U'); |
|
155 |
$replace = array(', ', ', ', '', ',', '\\1 \\2'); |
|
156 |
|
050410
|
157 |
// replace new lines and strip ending ', ', make address input more valid |
c58c0a
|
158 |
$mailto = trim(preg_replace($regexp, $replace, $mailto)); |
A |
159 |
|
050410
|
160 |
$result = array(); |
A |
161 |
$items = rcube_explode_quoted_string(',', $mailto); |
c58c0a
|
162 |
|
050410
|
163 |
foreach($items as $item) { |
A |
164 |
$item = trim($item); |
|
165 |
// address in brackets without name (do nothing) |
|
166 |
if (preg_match('/^<\S+@\S+>$/', $item)) { |
|
167 |
$result[] = $item; |
|
168 |
// address without brackets and without name (add brackets) |
|
169 |
} else if (preg_match('/^\S+@\S+$/', $item)) { |
|
170 |
$result[] = '<'.$item.'>'; |
|
171 |
// address with name (handle name) |
|
172 |
} else if (preg_match('/\S+@\S+>*$/', $item, $matches)) { |
|
173 |
$address = $matches[0]; |
|
174 |
$name = str_replace($address, '', $item); |
|
175 |
$name = trim($name); |
|
176 |
if ($name && ($name[0] != '"' || $name[strlen($name)-1] != '"') |
c58c0a
|
177 |
&& preg_match('/[\(\)\<\>\\\.\[\]@,;:"]/', $name)) { |
A |
178 |
$name = '"'.addcslashes($name, '"').'"'; |
|
179 |
} |
050410
|
180 |
if (!preg_match('/^<\S+@\S+>$/', $address)) |
A |
181 |
$address = '<'.$address.'>'; |
c58c0a
|
182 |
|
050410
|
183 |
$result[] = $name.' '.$address; |
A |
184 |
} else if (trim($item)) { |
|
185 |
// @TODO: handle errors |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
return implode(', ', $result); |
c58c0a
|
190 |
} |
acb08f
|
191 |
|
A |
192 |
/****** compose message ********/ |
|
193 |
|
b068a0
|
194 |
if (strlen($_POST['_draft_saveid']) > 3) |
T |
195 |
$olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST); |
|
196 |
|
83a763
|
197 |
$message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])); |
4e17e6
|
198 |
|
5bc8cb
|
199 |
// set default charset |
13c1af
|
200 |
$input_charset = $OUTPUT->get_charset(); |
c03095
|
201 |
$message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset; |
T |
202 |
|
8f9ab3
|
203 |
$mailto = rcmail_email_input_format(get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset)); |
A |
204 |
$mailcc = rcmail_email_input_format(get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
|
205 |
$mailbcc = rcmail_email_input_format(get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
4e17e6
|
206 |
|
e8f8fe
|
207 |
if (empty($mailto) && !empty($mailcc)) { |
T |
208 |
$mailto = $mailcc; |
|
209 |
$mailcc = null; |
|
210 |
} |
|
211 |
else if (empty($mailto)) |
|
212 |
$mailto = 'undisclosed-recipients:;'; |
|
213 |
|
|
214 |
// get sender name and address |
42b25a
|
215 |
$from = get_input_value('_from', RCUBE_INPUT_POST, true, $message_charset); |
fd51e0
|
216 |
$identity_arr = rcmail_get_identity($from); |
A |
217 |
|
8f9ab3
|
218 |
if (!$identity_arr && ($from = rcmail_email_input_format($from))) { |
42b25a
|
219 |
if (preg_match('/(\S+@\S+)/', $from, $m)) |
8f9ab3
|
220 |
$identity_arr['mailto'] = $m[1]; |
A |
221 |
} else |
fd51e0
|
222 |
$from = $identity_arr['mailto']; |
4e17e6
|
223 |
|
b068a0
|
224 |
if (empty($identity_arr['string'])) |
T |
225 |
$identity_arr['string'] = $from; |
4e17e6
|
226 |
|
T |
227 |
// compose headers array |
2471d3
|
228 |
$headers = array(); |
A |
229 |
|
|
230 |
// if configured, the Received headers goes to top, for good measure |
|
231 |
if ($CONFIG['http_received_header']) |
|
232 |
{ |
|
233 |
$nldlm = $RCMAIL->config->header_delimiter() . "\t"; |
|
234 |
$http_header = 'from '; |
|
235 |
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
236 |
$http_header .= rcmail_encrypt_header(gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR'])) . |
|
237 |
' [' . rcmail_encrypt_header($_SERVER['HTTP_X_FORWARDED_FOR']) . ']'; |
|
238 |
$http_header .= $nldlm . ' via '; |
|
239 |
} |
|
240 |
$http_header .= rcmail_encrypt_header(gethostbyaddr($_SERVER['REMOTE_ADDR'])) . |
|
241 |
' [' . rcmail_encrypt_header($_SERVER['REMOTE_ADDR']) .']'; |
|
242 |
$http_header .= $nldlm . 'with ' . $_SERVER['SERVER_PROTOCOL'] . |
|
243 |
' ('.$_SERVER['REQUEST_METHOD'] . '); ' . date('r'); |
|
244 |
$http_header = wordwrap($http_header, 69, $nldlm); |
|
245 |
$headers['Received'] = $http_header; |
|
246 |
} |
|
247 |
|
|
248 |
$headers['Date'] = date('r'); |
|
249 |
$headers['From'] = rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset); |
|
250 |
$headers['To'] = $mailto; |
4e17e6
|
251 |
|
T |
252 |
// additional recipients |
e8f8fe
|
253 |
if (!empty($mailcc)) |
T |
254 |
$headers['Cc'] = $mailcc; |
4e17e6
|
255 |
|
e8f8fe
|
256 |
if (!empty($mailbcc)) |
T |
257 |
$headers['Bcc'] = $mailbcc; |
4e17e6
|
258 |
|
ea7c46
|
259 |
if (!empty($identity_arr['bcc'])) |
4e17e6
|
260 |
$headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc']; |
T |
261 |
|
|
262 |
// add subject |
762a69
|
263 |
$headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, TRUE, $message_charset)); |
4e17e6
|
264 |
|
ea7c46
|
265 |
if (!empty($identity_arr['organization'])) |
4e17e6
|
266 |
$headers['Organization'] = $identity_arr['organization']; |
T |
267 |
|
7984ec
|
268 |
if (!empty($_POST['_replyto'])) |
8f9ab3
|
269 |
$headers['Reply-To'] = rcmail_email_input_format(get_input_value('_replyto', RCUBE_INPUT_POST, TRUE, $message_charset)); |
7984ec
|
270 |
else if (!empty($identity_arr['reply-to'])) |
4e17e6
|
271 |
$headers['Reply-To'] = $identity_arr['reply-to']; |
T |
272 |
|
f88d41
|
273 |
if (!empty($_SESSION['compose']['reply_msgid'])) |
4e17e6
|
274 |
$headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid']; |
T |
275 |
|
f88d41
|
276 |
if (!empty($_SESSION['compose']['references'])) |
T |
277 |
$headers['References'] = $_SESSION['compose']['references']; |
4e17e6
|
278 |
|
ea7c46
|
279 |
if (!empty($_POST['_priority'])) |
4e17e6
|
280 |
{ |
c57996
|
281 |
$priority = intval($_POST['_priority']); |
3287e8
|
282 |
$a_priorities = array(1=>'highest', 2=>'high', 4=>'low', 5=>'lowest'); |
4e17e6
|
283 |
if ($str_priority = $a_priorities[$priority]) |
T |
284 |
$headers['X-Priority'] = sprintf("%d (%s)", $priority, ucfirst($str_priority)); |
|
285 |
} |
|
286 |
|
620439
|
287 |
if (!empty($_POST['_receipt'])) |
T |
288 |
{ |
|
289 |
$headers['Return-Receipt-To'] = $identity_arr['string']; |
|
290 |
$headers['Disposition-Notification-To'] = $identity_arr['string']; |
|
291 |
} |
4e17e6
|
292 |
|
T |
293 |
// additional headers |
53e79d
|
294 |
$headers['Message-ID'] = $message_id; |
A |
295 |
$headers['X-Sender'] = $from; |
|
296 |
|
ea7c46
|
297 |
if (!empty($CONFIG['useragent'])) |
4e17e6
|
298 |
$headers['User-Agent'] = $CONFIG['useragent']; |
T |
299 |
|
940fc1
|
300 |
$isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST)); |
A |
301 |
$isHtml = ($isHtmlVal == "1"); |
|
302 |
|
c03095
|
303 |
// fetch message body |
ea7c46
|
304 |
$message_body = get_input_value('_message', RCUBE_INPUT_POST, TRUE, $message_charset); |
940fc1
|
305 |
|
65605c
|
306 |
if (!$savedraft) { |
A |
307 |
// remove signature's div ID |
|
308 |
if ($isHtml) |
|
309 |
$message_body = preg_replace('/\s*id="_rc_sig"/', '', $message_body); |
4e17e6
|
310 |
|
65605c
|
311 |
// generic footer for all messages |
A |
312 |
if (!empty($CONFIG['generic_message_footer'])) { |
|
313 |
$footer = file_get_contents(realpath($CONFIG['generic_message_footer'])); |
ecb9fb
|
314 |
$footer = rcube_charset_convert($footer, RCMAIL_CHARSET, $message_charset); |
65605c
|
315 |
} |
A |
316 |
} |
a0109c
|
317 |
|
ab6f80
|
318 |
// create extended PEAR::Mail_mime instance |
83a763
|
319 |
$MAIL_MIME = new rcube_mail_mime($RCMAIL->config->header_delimiter()); |
a0109c
|
320 |
|
S |
321 |
// For HTML-formatted messages, construct the MIME message with both |
|
322 |
// the HTML part and the plain-text part |
|
323 |
|
cc97ea
|
324 |
if ($isHtml) { |
T |
325 |
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'html', 'message' => $MAIL_MIME)); |
|
326 |
$MAIL_MIME->setHTMLBody($plugin['body'] . ($footer ? "\r\n<pre>".$footer.'</pre>' : '')); |
a0109c
|
327 |
|
S |
328 |
// add a plain text version of the e-mail as an alternative part. |
cc97ea
|
329 |
$h2t = new html2text($plugin['body'], false, true, 0); |
T |
330 |
$plainTextPart = rc_wordwrap($h2t->get_text(), 75, "\r\n") . ($footer ? "\r\n".$footer : ''); |
65605c
|
331 |
$plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true); |
cc97ea
|
332 |
if (!strlen($plainTextPart)) { |
212352
|
333 |
// empty message body breaks attachment handling in drafts |
T |
334 |
$plainTextPart = "\r\n"; |
cc97ea
|
335 |
} |
T |
336 |
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $plainTextPart, 'type' => 'alternative', 'message' => $MAIL_MIME)); |
|
337 |
$MAIL_MIME->setTXTBody($plugin['body']); |
a0109c
|
338 |
|
S |
339 |
// look for "emoticon" images from TinyMCE and copy into message as attachments |
24ed41
|
340 |
$message_body = rcmail_attach_emoticons($MAIL_MIME); |
cc97ea
|
341 |
} |
a0109c
|
342 |
else |
S |
343 |
{ |
7145e0
|
344 |
$message_body = rc_wordwrap($message_body, 75, "\r\n"); |
65605c
|
345 |
if ($footer) |
A |
346 |
$message_body .= "\r\n" . $footer; |
a23884
|
347 |
$message_body = wordwrap($message_body, 998, "\r\n", true); |
cc97ea
|
348 |
if (!strlen($message_body)) { |
212352
|
349 |
// empty message body breaks attachment handling in drafts |
T |
350 |
$message_body = "\r\n"; |
a0109c
|
351 |
} |
cc97ea
|
352 |
$plugin = $RCMAIL->plugins->exec_hook('outgoing_message_body', array('body' => $message_body, 'type' => 'plain', 'message' => $MAIL_MIME)); |
T |
353 |
$MAIL_MIME->setTXTBody($plugin['body'], false, true); |
|
354 |
} |
4e17e6
|
355 |
|
33ca14
|
356 |
// chose transfer encoding |
A |
357 |
$charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15'); |
|
358 |
$transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit'; |
4e17e6
|
359 |
|
T |
360 |
// add stored attachments, if any |
cc97ea
|
361 |
if (is_array($_SESSION['compose']['attachments'])) { |
T |
362 |
foreach ($_SESSION['compose']['attachments'] as $id => $attachment) { |
|
363 |
// This hook retrieves the attachment contents from the file storage backend |
|
364 |
$attachment = $RCMAIL->plugins->exec_hook('get_attachment', $attachment); |
|
365 |
|
|
366 |
$dispurl = '/\ssrc\s*=\s*[\'"]*\S+display-attachment\S+file=rcmfile' . preg_quote($attachment['id']) . '[\s\'"]\s*/'; |
|
367 |
$message_body = $MAIL_MIME->getHTMLBody(); |
|
368 |
if ($isHtml && (preg_match($dispurl, $message_body) > 0)) { |
d519ef
|
369 |
$message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'" ', $message_body); |
7145e0
|
370 |
$MAIL_MIME->setHTMLBody($message_body); |
cc97ea
|
371 |
|
T |
372 |
if ($attachment['data']) |
|
373 |
$MAIL_MIME->addHTMLImage($attachment['data'], $attachment['mimetype'], $attachment['name'], false); |
|
374 |
else |
|
375 |
$MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name'], true); |
4315b0
|
376 |
} |
cc97ea
|
377 |
else { |
6d5dba
|
378 |
$ctype = str_replace('image/pjpeg', 'image/jpeg', $attachment['mimetype']); // #1484914 |
cc97ea
|
379 |
$file = $attachment['data'] ? $attachment['data'] : $attachment['path']; |
33ca14
|
380 |
|
A |
381 |
// .eml attachments send inline |
cc97ea
|
382 |
$MAIL_MIME->addAttachment($file, |
8b36d4
|
383 |
$ctype, |
cc97ea
|
384 |
$attachment['name'], |
T |
385 |
($attachment['data'] ? false : true), |
8b36d4
|
386 |
($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'), |
33ca14
|
387 |
($ctype == 'message/rfc822' ? 'inline' : 'attachment'), |
ffae15
|
388 |
$message_charset, '', '', |
cc97ea
|
389 |
$CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL, |
T |
390 |
$CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL |
|
391 |
); |
4315b0
|
392 |
} |
S |
393 |
} |
cc97ea
|
394 |
} |
4e17e6
|
395 |
|
T |
396 |
// add submitted attachments |
cc97ea
|
397 |
if (is_array($_FILES['_attachments']['tmp_name'])) { |
T |
398 |
foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) { |
33ca14
|
399 |
$ctype = $files['type'][$i]; |
A |
400 |
$ctype = str_replace('image/pjpeg', 'image/jpeg', $ctype); // #1484914 |
|
401 |
|
|
402 |
$MAIL_MIME->addAttachment($filepath, $ctype, $files['name'][$i], true, |
cc97ea
|
403 |
$ctype == 'message/rfc822' ? $transfer_encoding : 'base64', |
T |
404 |
'attachment', $message_charset, '', '', |
|
405 |
$CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL, |
|
406 |
$CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL |
|
407 |
); |
|
408 |
} |
|
409 |
} |
f88d41
|
410 |
|
a95e0e
|
411 |
// encoding settings for mail composing |
fba1f5
|
412 |
$MAIL_MIME->setParam(array( |
a23884
|
413 |
'text_encoding' => $transfer_encoding, |
T |
414 |
'html_encoding' => 'quoted-printable', |
|
415 |
'head_encoding' => 'quoted-printable', |
|
416 |
'head_charset' => $message_charset, |
|
417 |
'html_charset' => $message_charset, |
|
418 |
'text_charset' => $message_charset, |
fba1f5
|
419 |
)); |
4e17e6
|
420 |
|
cc97ea
|
421 |
$data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers)); |
T |
422 |
$headers = $data['headers']; |
|
423 |
|
5a6ad2
|
424 |
// encoding subject header with mb_encode provides better results with asian characters |
197601
|
425 |
if (function_exists("mb_encode_mimeheader")) |
b517af
|
426 |
{ |
24fe97
|
427 |
mb_internal_encoding($message_charset); |
fba1f5
|
428 |
$headers['Subject'] = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q'); |
f11541
|
429 |
mb_internal_encoding(RCMAIL_CHARSET); |
b517af
|
430 |
} |
4e17e6
|
431 |
|
fba1f5
|
432 |
// pass headers to message object |
T |
433 |
$MAIL_MIME->headers($headers); |
4e17e6
|
434 |
|
fba1f5
|
435 |
// Begin SMTP Delivery Block |
T |
436 |
if (!$savedraft) |
|
437 |
{ |
fd51e0
|
438 |
// check for 'From' address (identity may be incomplete) |
A |
439 |
if ($identity_arr && !$identity_arr['mailto']) { |
|
440 |
$OUTPUT->show_message('nofromaddress', 'error'); |
|
441 |
$OUTPUT->send('iframe'); |
|
442 |
} |
|
443 |
|
2818f8
|
444 |
$sent = rcmail_deliver_message($MAIL_MIME, $from, $mailto, $smtp_error); |
1966c5
|
445 |
|
S |
446 |
// return to compose page if sending failed |
968bdc
|
447 |
if (!$sent) |
4e17e6
|
448 |
{ |
2818f8
|
449 |
if ($smtp_error) |
A |
450 |
$OUTPUT->show_message($smtp_error['label'], 'error', $smtp_error['vars']); |
|
451 |
else |
|
452 |
$OUTPUT->show_message('sendingfailed', 'error'); |
f11541
|
453 |
$OUTPUT->send('iframe'); |
4e17e6
|
454 |
} |
acb08f
|
455 |
|
A |
456 |
// save message sent time |
|
457 |
if (!empty($CONFIG['sendmail_delay'])) |
4b60fa
|
458 |
$RCMAIL->user->save_prefs(array('last_message_time' => time())); |
1966c5
|
459 |
|
4dae73
|
460 |
// set replied/forwarded flag |
1966c5
|
461 |
if ($_SESSION['compose']['reply_uid']) |
48958e
|
462 |
$IMAP->set_flag($_SESSION['compose']['reply_uid'], 'ANSWERED', $_SESSION['compose']['mailbox']); |
4dae73
|
463 |
else if ($_SESSION['compose']['forward_uid']) |
48958e
|
464 |
$IMAP->set_flag($_SESSION['compose']['forward_uid'], 'FORWARDED', $_SESSION['compose']['mailbox']); |
c03095
|
465 |
|
4dae73
|
466 |
} // End of SMTP Delivery Block |
41fa0b
|
467 |
|
T |
468 |
|
4e17e6
|
469 |
|
1966c5
|
470 |
// Determine which folder to save message |
b068a0
|
471 |
if ($savedraft) |
faf876
|
472 |
$store_target = $CONFIG['drafts_mbox']; |
d583bc
|
473 |
else |
faf876
|
474 |
$store_target = isset($_POST['_store_target']) ? get_input_value('_store_target', RCUBE_INPUT_POST) : $CONFIG['sent_mbox']; |
c03095
|
475 |
|
faf876
|
476 |
if ($store_target) |
4e17e6
|
477 |
{ |
T |
478 |
// check if mailbox exists |
faf876
|
479 |
if (!in_array_nocase($store_target, $IMAP->list_mailboxes())) |
d583bc
|
480 |
{ |
A |
481 |
// folder may be existing but not subscribed (#1485241) |
|
482 |
if (!in_array_nocase($store_target, $IMAP->list_unsubscribed())) |
8b36d4
|
483 |
$store_folder = $IMAP->create_mailbox($store_target, TRUE); |
d583bc
|
484 |
else if ($IMAP->subscribe($store_target)) |
8b36d4
|
485 |
$store_folder = TRUE; |
d583bc
|
486 |
} |
520c36
|
487 |
else |
1966c5
|
488 |
$store_folder = TRUE; |
b068a0
|
489 |
|
4e17e6
|
490 |
// append message to sent box |
1966c5
|
491 |
if ($store_folder) |
faf876
|
492 |
$saved = $IMAP->save_message($store_target, $MAIL_MIME->getMessage()); |
520c36
|
493 |
|
T |
494 |
// raise error if saving failed |
|
495 |
if (!$saved) |
f0f98f
|
496 |
{ |
f11541
|
497 |
raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, |
faf876
|
498 |
'message' => "Could not save message in $store_target"), TRUE, FALSE); |
41fa0b
|
499 |
|
9a5762
|
500 |
if ($savedraft) { |
A |
501 |
$OUTPUT->show_message('errorsaving', 'error'); |
|
502 |
$OUTPUT->send('iframe'); |
|
503 |
} |
f0f98f
|
504 |
} |
4e17e6
|
505 |
|
b068a0
|
506 |
if ($olddraftmessageid) |
T |
507 |
{ |
1966c5
|
508 |
// delete previous saved draft |
4e74d2
|
509 |
$a_deleteid = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$olddraftmessageid); |
A |
510 |
|
c719f3
|
511 |
$deleted = $IMAP->delete_message($IMAP->get_uid($a_deleteid[0], $CONFIG['drafts_mbox']), $CONFIG['drafts_mbox']); |
4e17e6
|
512 |
|
f0f98f
|
513 |
// raise error if deletion of old draft failed |
1966c5
|
514 |
if (!$deleted) |
f11541
|
515 |
raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, |
1966c5
|
516 |
'message' => "Could not delete message from ".$CONFIG['drafts_mbox']), TRUE, FALSE); |
4e17e6
|
517 |
} |
T |
518 |
} |
|
519 |
|
1966c5
|
520 |
if ($savedraft) |
S |
521 |
{ |
c719f3
|
522 |
$msgid = strtr($message_id, array('>' => '', '<' => '')); |
T |
523 |
|
|
524 |
// remember new draft-uid |
4e74d2
|
525 |
$draftids = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid); |
c719f3
|
526 |
$_SESSION['compose']['param']['_draft_uid'] = $IMAP->get_uid($draftids[0], $CONFIG['drafts_mbox']); |
T |
527 |
|
f11541
|
528 |
// display success |
T |
529 |
$OUTPUT->show_message('messagesaved', 'confirmation'); |
f0f98f
|
530 |
|
f11541
|
531 |
// update "_draft_saveid" and the "cmp_hash" to prevent "Unsaved changes" warning |
c719f3
|
532 |
$OUTPUT->command('set_draft_id', $msgid); |
f11541
|
533 |
$OUTPUT->command('compose_field_hash', true); |
41fa0b
|
534 |
|
f0f98f
|
535 |
// start the auto-save timer again |
f11541
|
536 |
$OUTPUT->command('auto_save_start'); |
f0f98f
|
537 |
|
f11541
|
538 |
$OUTPUT->send('iframe'); |
1966c5
|
539 |
} |
S |
540 |
else |
|
541 |
{ |
|
542 |
rcmail_compose_cleanup(); |
9a5762
|
543 |
|
A |
544 |
if ($store_folder && !$saved) |
|
545 |
$OUTPUT->command('sent_successfully', 'error', rcube_label('errorsavingsent')); |
|
546 |
else |
|
547 |
$OUTPUT->command('sent_successfully', 'confirmation', rcube_label('messagesent')); |
f11541
|
548 |
$OUTPUT->send('iframe'); |
1966c5
|
549 |
} |
4e17e6
|
550 |
|
1966c5
|
551 |
?> |