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