59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * compose.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This code sends a mail. |
10 | * |
11 | * There are 4 modes of operation: |
12 | * - Start new mail |
13 | * - Add an attachment |
14 | * - Send mail |
15 | * - Save As Draft |
16 | * |
17 | * $Id$ |
18 | */ |
f7fb20fe |
19 | |
86725763 |
20 | /* Path for SquirrelMail required files. */ |
21 | define('SM_PATH','../'); |
22 | |
23 | /* SquirrelMail required files. */ |
08185f2a |
24 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
25 | require_once(SM_PATH . 'functions/imap.php'); |
26 | require_once(SM_PATH . 'functions/date.php'); |
27 | require_once(SM_PATH . 'functions/mime.php'); |
86725763 |
28 | require_once(SM_PATH . 'functions/plugin.php'); |
29 | require_once(SM_PATH . 'functions/display_messages.php'); |
30 | require_once(SM_PATH . 'class/deliver/Deliver.class.php'); |
24192f77 |
31 | require_once(SM_PATH . 'functions/addressbook.php'); |
91f2085b |
32 | |
0b97a708 |
33 | /* --------------------- Get globals ------------------------------------- */ |
34 | $username = $_SESSION['username']; |
35 | $onetimepad = $_SESSION['onetimepad']; |
36 | $base_uri = $_SESSION['base_uri']; |
37 | $delimiter = $_SESSION['delimiter']; |
38 | |
39 | if (isset($_POST['return'])) { |
40 | $html_addr_search_done = 'Use Addresses'; |
41 | } |
42 | if ( isset($_SESSION['composesession']) ) { |
43 | $composesession = $_SESSION['composesession']; |
44 | } |
fe369c70 |
45 | sqextractGlobalVar('action'); |
0b97a708 |
46 | sqextractGlobalVar('session'); |
47 | sqextractGlobalVar('mailbox'); |
48 | sqextractGlobalVar('identity'); |
49 | sqextractGlobalVar('send_to'); |
50 | sqextractGlobalVar('send_to_cc'); |
51 | sqextractGlobalVar('send_to_bcc'); |
52 | sqextractGlobalVar('subject'); |
53 | sqextractGlobalVar('body'); |
54 | sqextractGlobalVar('mailprio'); |
55 | sqextractGlobalVar('request_mdn'); |
56 | sqextractGlobalVar('request_dr'); |
57 | sqextractGlobalVar('html_addr_search'); |
58 | sqextractGlobalVar('mail_sent'); |
59 | sqextractGlobalVar('passed_id'); |
fe369c70 |
60 | sqextractGlobalVar('passed_ent_id'); |
4dfb9db7 |
61 | sqextractGlobalVar('send'); |
0b97a708 |
62 | |
63 | if ( isset($_POST['sigappend']) ) { |
64 | $sigappend = $_POST['sigappend']; |
65 | } |
66 | /* From addressbook search */ |
67 | if ( isset($_POST['from_htmladdr_search']) ) { |
68 | $from_htmladdr_search = $_POST['from_htmladdr_search']; |
69 | } |
70 | if ( isset($_POST['addr_search_done']) ) { |
71 | $html_addr_search_done = $_POST['addr_search_done']; |
72 | } |
73 | if ( isset($_POST['send_to_search']) ) { |
74 | $send_to_search = &$_POST['send_to_search']; |
75 | } |
76 | |
77 | /* Attachments */ |
78 | sqextractGlobalVar('attach'); |
79 | if ( isset($_POST['do_delete']) ) { |
80 | $do_delete = $_POST['do_delete']; |
81 | } |
82 | if ( isset($_POST['delete']) ) { |
83 | $delete = &$_POST['delete']; |
84 | } |
4dfb9db7 |
85 | if ( isset($_SESSION['compose_messages']) ) { |
86 | $compose_messages = &$_SESSION['compose_messages']; |
0b97a708 |
87 | } |
88 | |
4dfb9db7 |
89 | |
0b97a708 |
90 | /* Forward message as attachment */ |
91 | if ( isset($_GET['attachedmessages']) ) { |
92 | $attachedmessages = $_GET['attachedmessages']; |
93 | } |
94 | |
95 | /* Drafts */ |
96 | sqextractGlobalVar('draft'); |
97 | sqextractGlobalVar('draft_id'); |
98 | sqextractGlobalVar('ent_num'); |
99 | sqextractGlobalVar('saved_draft'); |
100 | sqextractGlobalVar('delete_draft'); |
101 | |
102 | $key = $_COOKIE['key']; |
103 | |
09044055 |
104 | /* --------------------- Specific Functions ------------------------------ */ |
0b97a708 |
105 | |
41b94d65 |
106 | function replyAllString($header) { |
107 | global $include_self_reply_all, $username, $data_dir; |
98e47335 |
108 | $excl_ar = array(); |
41b94d65 |
109 | /** |
110 | * 1) Remove the addresses we'll be sending the message 'to' |
111 | */ |
112 | $url_replytoall_avoid_addrs = ''; |
113 | if (isset($header->replyto)) { |
114 | $excl_ar = $header->getAddr_a('replyto'); |
115 | } |
116 | /** |
117 | * 2) Remove our identities from the CC list (they still can be in the |
118 | * TO list) only if $include_self_reply_all is turned off |
119 | */ |
120 | if (!$include_self_reply_all) { |
2464e20d |
121 | $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address'))); |
41b94d65 |
122 | $excl_ar[$email_address] = ''; |
41b94d65 |
123 | $idents = getPref($data_dir, $username, 'identities'); |
124 | if ($idents != '' && $idents > 1) { |
fd54bb4e |
125 | $first_id = false; |
41b94d65 |
126 | for ($i = 1; $i < $idents; $i ++) { |
127 | $cur_email_address = getPref($data_dir, $username, |
128 | 'email_address' . $i); |
2464e20d |
129 | $cur_email_address = strtolower(trim($cur_email_address)); |
fd54bb4e |
130 | $excl_ar[$cur_email_address] = ''; |
41b94d65 |
131 | } |
132 | } |
133 | } |
134 | |
135 | /** |
136 | * 3) get the addresses. |
137 | */ |
138 | $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); |
139 | |
140 | /** |
141 | * 4) generate the string. |
142 | */ |
143 | $url_replytoallcc = ''; |
144 | foreach( $url_replytoall_ar as $email => $personal) { |
145 | if ($personal) { |
fd54bb4e |
146 | $url_replytoallcc .= ", \"$personal\" <$email>"; |
41b94d65 |
147 | } else { |
fd54bb4e |
148 | $url_replytoallcc .= ', '. $email; |
41b94d65 |
149 | } |
150 | } |
151 | $url_replytoallcc = substr($url_replytoallcc,2); |
152 | return $url_replytoallcc; |
09044055 |
153 | } |
154 | |
41b94d65 |
155 | function getforwardHeader($orig_header) { |
19c6f7a7 |
156 | global $editor_size; |
157 | |
a61878d0 |
158 | $display = array( _("Subject") => strlen(_("Subject")), |
159 | _("From") => strlen(_("From")), |
160 | _("Date") => strlen(_("Date")), |
161 | _("To") => strlen(_("To")), |
162 | _("Cc") => strlen(_("Cc")) ); |
a45887d7 |
163 | $maxsize = max($display); |
164 | $indent = str_pad('',$maxsize+2); |
165 | foreach($display as $key => $val) { |
166 | $display[$key] = $key .': '. str_pad('', $maxsize - $val); |
167 | } |
a61878d0 |
168 | $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) . |
169 | "\n". $display[_("Subject")] . |
170 | decodeHeader($orig_header->subject) . "\n" . |
171 | $display[_("From")] . |
172 | decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" . |
173 | $display[_("Date")] . |
174 | getLongDateString( $orig_header->date ). "\n" . |
175 | $display[_("To")] . |
176 | decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n"; |
41b94d65 |
177 | if ($orig_header->cc != array() && $orig_header->cc !='') { |
c4d02444 |
178 | $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n"; |
41b94d65 |
179 | } |
a61878d0 |
180 | $bodyTop .= str_pad('', $editor_size -2 , '-') . |
181 | "\n"; |
41b94d65 |
182 | return $bodyTop; |
183 | } |
09044055 |
184 | /* ----------------------------------------------------------------------- */ |
185 | |
44560457 |
186 | /* |
187 | * If the session is expired during a post this restores the compose session |
188 | * vars. |
189 | */ |
5da08ef7 |
190 | if (sqsession_is_registered('session_expired_post')) { |
191 | $session_expired_post = $_SESSION['session_expired_post']; |
40934000 |
192 | /* |
193 | * extra check for username so we don't display previous post data from |
194 | * another user during this session. |
195 | */ |
196 | if ($session_expired_post['username'] != $username) { |
0ec1a14b |
197 | unset($session_expired_post); |
0b97a708 |
198 | sqsession_unregister('session_expired_post'); |
0ec1a14b |
199 | session_write_close(); |
40934000 |
200 | } else { |
201 | foreach ($session_expired_post as $postvar => $val) { |
202 | if (isset($val)) { |
203 | $$postvar = $val; |
204 | } else { |
205 | $$postvar = ''; |
206 | } |
207 | } |
0ec1a14b |
208 | $compose_messages = unserialize(urldecode($restoremessages)); |
209 | sqsession_register($compose_messages,'compose_messages'); |
210 | sqsession_register($composesession,'composesession'); |
40934000 |
211 | if (isset($send)) { |
212 | unset($send); |
213 | } |
214 | $session_expired = true; |
215 | } |
5da08ef7 |
216 | unset($session_expired_post); |
0b97a708 |
217 | sqsession_unregister('session_expired_post'); |
5da08ef7 |
218 | session_write_close(); |
40934000 |
219 | if (!isset($mailbox)) { |
220 | $mailbox = ''; |
221 | } |
222 | if ($compose_new_win == '1') { |
223 | compose_Header($color, $mailbox); |
224 | } else { |
225 | displayPageHeader($color, $mailbox); |
226 | } |
227 | showInputForm($session, false); |
228 | exit(); |
44560457 |
229 | } |
da95c4b6 |
230 | if (!isset($composesession)) { |
231 | $composesession = 0; |
a43e4b90 |
232 | sqsession_register(0,'composesession'); |
da95c4b6 |
233 | } |
234 | |
d7f8e6e6 |
235 | if (!isset($session) || (isset($newmessage) && $newmessage)) { |
0b97a708 |
236 | sqsession_unregister('composesession'); |
da95c4b6 |
237 | $session = "$composesession" +1; |
91f2085b |
238 | $composesession = $session; |
a43e4b90 |
239 | sqsession_register($composesession,'composesession'); |
d7f8e6e6 |
240 | } |
a43e4b90 |
241 | if (!isset($compose_messages)) { |
242 | $compose_messages = array(); |
243 | } |
40934000 |
244 | if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { |
245 | /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */ |
5628fdde |
246 | $composeMessage = new Message(); |
a43e4b90 |
247 | $rfc822_header = new Rfc822Header(); |
248 | $composeMessage->rfc822_header = $rfc822_header; |
249 | $composeMessage->reply_rfc822_header = ''; |
250 | $compose_messages[$session] = $composeMessage; |
5628fdde |
251 | sqsession_register($compose_messages,'compose_messages'); |
252 | } else { |
253 | $composeMessage=$compose_messages[$session]; |
a43e4b90 |
254 | } |
a43e4b90 |
255 | |
00793a25 |
256 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
257 | $mailbox = 'INBOX'; |
258 | } |
259 | |
4dfb9db7 |
260 | if ($draft) { |
261 | /* |
262 | * Set $default_charset to correspond with the user's selection |
263 | * of language interface. |
264 | */ |
265 | set_my_charset(); |
266 | $composeMessage=$compose_messages[$session]; |
b7ff469f |
267 | if (! deliverMessage($composeMessage, true)) { |
da95c4b6 |
268 | showInputForm($session); |
00793a25 |
269 | exit(); |
734f4ee6 |
270 | } else { |
5da08ef7 |
271 | unset($compose_messages[$session]); |
00793a25 |
272 | $draft_message = _("Draft Email Saved"); |
273 | /* If this is a resumed draft, then delete the original */ |
274 | if(isset($delete_draft)) { |
7058a2a9 |
275 | Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) . |
fae72101 |
276 | "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes"); |
00793a25 |
277 | exit(); |
7058a2a9 |
278 | } |
9c3e6cd4 |
279 | else { |
280 | if ($compose_new_win == '1') { |
da95c4b6 |
281 | Header("Location: compose.php?saved_draft=yes&session=$composesession"); |
a61878d0 |
282 | exit(); |
9c3e6cd4 |
283 | } |
284 | else { |
a61878d0 |
285 | Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". |
286 | "&startMessage=1¬e=".urlencode($draft_message)); |
287 | exit(); |
9c3e6cd4 |
288 | } |
00793a25 |
289 | } |
290 | } |
291 | } |
292 | |
4dfb9db7 |
293 | if ($send) { |
0b97a708 |
294 | if (isset($_FILES['attachfile']) && |
295 | $_FILES['attachfile']['tmp_name'] && |
296 | $_FILES['attachfile']['tmp_name'] != 'none') { |
da95c4b6 |
297 | $AttachFailure = saveAttachedFiles($session); |
00793a25 |
298 | } |
299 | if (checkInput(false) && !isset($AttachFailure)) { |
4c8f834a |
300 | if ($mailbox == "All Folders") { |
301 | /* We entered compose via the search results page */ |
302 | $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */ |
303 | } |
00793a25 |
304 | $urlMailbox = urlencode (trim($mailbox)); |
3f6b1b6f |
305 | if (! isset($passed_id)) { |
306 | $passed_id = 0; |
00793a25 |
307 | } |
308 | /* |
309 | * Set $default_charset to correspond with the user's selection |
7058a2a9 |
310 | * of language interface. |
00793a25 |
311 | */ |
312 | set_my_charset(); |
00793a25 |
313 | /* |
314 | * This is to change all newlines to \n |
7058a2a9 |
315 | * We'll change them to \r\n later (in the sendMessage function) |
00793a25 |
316 | */ |
317 | $body = str_replace("\r\n", "\n", $body); |
318 | $body = str_replace("\r", "\n", $body); |
319 | |
320 | /* |
321 | * Rewrap $body so that no line is bigger than $editor_size |
322 | * This should only really kick in the sqWordWrap function |
f302d704 |
323 | * if the browser doesn't support "VIRTUAL" as the wrap type. |
00793a25 |
324 | */ |
325 | $body = explode("\n", $body); |
326 | $newBody = ''; |
327 | foreach ($body as $line) { |
328 | if( $line <> '-- ' ) { |
329 | $line = rtrim($line); |
330 | } |
331 | if (strlen($line) <= $editor_size + 1) { |
332 | $newBody .= $line . "\n"; |
734f4ee6 |
333 | } else { |
e0858036 |
334 | sqWordWrap($line, $editor_size); |
335 | $newBody .= $line . "\n"; |
00793a25 |
336 | } |
337 | } |
338 | $body = $newBody; |
e02775fe |
339 | do_hook('compose_send'); |
a43e4b90 |
340 | $composeMessage=$compose_messages[$session]; |
d5181a1d |
341 | |
b7ff469f |
342 | $Result = deliverMessage($composeMessage); |
00793a25 |
343 | if (! $Result) { |
da95c4b6 |
344 | showInputForm($session); |
00793a25 |
345 | exit(); |
346 | } |
0ec1a14b |
347 | unset($compose_messages[$session]); |
00793a25 |
348 | if ( isset($delete_draft)) { |
7058a2a9 |
349 | Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ). |
fae72101 |
350 | "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes"); |
00793a25 |
351 | exit(); |
352 | } |
9c3e6cd4 |
353 | if ($compose_new_win == '1') { |
0ec1a14b |
354 | |
d7f8e6e6 |
355 | Header("Location: compose.php?mail_sent=yes"); |
9c3e6cd4 |
356 | } |
357 | else { |
fae72101 |
358 | Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". |
359 | "&startMessage=1"); |
9c3e6cd4 |
360 | } |
734f4ee6 |
361 | } else { |
9c3e6cd4 |
362 | if ($compose_new_win == '1') { |
363 | compose_Header($color, $mailbox); |
364 | } |
365 | else { |
366 | displayPageHeader($color, $mailbox); |
367 | } |
00793a25 |
368 | if (isset($AttachFailure)) { |
369 | plain_error_message(_("Could not move/copy file. File not attached"), |
370 | $color); |
371 | } |
00793a25 |
372 | checkInput(true); |
da95c4b6 |
373 | showInputForm($session); |
00793a25 |
374 | /* sqimap_logout($imapConnection); */ |
375 | } |
e02775fe |
376 | } elseif (isset($html_addr_search_done)) { |
9c3e6cd4 |
377 | if ($compose_new_win == '1') { |
378 | compose_Header($color, $mailbox); |
379 | } |
380 | else { |
381 | displayPageHeader($color, $mailbox); |
382 | } |
00793a25 |
383 | |
384 | if (isset($send_to_search) && is_array($send_to_search)) { |
385 | foreach ($send_to_search as $k => $v) { |
386 | if (substr($k, 0, 1) == 'T') { |
387 | if ($send_to) { |
388 | $send_to .= ', '; |
389 | } |
390 | $send_to .= $v; |
391 | } |
392 | elseif (substr($k, 0, 1) == 'C') { |
393 | if ($send_to_cc) { |
394 | $send_to_cc .= ', '; |
395 | } |
396 | $send_to_cc .= $v; |
397 | } |
398 | elseif (substr($k, 0, 1) == 'B') { |
399 | if ($send_to_bcc) { |
400 | $send_to_bcc .= ', '; |
401 | } |
402 | $send_to_bcc .= $v; |
403 | } |
404 | } |
405 | } |
da95c4b6 |
406 | showInputForm($session); |
e02775fe |
407 | } elseif (isset($html_addr_search)) { |
0b97a708 |
408 | if (isset($_FILES['attachfile']) && |
409 | $_FILES['attachfile']['tmp_name'] && |
410 | $_FILES['attachfile']['tmp_name'] != 'none') { |
411 | if(saveAttachedFiles($session)) { |
00793a25 |
412 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
413 | } |
414 | } |
415 | /* |
416 | * I am using an include so as to elminiate an extra unnecessary |
417 | * click. If you can think of a better way, please implement it. |
418 | */ |
419 | include_once('./addrbook_search_html.php'); |
e02775fe |
420 | } elseif (isset($attach)) { |
da95c4b6 |
421 | if (saveAttachedFiles($session)) { |
00793a25 |
422 | plain_error_message(_("Could not move/copy file. File not attached"), $color); |
423 | } |
9c3e6cd4 |
424 | if ($compose_new_win == '1') { |
425 | compose_Header($color, $mailbox); |
426 | } |
427 | else { |
428 | displayPageHeader($color, $mailbox); |
429 | } |
da95c4b6 |
430 | showInputForm($session); |
01265fba |
431 | } |
432 | elseif (isset($sigappend)) { |
433 | $idents = getPref($data_dir, $username, 'identities', 0); |
434 | if ($idents > 1) { |
435 | if ($identity == 'default') { |
436 | $no = 'g'; |
437 | } else { |
438 | $no = $identity; |
439 | } |
440 | $signature = getSig($data_dir, $username, $no); |
441 | } |
442 | $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; |
443 | if ($compose_new_win == '1') { |
444 | compose_Header($color, $mailbox); |
445 | } else { |
446 | displayPageHeader($color, $mailbox); |
447 | } |
da95c4b6 |
448 | showInputForm($session); |
e02775fe |
449 | } elseif (isset($do_delete)) { |
9c3e6cd4 |
450 | if ($compose_new_win == '1') { |
451 | compose_Header($color, $mailbox); |
452 | } |
453 | else { |
454 | displayPageHeader($color, $mailbox); |
455 | } |
00793a25 |
456 | |
00793a25 |
457 | if (isset($delete) && is_array($delete)) { |
a43e4b90 |
458 | $composeMessage = $compose_messages[$session]; |
00793a25 |
459 | foreach($delete as $index) { |
a43e4b90 |
460 | $attached_file = $composeMessage->entities[$index]->att_local_name; |
a61878d0 |
461 | unlink ($attached_file); |
a43e4b90 |
462 | unset ($composeMessage->entities[$index]); |
00793a25 |
463 | } |
a43e4b90 |
464 | $new_entities = array(); |
465 | foreach ($composeMessage->entities as $entity) { |
466 | $new_entities[] = $entity; |
467 | } |
468 | $composeMessage->entities = $new_entities; |
469 | $compose_messages[$session] = $composeMessage; |
470 | sqsession_register($compose_messages, 'compose_messages'); |
00793a25 |
471 | } |
da95c4b6 |
472 | showInputForm($session); |
734f4ee6 |
473 | } else { |
00793a25 |
474 | /* |
475 | * This handles the default case as well as the error case |
476 | * (they had the same code) --> if (isset($smtpErrors)) |
477 | */ |
44560457 |
478 | |
479 | if ($compose_new_win == '1') { |
480 | compose_Header($color, $mailbox); |
481 | } else { |
482 | displayPageHeader($color, $mailbox); |
483 | } |
00793a25 |
484 | |
485 | $newmail = true; |
486 | |
a61878d0 |
487 | if (!isset($passed_ent_id)) { |
488 | $passed_ent_id = ''; |
489 | } |
490 | if (!isset($passed_id)) { |
491 | $passed_id = ''; |
492 | } |
493 | if (!isset($mailbox)) { |
494 | $mailbox = ''; |
495 | } |
496 | if (!isset($action)) { |
497 | $action = ''; |
498 | } |
41b94d65 |
499 | |
44560457 |
500 | $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); |
b9928adc |
501 | |
502 | /* in case the origin is not read_body.php */ |
503 | if (isset($send_to)) { |
504 | $values['send_to'] = $send_to; |
505 | } |
506 | if (isset($send_to_cc)) { |
44560457 |
507 | $values['send_to_cc'] = $send_to_cc; |
b9928adc |
508 | } |
509 | if (isset($send_to_bcc)) { |
44560457 |
510 | $values['send_to_bcc'] = $send_to_bcc; |
b9928adc |
511 | } |
41b94d65 |
512 | showInputForm($session, $values); |
00793a25 |
513 | } |
514 | |
515 | exit(); |
516 | |
00793a25 |
517 | /**************** Only function definitions go below *************/ |
518 | |
519 | |
48985d59 |
520 | /* This function is used when not sending or adding attachments */ |
44560457 |
521 | function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { |
91f2085b |
522 | global $editor_size, $default_use_priority, $body, |
44560457 |
523 | $use_signature, $composesession, $data_dir, $username, |
a43e4b90 |
524 | $username, $key, $imapServerAddress, $imapPort, $compose_messages, |
525 | $composeMessage; |
e7f1a81d |
526 | |
91f2085b |
527 | $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; |
bdb92db3 |
528 | $mailprio = 3; |
44560457 |
529 | |
41b94d65 |
530 | if ($passed_id) { |
44560457 |
531 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
a61878d0 |
532 | $imapPort, 0); |
533 | |
48985d59 |
534 | sqimap_mailbox_select($imapConnection, $mailbox); |
41b94d65 |
535 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
a43e4b90 |
536 | |
a61878d0 |
537 | $body = ''; |
538 | if ($passed_ent_id) { |
539 | /* redefine the messsage in case of message/rfc822 */ |
540 | $message = $message->getEntity($passed_ent_id); |
541 | /* message is an entity which contains the envelope and type0=message |
542 | * and type1=rfc822. The actual entities are childs from |
543 | * $message->entities[0]. That's where the encoding and is located |
544 | */ |
545 | |
546 | $entities = $message->entities[0]->findDisplayEntity |
547 | (array(), $alt_order = array('text/plain')); |
548 | if (!count($entities)) { |
549 | $entities = $message->entities[0]->findDisplayEntity |
550 | (array(), $alt_order = array('text/plain','html/plain')); |
551 | } |
552 | $orig_header = $message->rfc822_header; /* here is the envelope located */ |
553 | /* redefine the message for picking up the attachments */ |
554 | $message = $message->entities[0]; |
555 | |
556 | } else { |
557 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); |
558 | if (!count($entities)) { |
559 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); |
560 | } |
561 | $orig_header = $message->rfc822_header; |
562 | } |
a43e4b90 |
563 | |
41b94d65 |
564 | $encoding = $message->header->encoding; |
a61878d0 |
565 | $type0 = $message->type0; |
566 | $type1 = $message->type1; |
41b94d65 |
567 | foreach ($entities as $ent) { |
a61878d0 |
568 | $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); |
569 | $body_part_entity = $message->getEntity($ent); |
570 | $bodypart = decodeBody($unencoded_bodypart, |
571 | $body_part_entity->header->encoding); |
572 | if ($type1 == 'html') { |
573 | $bodypart = strip_tags($bodypart); |
574 | } |
575 | $body .= $bodypart; |
576 | } |
577 | if ($default_use_priority) { |
578 | $mailprio = substr($orig_header->priority,0,1); |
579 | if (!$mailprio) { |
580 | $mailprio = 3; |
581 | } |
582 | } else { |
583 | $mailprio = ''; |
584 | } |
a43e4b90 |
585 | //ClearAttachments($session); |
bdb92db3 |
586 | |
587 | $identity = ''; |
588 | $idents = getPref($data_dir, $username, 'identities'); |
a45887d7 |
589 | $from_o = $orig_header->from; |
bdb92db3 |
590 | if (is_object($from_o)) { |
591 | $orig_from = $from_o->getAddress(); |
592 | } else { |
593 | $orig_from = ''; |
a61878d0 |
594 | } |
fd54bb4e |
595 | $identities = array(); |
bdb92db3 |
596 | if (!empty($idents) && $idents > 1) { |
fd54bb4e |
597 | $identities[] = '"'. getPref($data_dir, $username, 'full_name') |
598 | . '" <' . getPref($data_dir, $username, 'email_address') . '>'; |
599 | for ($i = 1; $i < $idents; $i++) { |
600 | $enc_from_name = '"'. |
601 | getPref($data_dir, $username, 'full_name' . $i) . |
602 | '" <' . |
603 | getPref($data_dir, $username, 'email_address' . $i) . '>'; |
604 | if ($enc_from_name == $orig_from && $i) { |
a61878d0 |
605 | $identity = $i; |
606 | break; |
607 | } |
fd54bb4e |
608 | $identities[] = $enc_from_name; |
a61878d0 |
609 | } |
fd54bb4e |
610 | $identity_match = $orig_header->findAddress($identities); |
611 | if ($identity_match) { |
612 | $identity = $identity_match; |
613 | } |
bdb92db3 |
614 | } |
a61878d0 |
615 | |
616 | switch ($action) { |
617 | case ('draft'): |
618 | $use_signature = FALSE; |
c3d1d2cf |
619 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
620 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
621 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
a61878d0 |
622 | $subject = decodeHeader($orig_header->subject); |
623 | |
624 | $body_ary = explode("\n", $body); |
625 | $cnt = count($body_ary) ; |
626 | $body = ''; |
627 | for ($i=0; $i < $cnt; $i++) { |
628 | if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) { |
629 | sqWordWrap($body_ary[$i], $editor_size ); |
630 | $body .= $body_ary[$i] . "\n"; |
631 | } |
632 | unset($body_ary[$i]); |
633 | } |
634 | sqUnWordWrap($body); |
a43e4b90 |
635 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
a61878d0 |
636 | break; |
a45887d7 |
637 | case ('edit_as_new'): |
c3d1d2cf |
638 | $send_to = decodeHeader($orig_header->getAddr_s('to')); |
639 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc')); |
640 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc')); |
a61878d0 |
641 | $subject = decodeHeader($orig_header->subject); |
642 | $mailprio = $orig_header->priority; |
643 | $orig_from = ''; |
a43e4b90 |
644 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
a61878d0 |
645 | sqUnWordWrap($body); |
646 | break; |
647 | case ('forward'): |
648 | $send_to = ''; |
649 | $subject = decodeHeader($orig_header->subject); |
650 | if ((substr(strtolower($subject), 0, 4) != 'fwd:') && |
651 | (substr(strtolower($subject), 0, 5) != '[fwd:') && |
652 | (substr(strtolower($subject), 0, 6) != '[ fwd:')) { |
653 | $subject = '[Fwd: ' . $subject . ']'; |
654 | } |
655 | $body = getforwardHeader($orig_header) . $body; |
656 | sqUnWordWrap($body); |
a43e4b90 |
657 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
d5181a1d |
658 | $body = "\n" . $body; |
a61878d0 |
659 | break; |
660 | case ('forward_as_attachment'): |
a43e4b90 |
661 | $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); |
a61878d0 |
662 | $body = ''; |
663 | break; |
a45887d7 |
664 | case ('reply_all'): |
a61878d0 |
665 | $send_to_cc = replyAllString($orig_header); |
666 | case ('reply'): |
667 | $send_to = $orig_header->reply_to; |
f55207e3 |
668 | if (is_array($send_to) && count($send_to)) { |
52cf8e76 |
669 | $send_to = decodeHeader($orig_header->getAddr_s('reply_to')); |
f55207e3 |
670 | } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */ |
52cf8e76 |
671 | $send_to = decodeHeader($orig_header->getAddr_s('reply_to')); |
f55207e3 |
672 | } else { |
c3d1d2cf |
673 | $send_to = decodeHeader($orig_header->getAddr_s('from')); |
a61878d0 |
674 | } |
675 | $subject = decodeHeader($orig_header->subject); |
676 | $subject = str_replace('"', "'", $subject); |
677 | $subject = trim($subject); |
678 | if (substr(strtolower($subject), 0, 3) != 're:') { |
679 | $subject = 'Re: ' . $subject; |
680 | } |
681 | /* this corrects some wrapping/quoting problems on replies */ |
682 | $rewrap_body = explode("\n", $body); |
cf7a1725 |
683 | $from = (is_array($orig_header->from)) ? |
684 | $orig_header->from[0] : $orig_header->from; |
4dfb9db7 |
685 | $body = getReplyCitation($from->getAddress(false)); |
6339f68f |
686 | sqUnWordWrap($body); |
a61878d0 |
687 | $cnt = count($rewrap_body); |
688 | for ($i=0;$i<$cnt;$i++) { |
cf7a1725 |
689 | sqWordWrap($rewrap_body[$i], ($editor_size)); |
a61878d0 |
690 | if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) { |
691 | $gt = $matches[1]; |
cf7a1725 |
692 | $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n"; |
a61878d0 |
693 | } else { |
cf7a1725 |
694 | $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n"; |
a61878d0 |
695 | } |
696 | unset($rewrap_body[$i]); |
697 | } |
a43e4b90 |
698 | $composeMessage->reply_rfc822_header = $orig_header; |
a61878d0 |
699 | break; |
700 | default: |
701 | break; |
41b94d65 |
702 | } |
a43e4b90 |
703 | $compose_messages[$session] = $composeMessage; |
704 | sqsession_register($compose_messages, 'compose_messages'); |
5da08ef7 |
705 | session_write_close(); |
a61878d0 |
706 | sqimap_logout($imapConnection); |
41b94d65 |
707 | } |
a61878d0 |
708 | $ret = array( 'send_to' => $send_to, |
709 | 'send_to_cc' => $send_to_cc, |
710 | 'send_to_bcc' => $send_to_bcc, |
711 | 'subject' => $subject, |
712 | 'mailprio' => $mailprio, |
713 | 'body' => $body, |
714 | 'identity' => $identity ); |
715 | |
41b94d65 |
716 | return ($ret); |
48985d59 |
717 | } /* function newMail() */ |
718 | |
a43e4b90 |
719 | function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) { |
59edcad6 |
720 | global $attachment_dir, $username, $data_dir, $squirrelmail_language; |
48985d59 |
721 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
41b94d65 |
722 | if (!count($message->entities) || |
723 | ($message->type0 == 'message' && $message->type1 == 'rfc822')) { |
724 | if ( !in_array($message->entity_id, $entities) && $message->entity_id) { |
a43e4b90 |
725 | switch ($message->type0) { |
726 | case 'message': |
727 | if ($message->type1 == 'rfc822') { |
728 | $filename = decodeHeader($message->rfc822_header->subject.'.eml'); |
729 | if ($filename == "") { |
730 | $filename = "untitled-".$message->entity_id.'.eml'; |
731 | } |
732 | } else { |
733 | $filename = decodeHeader($message->getFilename()); |
734 | } |
735 | break; |
736 | default: |
737 | $filename = decodeHeader($message->getFilename()); |
738 | break; |
739 | } |
740 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
741 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
742 | $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename); |
743 | } |
744 | |
745 | $localfilename = GenerateRandomString(32, '', 7); |
746 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
747 | while (file_exists($full_localfilename)) { |
748 | $localfilename = GenerateRandomString(32, '', 7); |
749 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
750 | } |
751 | $message->att_local_name = $full_localfilename; |
752 | if (!$message->mime_header) { /* temporary hack */ |
753 | $message->mime_header = $message->header; |
754 | } |
755 | |
756 | $composeMessage->addEntity($message); |
757 | |
758 | /* Write Attachment to file */ |
759 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb'); |
760 | fputs($fp, decodeBody(mime_fetch_body($imapConnection, |
761 | $passed_id, $message->entity_id), |
762 | $message->header->encoding)); |
763 | fclose ($fp); |
48985d59 |
764 | } |
734f4ee6 |
765 | } else { |
a43e4b90 |
766 | for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) { |
767 | $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection); |
48985d59 |
768 | } |
769 | } |
a43e4b90 |
770 | // setPref($data_dir, $username, 'attachments', serialize($attachments)); |
771 | return $composeMessage; |
48985d59 |
772 | } |
773 | |
a43e4b90 |
774 | function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
756406df |
775 | $passed_ent_id='', $imapConnection) { |
a6ec592e |
776 | global $attachments, $attachment_dir, $username, $data_dir, $uid_support; |
777 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
756406df |
778 | if (!$passed_ent_id) { |
a61878d0 |
779 | $body_a = sqimap_run_command($imapConnection, |
780 | 'FETCH '.$passed_id.' RFC822', |
781 | TRUE, $response, $readmessage, |
782 | $uid_support); |
756406df |
783 | } else { |
784 | $body_a = sqimap_run_command($imapConnection, |
a61878d0 |
785 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
786 | TRUE, $response, $readmessage, $uid_support); |
787 | $message = $message->parent; |
756406df |
788 | } |
a6ec592e |
789 | if ($response = 'OK') { |
a61878d0 |
790 | $subject = encodeHeader($message->rfc822_header->subject); |
791 | array_shift($body_a); |
792 | $body = implode('', $body_a) . "\r\n"; |
793 | |
794 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
795 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
796 | |
a43e4b90 |
797 | $fp = fopen( $full_localfilename, 'w'); |
a61878d0 |
798 | fwrite ($fp, $body); |
799 | fclose($fp); |
a43e4b90 |
800 | $composeMessage->initAttachment('message/rfc822',$subject.'.eml', |
801 | $full_localfilename); |
802 | } |
803 | return $composeMessage; |
a6ec592e |
804 | } |
805 | |
41b94d65 |
806 | function showInputForm ($session, $values=false) { |
a94c1db1 |
807 | global $send_to, $send_to_cc, $body, |
48985d59 |
808 | $passed_body, $color, $use_signature, $signature, $prefix_sig, |
809 | $editor_size, $attachments, $subject, $newmail, |
41b94d65 |
810 | $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox, |
48985d59 |
811 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
812 | $username, $data_dir, $identity, $draft_id, $delete_draft, |
9c3e6cd4 |
813 | $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win, |
44560457 |
814 | $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action, |
ab4700c3 |
815 | $username, $compose_messages, $composesession, $default_charset; |
a43e4b90 |
816 | |
817 | $composeMessage = $compose_messages[$session]; |
48985d59 |
818 | |
3b487216 |
819 | $subject = decodeHeader($subject, false); |
41b94d65 |
820 | if ($values) { |
821 | $send_to = $values['send_to']; |
822 | $send_to_cc = $values['send_to_cc']; |
823 | $send_to_bcc = $values['send_to_bcc']; |
824 | $subject = $values['subject']; |
825 | $mailprio = $values['mailprio']; |
826 | $body = $values['body']; |
d3c13a51 |
827 | $identity = (int) $values['identity']; |
41b94d65 |
828 | } |
829 | |
48985d59 |
830 | if ($use_javascript_addr_book) { |
831 | echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" . |
832 | 'function open_abook() { ' . "\n" . |
833 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
834 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
835 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
836 | ' nwin.opener = document.windows;' . "\n" . |
837 | "}\n" . |
838 | '// --></SCRIPT>' . "\n\n"; |
839 | } |
840 | |
41b94d65 |
841 | echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' . |
842 | 'ENCTYPE="multipart/form-data"'; |
48985d59 |
843 | do_hook("compose_form"); |
57257333 |
844 | |
48985d59 |
845 | echo ">\n"; |
846 | |
41b94d65 |
847 | if ($action == 'draft') { |
848 | echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n"; |
48985d59 |
849 | } |
850 | if (isset($delete_draft)) { |
851 | echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n"; |
852 | } |
da95c4b6 |
853 | if (isset($session)) { |
44560457 |
854 | echo '<input type="hidden" name="session" value="' . $session . "\">\n"; |
da95c4b6 |
855 | } |
08bad2b1 |
856 | |
857 | if (isset($passed_id)) { |
858 | echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n"; |
859 | } |
44560457 |
860 | |
9c3e6cd4 |
861 | if ($saved_draft == 'yes') { |
862 | echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>'; |
863 | } |
864 | if ($mail_sent == 'yes') { |
865 | echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>'; |
866 | } |
a94c1db1 |
867 | echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n"; |
9c3e6cd4 |
868 | if ($compose_new_win == '1') { |
a94c1db1 |
869 | echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" . |
870 | ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n"; |
9c3e6cd4 |
871 | } |
78a35fcd |
872 | if ($location_of_buttons == 'top') { |
873 | showComposeButtonRow(); |
874 | } |
48985d59 |
875 | |
715225af |
876 | $idents = getPref($data_dir, $username, 'identities', 0); |
877 | if ($idents > 1) { |
a94c1db1 |
878 | echo ' <TR>' . "\n" . |
879 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
0ec1a14b |
880 | _("From:") . '</TD>' . "\n" . |
a94c1db1 |
881 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
0ec1a14b |
882 | ' <select name=identity>' . "\n" . |
883 | ' <option value=default>' . |
884 | htmlspecialchars(getPref($data_dir, $username, 'full_name')); |
48985d59 |
885 | $em = getPref($data_dir, $username, 'email_address'); |
886 | if ($em != '') { |
248bfebb |
887 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
888 | } |
889 | for ($i = 1; $i < $idents; $i ++) { |
248bfebb |
890 | echo '<option value="' . $i . '"'; |
48985d59 |
891 | if (isset($identity) && $identity == $i) { |
78a35fcd |
892 | echo ' SELECTED'; |
48985d59 |
893 | } |
894 | echo '>' . htmlspecialchars(getPref($data_dir, $username, |
895 | 'full_name' . $i)); |
248bfebb |
896 | $em = getPref($data_dir, $username, 'email_address' . $i); |
48985d59 |
897 | if ($em != '') { |
78a35fcd |
898 | echo htmlspecialchars(' <' . $em . '>') . "\n"; |
48985d59 |
899 | } |
9f599fe3 |
900 | echo '</option>'; |
48985d59 |
901 | } |
902 | echo '</select>' . "\n" . |
41b94d65 |
903 | ' </TD>' . "\n" . |
904 | ' </TR>' . "\n"; |
905 | } |
a94c1db1 |
906 | echo ' <TR>' . "\n" . |
907 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . |
0ec1a14b |
908 | _("To:") . '</TD>' . "\n" . |
a94c1db1 |
909 | ' <TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" . |
41b94d65 |
910 | ' <INPUT TYPE=text NAME="send_to" VALUE="' . |
0ec1a14b |
911 | htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" . |
41b94d65 |
912 | ' </TD>' . "\n" . |
913 | ' </TR>' . "\n" . |
a94c1db1 |
914 | ' <TR>' . "\n" . |
915 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
0ec1a14b |
916 | _("CC:") . '</TD>' . "\n" . |
a94c1db1 |
917 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
41b94d65 |
918 | ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' . |
0ec1a14b |
919 | htmlspecialchars($send_to_cc) . '"><BR>' . "\n" . |
41b94d65 |
920 | ' </TD>' . "\n" . |
921 | ' </TR>' . "\n" . |
a94c1db1 |
922 | ' <TR>' . "\n" . |
923 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
0ec1a14b |
924 | _("BCC:") . '</TD>' . "\n" . |
a94c1db1 |
925 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" . |
41b94d65 |
926 | ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' . |
0ec1a14b |
927 | htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" . |
928 | ' </TD>' . "\n" . |
929 | ' </TR>' . "\n" . |
a94c1db1 |
930 | ' <TR>' . "\n" . |
931 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . |
0ec1a14b |
932 | _("Subject:") . '</TD>' . "\n" . |
a94c1db1 |
933 | ' <TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n"; |
0ec1a14b |
934 | echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' . |
935 | htmlspecialchars($subject) . '">' . "\n" . |
936 | ' </TD>' . "\n" . |
937 | ' </TR>' . "\n\n"; |
48985d59 |
938 | |
78a35fcd |
939 | if ($location_of_buttons == 'between') { |
940 | showComposeButtonRow(); |
941 | } |
4dfb9db7 |
942 | |
fdc83c55 |
943 | if ($compose_new_win == '1') { |
a94c1db1 |
944 | echo ' <TR>' . "\n" . |
945 | ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" . |
41b94d65 |
946 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
0ec1a14b |
947 | $editor_size . '" WRAP="VIRTUAL">'; |
fdc83c55 |
948 | } |
949 | else { |
a94c1db1 |
950 | echo ' <TR>' . "\n" . |
951 | ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" . |
41b94d65 |
952 | ' <TEXTAREA NAME=body ROWS=20 COLS="' . |
0ec1a14b |
953 | $editor_size . '" WRAP="VIRTUAL">'; |
fdc83c55 |
954 | } |
48985d59 |
955 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
d3c13a51 |
956 | if ($idents > 1) { |
957 | if ($identity == 'default') { |
958 | $no = 'g'; |
959 | } else { |
960 | $no = $identity; |
961 | } |
962 | $signature = getSig($data_dir, $username, $no); |
963 | } |
964 | |
3b17e952 |
965 | if ($sig_first == '1') { |
ab4700c3 |
966 | if ($default_charset == 'iso-2022-jp') { |
83be314a |
967 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
968 | } else { |
3b17e952 |
969 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
83be314a |
970 | } |
3b17e952 |
971 | echo "\n\n".htmlspecialchars($body); |
972 | } |
973 | else { |
974 | echo "\n\n".htmlspecialchars($body); |
ab4700c3 |
975 | if ($default_charset == 'iso-2022-jp') { |
83be314a |
976 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
977 | }else{ |
3b17e952 |
978 | echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature); |
979 | } |
980 | } |
83be314a |
981 | } |
3b17e952 |
982 | else { |
983 | echo htmlspecialchars($body); |
48985d59 |
984 | } |
41b94d65 |
985 | echo '</TEXTAREA><BR>' . "\n" . |
986 | ' </TD>' . "\n" . |
987 | ' </TR>' . "\n"; |
48985d59 |
988 | |
989 | if ($location_of_buttons == 'bottom') { |
990 | showComposeButtonRow(); |
991 | } else { |
0ec1a14b |
992 | echo ' <TR>' . "\n" . |
993 | ' <TD COLSPAN=2 ALIGN=RIGHT>' . "\n" . |
994 | ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . "\n" . |
995 | ' <BR><BR>' . "\n" . |
996 | ' </TD>' . "\n" . |
997 | ' </TR>' . "\n"; |
48985d59 |
998 | } |
46bb8da8 |
999 | |
48985d59 |
1000 | /* This code is for attachments */ |
a64f47e7 |
1001 | if ((bool) ini_get('file_uploads')) { |
0ec1a14b |
1002 | echo ' <TR>' . "\n" . |
1003 | ' <TD COLSPAN=2>' . "\n" . |
a94c1db1 |
1004 | ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'. |
0ec1a14b |
1005 | ' border="0" bgcolor="'.$color[9].'">' . "\n" . |
1006 | ' <TR>' . "\n" . |
1007 | ' <TD>' . "\n" . |
a94c1db1 |
1008 | ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
0ec1a14b |
1009 | ' border="0">' . "\n" . |
1010 | ' <TR>' . "\n" . |
1011 | ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . |
1012 | _("Attach:") . '</TD>' . "\n" . |
1013 | ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" . |
1014 | ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" . |
1015 | ' <input type="submit" name="attach"' . |
1016 | ' value="' . _("Add") .'">' . "\n" . |
1017 | ' </TD>' . "\n" . |
1018 | ' </TR>' . "\n"; |
91f2085b |
1019 | |
41b94d65 |
1020 | |
91f2085b |
1021 | $s_a = array(); |
4dfb9db7 |
1022 | if ($composeMessage->entities) { |
1023 | foreach ($composeMessage->entities as $key => $attachment) { |
a43e4b90 |
1024 | $attached_file = $attachment->att_local_name; |
1025 | if ($attachment->att_local_name || $attachment->body_part) { |
1026 | $attached_filename = decodeHeader($attachment->mime_header->getParameter('name')); |
1027 | $type = $attachment->mime_header->type0.'/'. |
1028 | $attachment->mime_header->type1; |
a94c1db1 |
1029 | $s_a[] = '<input type="checkbox" name="delete[]" value="' . |
1030 | $key . "\">\n" . $attached_filename . ' - ' . $type . |
1031 | ' ('.show_readable_size( filesize( $attached_file ) ) |
1032 | . ')<br>'."\n"; |
a43e4b90 |
1033 | } |
4dfb9db7 |
1034 | } |
91f2085b |
1035 | } |
1036 | if (count($s_a)) { |
a94c1db1 |
1037 | foreach ($s_a as $s) { |
1038 | echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>'; |
a61878d0 |
1039 | } |
91f2085b |
1040 | echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' . |
1041 | _("Delete selected attachments") . "\">\n" . |
1042 | '</td></tr>'; |
1043 | } |
0ec1a14b |
1044 | echo ' </table>' . "\n" . |
1045 | ' </td>' . "\n" . |
1046 | ' </tr>' . "\n" . |
1047 | ' </TABLE>' . "\n" . |
1048 | ' </TD>' . "\n" . |
1049 | ' </TR>' . "\n"; |
a64f47e7 |
1050 | } // End of file_uploads if-block |
41b94d65 |
1051 | /* End of attachment code */ |
07687736 |
1052 | if ($compose_new_win == '1') { |
41b94d65 |
1053 | echo '</TABLE>'."\n"; |
07687736 |
1054 | } |
a64f47e7 |
1055 | |
a61878d0 |
1056 | echo '</TABLE>' . "\n" . |
1057 | '<input type="hidden" name="username" value="'. $username . "\">\n" . |
5da08ef7 |
1058 | '<input type=hidden name=action value="' . $action . "\">\n" . |
a61878d0 |
1059 | '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) . |
4dfb9db7 |
1060 | "\">\n"; |
5da08ef7 |
1061 | /* |
0ec1a14b |
1062 | store the complete ComposeMessages array in a hidden input value |
1063 | so we can restore them in case of a session timeout. |
5da08ef7 |
1064 | */ |
1065 | echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n"; |
1066 | echo '<input type=hidden name=composesession value="' . $composesession . "\">\n"; |
1067 | echo '<input type=hidden name=querystring value="' . $_SERVER['QUERY_STRING'] . "\">\n"; |
4dfb9db7 |
1068 | echo '</FORM>'; |
a64f47e7 |
1069 | if (!(bool) ini_get('file_uploads')) { |
1070 | /* File uploads are off, so we didn't show that part of the form. |
1071 | To avoid bogus bug reports, tell the user why. */ |
1072 | echo 'Because PHP file uploads are turned off, you can not attach files '; |
1073 | echo "to this message. Please see your system administrator for details.\r\n"; |
1074 | } |
1075 | |
1076 | |
9f599fe3 |
1077 | do_hook('compose_bottom'); |
48985d59 |
1078 | echo '</BODY></HTML>' . "\n"; |
1079 | } |
1080 | |
1081 | |
70c4fd84 |
1082 | function showComposeButtonRow() { |
78a35fcd |
1083 | global $use_javascript_addr_book, $save_as_draft, |
a61878d0 |
1084 | $default_use_priority, $mailprio, $default_use_mdn, |
1085 | $request_mdn, $request_dr, |
1086 | $data_dir, $username; |
70c4fd84 |
1087 | |
0ec1a14b |
1088 | echo ' <TR>' . "\n" . |
1089 | ' <TD></TD>' . "\n" . |
1090 | ' <TD>' . "\n"; |
ae25968c |
1091 | if ($default_use_priority) { |
1092 | if(!isset($mailprio)) { |
1093 | $mailprio = "3"; |
70c4fd84 |
1094 | } |
0ec1a14b |
1095 | echo ' ' . _("Priority") .': <select name="mailprio">'. |
70c4fd84 |
1096 | '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'. |
1097 | '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'. |
1098 | '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'. |
0ec1a14b |
1099 | '</select>' . "\n"; |
ae25968c |
1100 | } |
1101 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
1102 | if ($default_use_mdn) { |
70c4fd84 |
1103 | if ($mdn_user_support) { |
0ec1a14b |
1104 | echo ' ' . _("Receipt") .': '. |
b2a7e5bc |
1105 | '<input type="checkbox" name="request_mdn" value=1'. |
a61878d0 |
1106 | ($request_mdn=='1'?' checked':'') .'>'. _("On Read"). |
b2a7e5bc |
1107 | ' <input type="checkbox" name="request_dr" value=1'. |
a61878d0 |
1108 | ($request_dr=='1'?' checked':'') .'>'. _("On Delivery"); |
70c4fd84 |
1109 | } |
ae25968c |
1110 | } |
48985d59 |
1111 | |
0ec1a14b |
1112 | echo ' </TD>' . "\n" . |
1113 | ' </TR>' . "\n" . |
1114 | ' <TR>' . "\n" . |
1115 | ' <TD></TD>' . "\n" . |
1116 | ' <TD>' . "\n" . |
1117 | ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n"; |
78a35fcd |
1118 | if ($use_javascript_addr_book) { |
0ec1a14b |
1119 | echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"". |
1120 | " <input type=button value=\\\""._("Addresses"). |
1121 | "\\\" onclick='javascript:open_abook();'>\");". |
1122 | " // --></SCRIPT><NOSCRIPT>\n". |
1123 | " <input type=submit name=\"html_addr_search\" value=\"". |
46bb8da8 |
1124 | _("Addresses")."\">". |
0ec1a14b |
1125 | " </NOSCRIPT>\n"; |
734f4ee6 |
1126 | } else { |
0ec1a14b |
1127 | echo ' <input type=submit name="html_addr_search" value="'. |
1128 | _("Addresses").'">' . "\n"; |
78a35fcd |
1129 | } |
48985d59 |
1130 | |
78a35fcd |
1131 | if ($save_as_draft) { |
0ec1a14b |
1132 | echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n"; |
78a35fcd |
1133 | } |
0a17f9dd |
1134 | |
0ec1a14b |
1135 | echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n"; |
78a35fcd |
1136 | do_hook('compose_button_row'); |
441f2d33 |
1137 | |
0ec1a14b |
1138 | echo ' </TD>' . "\n" . |
1139 | ' </TR>' . "\n\n"; |
78a35fcd |
1140 | } |
b278172f |
1141 | |
70c4fd84 |
1142 | function checkInput ($show) { |
78a35fcd |
1143 | /* |
1144 | * I implemented the $show variable because the error messages |
1145 | * were getting sent before the page header. So, I check once |
1146 | * using $show=false, and then when i'm ready to display the error |
1147 | * message, show=true |
1148 | */ |
6bf2a88f |
1149 | global $body, $send_to, $send_to_bcc, $subject, $color; |
78a35fcd |
1150 | |
6bf2a88f |
1151 | if ($send_to == '' && $send_to_bcc == '') { |
78a35fcd |
1152 | if ($show) { |
0ad7dbda |
1153 | plain_error_message(_("You have not filled in the \"To:\" field."), $color); |
78a35fcd |
1154 | } |
1155 | return false; |
1156 | } |
1157 | return true; |
1158 | } /* function checkInput() */ |
df15de21 |
1159 | |
3806fa52 |
1160 | |
00793a25 |
1161 | /* True if FAILURE */ |
da95c4b6 |
1162 | function saveAttachedFiles($session) { |
0b97a708 |
1163 | global $_FILES, $attachment_dir, $attachments, $username, |
a43e4b90 |
1164 | $data_dir, $compose_messages; |
4c9d2242 |
1165 | |
45cdd1b5 |
1166 | /* get out of here if no file was attached at all */ |
1167 | if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) { |
1168 | return true; |
1169 | } |
1170 | |
4c9d2242 |
1171 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
1172 | $localfilename = GenerateRandomString(32, '', 7); |
1173 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1174 | while (file_exists($full_localfilename)) { |
1175 | $localfilename = GenerateRandomString(32, '', 7); |
1176 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1177 | } |
1178 | |
e6675f9a |
1179 | // FIXME: we SHOULD prefer move_uploaded_file over rename because |
1180 | // m_u_f works better with restricted PHP installes (safe_mode, open_basedir) |
1181 | if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
1182 | if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) { |
1183 | return true; |
1184 | } |
a61878d0 |
1185 | } |
a43e4b90 |
1186 | $message = $compose_messages[$session]; |
0b97a708 |
1187 | $type = strtolower($_FILES['attachfile']['type']); |
1188 | $name = $_FILES['attachfile']['name']; |
a43e4b90 |
1189 | $message->initAttachment($type, $name, $full_localfilename); |
1190 | $compose_messages[$session] = $message; |
4c9d2242 |
1191 | } |
1192 | |
a43e4b90 |
1193 | function ClearAttachments($composeMessage) { |
b48d3c53 |
1194 | if ($composeMessage->att_local_name) { |
1195 | $attached_file = $composeMessage->att_local_name; |
a43e4b90 |
1196 | if (file_exists($attached_file)) { |
1197 | unlink($attached_file); |
8712abea |
1198 | } |
da95c4b6 |
1199 | } |
a43e4b90 |
1200 | for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) { |
1201 | ClearAttachments($composeMessage->entities[$i]); |
1202 | } |
4c9d2242 |
1203 | } |
1204 | |
da95c4b6 |
1205 | |
a43e4b90 |
1206 | |
1207 | function getReplyCitation($orig_from) { |
4c9d2242 |
1208 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
1209 | |
1210 | /* First, return an empty string when no citation style selected. */ |
1211 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
1212 | return ''; |
1213 | } |
1214 | |
4c9d2242 |
1215 | /* Make sure our final value isn't an empty string. */ |
1216 | if ($orig_from == '') { |
1217 | return ''; |
1218 | } |
1219 | |
1220 | /* Otherwise, try to select the desired citation style. */ |
1221 | switch ($reply_citation_style) { |
1222 | case 'author_said': |
1223 | $start = ''; |
1224 | $end = ' ' . _("said") . ':'; |
1225 | break; |
1226 | case 'quote_who': |
1227 | $start = '<' . _("quote") . ' ' . _("who") . '="'; |
1228 | $end = '">'; |
1229 | break; |
1230 | case 'user-defined': |
55b321f2 |
1231 | $start = $reply_citation_start . |
a61878d0 |
1232 | ($reply_citation_start == '' ? '' : ' '); |
4c9d2242 |
1233 | $end = $reply_citation_end; |
1234 | break; |
1235 | default: |
1236 | return ''; |
1237 | } |
1238 | |
1239 | /* Build and return the citation string. */ |
1240 | return ($start . $orig_from . $end . "\n"); |
1241 | } |
1242 | |
a43e4b90 |
1243 | /* temporary function to make use of the deliver class. |
1244 | In the future the responsable backend should be automaticly loaded |
1245 | and conf.pl should show a list of available backends. |
1246 | The message also should be constructed by the message class. |
1247 | */ |
1248 | |
b7ff469f |
1249 | function deliverMessage($composeMessage, $draft=false) { |
a43e4b90 |
1250 | global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, |
1251 | $username, $popuser, $usernamedata, $identity, $data_dir, |
1252 | $request_mdn, $request_dr, $default_charset, $color, $useSendmail, |
b48d3c53 |
1253 | $domain, $action; |
a43e4b90 |
1254 | global $imapServerAddress, $imapPort, $sent_folder, $key; |
1255 | |
1256 | $rfc822_header = $composeMessage->rfc822_header; |
24192f77 |
1257 | |
1258 | $abook = addressbook_init(false, true); |
1259 | |
1260 | $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); |
1261 | $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); |
1262 | $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); |
a43e4b90 |
1263 | $rfc822_header->priority = $mailprio; |
1264 | $rfc822_header->subject = $subject; |
1265 | $special_encoding=''; |
1266 | if (strtolower($default_charset) == 'iso-2022-jp') { |
1267 | if (mb_detect_encoding($body) == 'ASCII') { |
1268 | $special_encoding = '8bit'; |
1269 | } else { |
1270 | $body = mb_convert_encoding($body, 'JIS'); |
1271 | $special_encoding = '7bit'; |
1272 | } |
1273 | } |
1274 | $composeMessage->setBody($body); |
1275 | |
1276 | if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { |
1277 | $popuser = $usernamedata[1]; |
1278 | $domain = $usernamedata[2]; |
1279 | unset($usernamedata); |
1280 | } else { |
1281 | $popuser = $username; |
1282 | } |
1283 | $reply_to = ''; |
1284 | if (isset($identity) && $identity != 'default') { |
045714fd |
1285 | $from_mail = getPref($data_dir, $username,'email_address' . $identity); |
1286 | $full_name = getPref($data_dir, $username,'full_name' . $identity); |
1287 | $reply_to = getPref($data_dir, $username,'reply_to' . $identity); |
a43e4b90 |
1288 | } else { |
1289 | $from_mail = getPref($data_dir, $username, 'email_address'); |
1290 | $full_name = getPref($data_dir, $username, 'full_name'); |
a43e4b90 |
1291 | $reply_to = getPref($data_dir, $username,'reply_to'); |
1292 | } |
045714fd |
1293 | if (!$from_mail) { |
1294 | $from_mail = "$popuser@$domain"; |
1295 | $full_name = ''; |
1296 | } |
1297 | $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); |
1298 | if ($full_name) { |
9783f396 |
1299 | $from = $rfc822_header->from[0]; |
045714fd |
1300 | if (!$from->host) $from->host = $domain; |
1da690a2 |
1301 | $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; |
045714fd |
1302 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
a43e4b90 |
1303 | } |
a43e4b90 |
1304 | if ($reply_to) { |
1305 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
1306 | } |
1307 | /* Receipt: On Read */ |
1308 | if (isset($request_mdn) && $request_mdn) { |
1309 | $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); |
1310 | } |
1311 | /* Receipt: On Delivery */ |
1312 | if (isset($request_dr) && $request_dr) { |
1313 | $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; |
1314 | } |
1315 | /* multipart messages */ |
1316 | if (count($composeMessage->entities)) { |
1317 | $message_body = new Message(); |
1318 | $message_body->body_part = $composeMessage->body_part; |
1319 | $composeMessage->body_part = ''; |
1320 | $mime_header = new MessageHeader; |
1321 | $mime_header->type0 = 'text'; |
1322 | $mime_header->type1 = 'plain'; |
1323 | if ($special_encoding) { |
1324 | $mime_header->encoding = $special_encoding; |
1325 | } else { |
1326 | $mime_header->encoding = 'us-ascii'; |
1327 | } |
1328 | if ($default_charset) { |
1329 | $mime_header->parameters['charset'] = $default_charset; |
1330 | } |
1331 | $message_body->mime_header = $mime_header; |
1332 | array_unshift($composeMessage->entities, $message_body); |
1333 | $content_type = new ContentType('multipart/mixed'); |
1334 | } else { |
1335 | $content_type = new ContentType('text/plain'); |
1336 | } |
1337 | if ($default_charset) { |
1338 | $content_type->properties['charset']=$default_charset; |
1339 | } |
1340 | |
1341 | $rfc822_header->content_type = $content_type; |
1342 | $composeMessage->rfc822_header = $rfc822_header; |
1343 | |
b48d3c53 |
1344 | if (!$useSendmail && !$draft) { |
86725763 |
1345 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
a43e4b90 |
1346 | $deliver = new Deliver_SMTP(); |
47a29326 |
1347 | global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech; |
1348 | |
1349 | if ($smtp_auth_mech == 'none') { |
1350 | $user = ''; |
1351 | $pass = ''; |
a43e4b90 |
1352 | } else { |
47a29326 |
1353 | global $key, $onetimepad; |
1354 | $user = $username; |
1355 | $pass = OneTimePadDecrypt($key, $onetimepad); |
a43e4b90 |
1356 | } |
47a29326 |
1357 | |
b48d3c53 |
1358 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
a43e4b90 |
1359 | $stream = $deliver->initStream($composeMessage,$domain,0, |
70ce2218 |
1360 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
b48d3c53 |
1361 | } elseif (!$draft) { |
86725763 |
1362 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
b48d3c53 |
1363 | global $sendmail_path; |
1364 | $deliver = new Deliver_SendMail(); |
1365 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
1366 | } elseif ($draft) { |
1367 | global $draft_folder; |
86725763 |
1368 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
b48d3c53 |
1369 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
1370 | $imapPort, 0); |
1371 | if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { |
4dfb9db7 |
1372 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
1373 | $imap_deliver = new Deliver_IMAP(); |
1374 | $length = $imap_deliver->mail($composeMessage); |
1375 | sqimap_append ($imap_stream, $draft_folder, $length); |
1376 | $imap_deliver->mail($composeMessage, $imap_stream); |
f55207e3 |
1377 | sqimap_append_done ($imap_stream, $draft_folder); |
4dfb9db7 |
1378 | sqimap_logout($imap_stream); |
1379 | unset ($imap_deliver); |
1380 | return $length; |
1381 | } else { |
1382 | $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.'; |
1383 | plain_error_message($msg, $color); |
1384 | return false; |
b48d3c53 |
1385 | } |
a43e4b90 |
1386 | } |
1387 | $succes = false; |
1388 | if ($stream) { |
1389 | $length = $deliver->mail($composeMessage, $stream); |
1390 | $succes = $deliver->finalizeStream($stream); |
1391 | } |
1392 | if (!$succes) { |
00ac2f42 |
1393 | $msg = $deliver->dlv_msg . '<br>' . |
1394 | _("Server replied: ") . $deliver->dlv_ret_nr . ' '. |
1395 | $deliver->dlv_server_msg; |
a43e4b90 |
1396 | plain_error_message($msg, $color); |
1397 | } else { |
1398 | unset ($deliver); |
1399 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
1400 | $imapPort, 0); |
1401 | if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) { |
1402 | sqimap_append ($imap_stream, $sent_folder, $length); |
86725763 |
1403 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
a43e4b90 |
1404 | $imap_deliver = new Deliver_IMAP(); |
1405 | $imap_deliver->mail($composeMessage, $imap_stream); |
f55207e3 |
1406 | sqimap_append_done ($imap_stream, $sent_folder); |
a43e4b90 |
1407 | unset ($imap_deliver); |
1408 | } |
b48d3c53 |
1409 | global $passed_id, $mailbox, $action; |
a43e4b90 |
1410 | ClearAttachments($composeMessage); |
b48d3c53 |
1411 | if ($action == 'reply' || $action == 'reply_all') { |
1412 | sqimap_mailbox_select ($imap_stream, $mailbox); |
1413 | sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true); |
1414 | } |
1415 | sqimap_logout($imap_stream); |
a43e4b90 |
1416 | } |
1417 | return $succes; |
1418 | } |
1419 | |
6bf2a88f |
1420 | ?> |