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