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