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