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