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