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