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