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