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