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