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