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