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