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