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