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