6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
18 * @package squirrelmail
22 * Path for SquirrelMail required files.
25 define('SM_PATH','../');
27 /* SquirrelMail required files. */
28 require_once(SM_PATH
. 'include/validate.php');
29 require_once(SM_PATH
. 'functions/global.php');
30 require_once(SM_PATH
. 'functions/imap.php');
31 require_once(SM_PATH
. 'functions/date.php');
32 require_once(SM_PATH
. 'functions/mime.php');
33 require_once(SM_PATH
. 'functions/plugin.php');
34 require_once(SM_PATH
. 'functions/display_messages.php');
35 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
36 require_once(SM_PATH
. 'functions/addressbook.php');
37 require_once(SM_PATH
. 'functions/identity.php');
38 require_once(SM_PATH
. 'functions/forms.php');
40 /* --------------------- Get globals ------------------------------------- */
42 sqgetGlobalVar('key', $key, SQ_COOKIE
);
45 sqgetGlobalVar('username', $username, SQ_SESSION
);
46 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
47 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
50 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
51 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
53 /** SESSION/POST/GET VARS */
54 sqgetGlobalVar('session',$session);
55 sqgetGlobalVar('mailbox',$mailbox);
56 if(!sqgetGlobalVar('identity',$identity)) {
59 sqgetGlobalVar('send_to',$send_to);
60 sqgetGlobalVar('send_to_cc',$send_to_cc);
61 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
62 sqgetGlobalVar('subject',$subject);
63 sqgetGlobalVar('body',$body);
64 sqgetGlobalVar('mailprio',$mailprio);
65 sqgetGlobalVar('request_mdn',$request_mdn);
66 sqgetGlobalVar('request_dr',$request_dr);
67 sqgetGlobalVar('html_addr_search',$html_addr_search);
68 sqgetGlobalVar('mail_sent',$mail_sent);
69 sqgetGlobalVar('passed_id',$passed_id);
70 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
71 sqgetGlobalVar('send',$send);
73 sqgetGlobalVar('attach',$attach);
75 sqgetGlobalVar('draft',$draft);
76 sqgetGlobalVar('draft_id',$draft_id);
77 sqgetGlobalVar('ent_num',$ent_num);
78 sqgetGlobalVar('saved_draft',$saved_draft);
79 sqgetGlobalVar('delete_draft',$delete_draft);
80 sqgetGlobalVar('startMessage',$startMessage);
83 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
84 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
85 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
86 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
87 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
88 sqgetGlobalVar('delete', $delete, SQ_POST
);
89 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
90 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
91 $html_addr_search_done = 'Use Addresses';
95 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
98 if ( !sqgetGlobalVar('smaction',$action) )
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';
108 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
109 $location = get_location();
110 /* Identities (fetch only once) */
111 $idents = get_identities();
113 /* --------------------- Specific Functions ------------------------------ */
115 function replyAllString($header) {
116 global $include_self_reply_all, $idents;
119 * 1) Remove the addresses we'll be sending the message 'to'
121 if (isset($header->replyto
)) {
122 $excl_ar = $header->getAddr_a('replyto');
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
128 if (!$include_self_reply_all) {
129 foreach($idents as $id) {
130 $excl_ar[strtolower(trim($id['email_address']))] = '';
135 * 3) get the addresses.
137 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
140 * 4) generate the string.
142 $url_replytoallcc = '';
143 foreach( $url_replytoall_ar as $email => $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.'"';
150 $url_replytoallcc .= ", $personal <$email>";
152 $url_replytoallcc .= ', '. $email;
155 $url_replytoallcc = substr($url_replytoallcc,2);
157 return $url_replytoallcc;
161 * creates top line in reply citations
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
169 function getReplyCitation($orig_from, $orig_date) {
170 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
172 // FIXME: why object is rewritten with string.
173 if (!is_object($orig_from)) {
176 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
178 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
180 /* First, return an empty string when no citation style selected. */
181 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
185 /* Make sure our final value isn't an empty string. */
186 if ($orig_from == '') {
190 /* Otherwise, try to select the desired citation style. */
191 switch ($reply_citation_style) {
194 * To translators: %s is for author's name
196 $full_reply_citation = sprintf(_("%s said:"),$orig_from);
199 // FIXME: do we have to translate xml formating?
200 $start = '<' . _("quote") . ' ' . _("who") . '="';
202 $full_reply_citation = $start . $orig_from . $end;
204 case 'date_time_author':
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.
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
214 $full_reply_citation = sprintf(_("On %s, %s said:"), getLongDateString($orig_date), $orig_from);
217 $start = $reply_citation_start .
218 ($reply_citation_start == '' ?
'' : ' ');
219 $end = $reply_citation_end;
220 $full_reply_citation = $start . $orig_from . $end;
226 /* Add line feed and return the citation string. */
227 return ($full_reply_citation . "\n");
231 * Creates header fields in forwarded email body
233 * $default_charset global must be set correctly before you call this function.
234 * @param object $orig_header
237 function getforwardHeader($orig_header) {
238 global $editor_size, $default_charset;
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) );
246 $maxsize = max($display);
247 $indent = str_pad('',$maxsize+
2);
248 foreach($display as $key => $val) {
249 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
251 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
252 $from = str_replace(' ',' ',$from);
253 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
254 $to = str_replace(' ',' ',$to);
255 $subject = decodeHeader($orig_header->subject
,false,false,true);
256 $subject = str_replace(' ',' ',$subject);
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) .
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(' ',' ',$cc);
267 $bodyTop .= $display[_("Cc")] .$cc . "\n";
269 $bodyTop .= str_pad('', $editor_size -2 , '-') .
273 /* ----------------------------------------------------------------------- */
276 * If the session is expired during a post this restores the compose session
279 if (sqsession_is_registered('session_expired_post')) {
280 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
282 * extra check for username so we don't display previous post data from
283 * another user during this session.
285 if ($session_expired_post['username'] != $username) {
286 unset($session_expired_post);
287 sqsession_unregister('session_expired_post');
288 session_write_close();
290 foreach ($session_expired_post as $postvar => $val) {
297 $compose_messages = unserialize(urldecode($restoremessages));
298 sqsession_register($compose_messages,'compose_messages');
299 sqsession_register($composesession,'composesession');
303 $session_expired = true;
305 unset($session_expired_post);
306 sqsession_unregister('session_expired_post');
307 session_write_close();
308 if (!isset($mailbox)) {
311 if ($compose_new_win == '1') {
312 compose_Header($color, $mailbox);
314 displayPageHeader($color, $mailbox);
316 showInputForm($session, false);
319 if (!isset($composesession)) {
321 sqsession_register(0,'composesession');
324 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
325 sqsession_unregister('composesession');
326 $session = "$composesession" +
1;
327 $composesession = $session;
328 sqsession_register($composesession,'composesession');
330 if (!isset($compose_messages)) {
331 $compose_messages = array();
333 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
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');
342 $composeMessage=$compose_messages[$session];
345 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
351 * Set $default_charset to correspond with the user's selection
352 * of language interface.
355 $composeMessage=$compose_messages[$session];
356 if (! deliverMessage($composeMessage, true)) {
357 showInputForm($session);
360 unset($compose_messages[$session]);
361 $draft_message = _("Draft Email Saved");
362 /* If this is a resumed draft, then delete the original */
363 if(isset($delete_draft)) {
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);
371 sqimap_mailbox_expunge($imap_stream, $draft_folder, true);
373 sqimap_logout($imap_stream);
375 if ($compose_new_win == '1') {
376 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
379 Header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
380 "&startMessage=1¬e=".urlencode($draft_message));
387 if (isset($_FILES['attachfile']) &&
388 $_FILES['attachfile']['tmp_name'] &&
389 $_FILES['attachfile']['tmp_name'] != 'none') {
390 $AttachFailure = saveAttachedFiles($session);
392 if (checkInput(false) && !isset($AttachFailure)) {
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 */
397 $urlMailbox = urlencode (trim($mailbox));
398 if (! isset($passed_id)) {
402 * Set $default_charset to correspond with the user's selection
403 * of language interface.
407 * This is to change all newlines to \n
408 * We'll change them to \r\n later (in the sendMessage function)
410 $body = str_replace("\r\n", "\n", $body);
411 $body = str_replace("\r", "\n", $body);
414 * Rewrap $body so that no line is bigger than $editor_size
416 $body = explode("\n", $body);
418 foreach ($body as $line) {
419 if( $line <> '-- ' ) {
420 $line = rtrim($line);
422 if (sq_strlen($line,$default_charset) <= $editor_size +
1) {
423 $newBody .= $line . "\n";
425 sqWordWrap($line, $editor_size,$default_charset);
426 $newBody .= $line . "\n";
433 $composeMessage=$compose_messages[$session];
435 $Result = deliverMessage($composeMessage);
437 showInputForm($session);
440 unset($compose_messages[$session]);
441 /* if it is resumed draft, delete draft message */
442 if ( isset($delete_draft)) {
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);
450 sqimap_mailbox_expunge($imap_stream, $draft_folder, true);
452 sqimap_logout($imap_stream);
454 if ($compose_new_win == '1') {
455 Header("Location: $location/compose.php?mail_sent=yes");
457 Header("Location: $location/right_main.php?mailbox=$urlMailbox".
458 "&startMessage=$startMessage&mail_sent=yes");
461 if ($compose_new_win == '1') {
462 compose_Header($color, $mailbox);
465 displayPageHeader($color, $mailbox);
467 if (isset($AttachFailure)) {
468 plain_error_message(_("Could not move/copy file. File not attached"),
472 showInputForm($session);
473 /* sqimap_logout($imapConnection); */
475 } elseif (isset($html_addr_search_done)) {
476 if ($compose_new_win == '1') {
477 compose_Header($color, $mailbox);
480 displayPageHeader($color, $mailbox);
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') {
491 elseif (substr($k, 0, 1) == 'C') {
497 elseif (substr($k, 0, 1) == 'B') {
499 $send_to_bcc .= ', ';
505 showInputForm($session);
506 } elseif (isset($html_addr_search)) {
507 if (isset($_FILES['attachfile']) &&
508 $_FILES['attachfile']['tmp_name'] &&
509 $_FILES['attachfile']['tmp_name'] != 'none') {
510 if(saveAttachedFiles($session)) {
511 plain_error_message(_("Could not move/copy file. File not attached"), $color);
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.
518 include_once('./addrbook_search_html.php');
519 } elseif (isset($attach)) {
520 if (saveAttachedFiles($session)) {
521 plain_error_message(_("Could not move/copy file. File not attached"), $color);
523 if ($compose_new_win == '1') {
524 compose_Header($color, $mailbox);
526 displayPageHeader($color, $mailbox);
528 showInputForm($session);
530 elseif (isset($sigappend)) {
531 $signature = $idents[$identity]['signature'];
533 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
534 if ($compose_new_win == '1') {
535 compose_Header($color, $mailbox);
537 displayPageHeader($color, $mailbox);
539 showInputForm($session);
540 } elseif (isset($do_delete)) {
541 if ($compose_new_win == '1') {
542 compose_Header($color, $mailbox);
544 displayPageHeader($color, $mailbox);
547 if (isset($delete) && is_array($delete)) {
548 $composeMessage = $compose_messages[$session];
549 foreach($delete as $index) {
550 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
551 unlink ($attached_file);
552 unset ($composeMessage->entities
[$index]);
554 $new_entities = array();
555 foreach ($composeMessage->entities
as $entity) {
556 $new_entities[] = $entity;
558 $composeMessage->entities
= $new_entities;
559 $compose_messages[$session] = $composeMessage;
560 sqsession_register($compose_messages, 'compose_messages');
562 showInputForm($session);
565 * This handles the default case as well as the error case
566 * (they had the same code) --> if (isset($smtpErrors))
569 if ($compose_new_win == '1') {
570 compose_Header($color, $mailbox);
572 displayPageHeader($color, $mailbox);
577 if (!isset($passed_ent_id)) {
580 if (!isset($passed_id)) {
583 if (!isset($mailbox)) {
586 if (!isset($action)) {
590 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
592 /* in case the origin is not read_body.php */
593 if (isset($send_to)) {
594 $values['send_to'] = $send_to;
596 if (isset($send_to_cc)) {
597 $values['send_to_cc'] = $send_to_cc;
599 if (isset($send_to_bcc)) {
600 $values['send_to_bcc'] = $send_to_bcc;
602 if (isset($subject)) {
603 $values['subject'] = $subject;
605 showInputForm($session, $values);
610 /**************** Only function definitions go below *************/
612 function getforwardSubject($subject)
614 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
615 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
616 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
617 $subject = '[Fwd: ' . $subject . ']';
622 /* This function is used when not sending or adding attachments */
623 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
624 global $editor_size, $default_use_priority, $body, $idents,
625 $use_signature, $data_dir, $username,
626 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
627 $composeMessage, $body_quote;
628 global $languages, $squirrelmail_language, $default_charset;
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.
637 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
641 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
644 sqimap_mailbox_select($imapConnection, $mailbox);
645 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
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
652 * and type1=rfc822. The actual entities are childs from
653 * $message->entities[0]. That's where the encoding and is located
656 $entities = $message->entities
[0]->findDisplayEntity
657 (array(), $alt_order = array('text/plain'));
658 if (!count($entities)) {
659 $entities = $message->entities
[0]->findDisplayEntity
660 (array(), $alt_order = array('text/plain','html/plain'));
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];
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'));
671 $orig_header = $message->rfc822_header
;
674 $type0 = $message->type0
;
675 $type1 = $message->type1
;
676 foreach ($entities as $ent) {
677 $msg = $message->getEntity($ent);
678 $type0 = $msg->type0
;
679 $type1 = $msg->type1
;
680 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
681 $body_part_entity = $message->getEntity($ent);
682 $bodypart = decodeBody($unencoded_bodypart,
683 $body_part_entity->header
->encoding
);
684 if ($type1 == 'html') {
685 $bodypart = str_replace("\n", ' ', $bodypart);
686 $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
687 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
688 $bodypart = strip_tags($bodypart);
690 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
691 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
692 if (mb_detect_encoding($bodypart) != 'ASCII') {
693 $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart);
697 if (isset($body_part_entity->header
->parameters
['charset'])) {
698 $actual = $body_part_entity->header
->parameters
['charset'];
700 $actual = 'us-ascii';
703 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
704 $bodypart = charset_convert($actual,$bodypart,$default_charset,false);
709 if ($default_use_priority) {
710 $mailprio = substr($orig_header->priority
,0,1);
717 //ClearAttachments($session);
720 $from_o = $orig_header->from
;
721 if (is_array($from_o)) {
722 if (isset($from_o[0])) {
723 $from_o = $from_o[0];
726 if (is_object($from_o)) {
727 $orig_from = $from_o->getAddress();
732 $identities = array();
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) {
740 $identities[] = $enc_from_name;
743 $identity_match = $orig_header->findAddress($identities);
744 if ($identity_match) {
745 $identity = $identity_match;
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'];
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);
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
;
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);
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;
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);
805 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
806 $send_to = $orig_header->getAddr_s('mail_followup_to');
808 $send_to_cc = replyAllString($orig_header);
809 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
812 // skip this if send_to was already set right above here
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');
820 $send_to = $orig_header->getAddr_s('from');
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;
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
;
834 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
835 foreach ($rewrap_body as $line) {
836 if ($strip_sigs && substr($line,0,3) == '-- ') {
839 if (preg_match("/^(>+)/", $line, $matches)) {
841 $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n";
843 $body .= $body_quote . (!empty($body_quote) ?
' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ?
' ' : ''), rtrim($line)) . "\n";
847 //rewrap the body to clean up quotations and line lengths
848 $body = sqBodyWrap ($body, $editor_size);
850 $body = getReplyCitation($from , $orig_header->date
) . $body;
851 $composeMessage->reply_rfc822_header
= $orig_header;
857 $compose_messages[$session] = $composeMessage;
858 sqsession_register($compose_messages, 'compose_messages');
859 session_write_close();
860 sqimap_logout($imapConnection);
862 $ret = array( 'send_to' => $send_to,
863 'send_to_cc' => $send_to_cc,
864 'send_to_bcc' => $send_to_bcc,
865 'subject' => $subject,
866 'mailprio' => $mailprio,
868 'identity' => $identity );
871 } /* function newMail() */
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
883 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
884 global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages;
885 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
886 if (!count($message->entities
) ||
887 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
888 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
889 switch ($message->type0
) {
891 if ($message->type1
== 'rfc822') {
892 $filename = $message->rfc822_header
->subject
;
893 if ($filename == "") {
894 $filename = "untitled-".$message->entity_id
;
898 $filename = $message->getFilename();
902 if (!$message->mime_header
) { /* temporary hack */
903 $message->mime_header
= $message->header
;
905 $filename = $message->getFilename();
908 $filename = str_replace(' ', ' ', decodeHeader($filename));
909 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
910 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
911 $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename);
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";
919 $message->att_local_name
= $full_localfilename;
921 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
922 $full_localfilename);
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
));
932 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
933 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
936 return $composeMessage;
939 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
940 $passed_ent_id='', $imapConnection) {
941 global $attachment_dir, $username, $data_dir;
942 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
943 if (!$passed_ent_id) {
944 $body_a = sqimap_run_command($imapConnection,
945 'FETCH '.$passed_id.' RFC822',
946 TRUE, $response, $readmessage,
949 $body_a = sqimap_run_command($imapConnection,
950 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
951 TRUE, $response, $readmessage, TRUE);
952 $message = $message->parent
;
954 if ($response == 'OK') {
955 $subject = encodeHeader($message->rfc822_header
->subject
);
956 array_shift($body_a);
958 $body = implode('', $body_a) . "\r\n";
960 $localfilename = GenerateRandomString(32, 'FILE', 7);
961 $full_localfilename = "$hashed_attachment_dir/$localfilename";
963 $fp = fopen($full_localfilename, 'w');
966 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
967 $full_localfilename);
969 return $composeMessage;
972 function showInputForm ($session, $values=false) {
973 global $send_to, $send_to_cc, $body, $startMessage, $action,
974 $color, $use_signature, $signature, $prefix_sig,
975 $editor_size, $editor_height, $subject, $newmail,
976 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
977 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
978 $username, $data_dir, $identity, $idents, $delete_draft,
979 $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first,
980 $username, $compose_messages, $composesession, $default_charset;
982 $composeMessage = $compose_messages[$session];
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'];
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);
997 if ($use_javascript_addr_book) {
998 echo "\n". '<script language="JavaScript">'."\n<!--\n" .
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" .
1005 "// -->\n</script>\n\n";
1008 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
1009 'enctype="multipart/form-data"';
1010 do_hook('compose_form');
1014 echo addHidden('startMessage', $startMessage);
1016 if ($action == 'draft') {
1017 echo addHidden('delete_draft', $passed_id);
1019 if (isset($delete_draft)) {
1020 echo addHidden('delete_draft', $delete_draft);
1022 if (isset($session)) {
1023 echo addHidden('session', $session);
1026 if (isset($passed_id)) {
1027 echo addHidden('passed_id', $passed_id);
1030 if ($saved_draft == 'yes') {
1031 echo '<br /><center><b>'. _("Draft Saved").'</center></b>';
1033 if ($mail_sent == 'yes') {
1034 echo '<br /><center><b>'. _("Your Message has been sent.").'</center></b>';
1036 echo '<table align="center" cellspacing="0" border="0">' . "\n";
1037 if ($compose_new_win == '1') {
1038 echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
1039 ' <tr><td></td>'.html_tag( 'td', '', 'right' ).
1040 '<input type="button" name="Close" onclick="return self.close()" value="'.
1041 _("Close").'" /></td></tr>'."\n";
1043 if ($location_of_buttons == 'top') {
1044 showComposeButtonRow();
1047 /* display select list for identities */
1048 if (count($idents) > 1) {
1049 $ident_list = array();
1050 foreach($idents as $id => $data) {
1052 $data['full_name'].' <'.$data['email_address'].'>';
1054 echo ' <tr>' . "\n" .
1055 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1056 _("From:") . '</td>' . "\n" .
1057 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1059 addSelect('identity', $ident_list, $identity, TRUE);
1061 echo ' </td>' . "\n" .
1065 echo ' <tr>' . "\n" .
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" .
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" .
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" .
1087 html_tag( 'td', '', 'right', $color[4] ) .
1088 _("Subject") . ':</td>' . "\n" .
1089 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1090 echo ' '.addInput('subject', $subject, 60).
1094 if ($location_of_buttons == 'between') {
1095 showComposeButtonRow();
1098 /* why this distinction? */
1099 if ($compose_new_win == '1') {
1100 echo ' <tr>' . "\n" .
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">';
1106 echo ' <tr>' . "\n" .
1107 ' <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
1108 ' <textarea name="body" id="body" rows="' . (int)$editor_height .
1109 '" cols="' . (int)$editor_size . '" wrap="virtual">';
1112 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1113 $signature = $idents[$identity]['signature'];
1115 if ($sig_first == '1') {
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
1122 if ($default_charset == 'iso-2022-jp') {
1123 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1125 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1127 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1130 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1131 // FIXME: test is specific to ja_JP translation implementation. See above comments.
1132 if ($default_charset == 'iso-2022-jp') {
1133 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1135 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1139 echo htmlspecialchars(decodeHeader($body,false,false));
1141 echo '</textarea><br />' . "\n" .
1146 if ($location_of_buttons == 'bottom') {
1147 showComposeButtonRow();
1149 echo ' <tr>' . "\n" .
1150 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1151 ' ' . addSubmit(_("Send"), 'send').
1152 ' <br /><br />' . "\n" .
1157 /* This code is for attachments */
1158 if ((bool) ini_get('file_uploads')) {
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. */
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) {
1167 /* skip 0 or empty values, and -1 which means 'unlimited' */
1168 if( $size = getByteSize(ini_get($var)) ) {
1169 if ( $size != '-1' ) {
1175 if(count($sizes) > 0) {
1176 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1177 echo addHidden('MAX_FILE_SIZE', min( $sizes ));
1181 echo ' <tr>' . "\n" .
1182 ' <td colspan="2">' . "\n" .
1183 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1184 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1187 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1188 ' border="0">' . "\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 ' <input type="submit" name="attach"' .
1195 ' value="' . _("Add") .'" />' . "\n" .
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
.'/'.
1207 $attachment->mime_header
->type1
;
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";
1219 foreach ($s_a as $s) {
1220 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1222 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1223 _("Delete selected attachments") . "\" />\n" .
1226 echo ' </table>' . "\n" .
1229 ' </table>' . "\n" .
1232 } // End of file_uploads if-block
1233 /* End of attachment code */
1234 if ($compose_new_win == '1') {
1235 echo '</table>'."\n";
1238 echo '</table>' . "\n" .
1239 addHidden('username', $username).
1240 addHidden('smaction', $action).
1241 addHidden('mailbox', $mailbox);
1243 store the complete ComposeMessages array in a hidden input value
1244 so we can restore them in case of a session timeout.
1246 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1247 echo addHidden('restoremessages', serialize($compose_messages)).
1248 addHidden('composesession', $composesession).
1249 addHidden('querystring', $queryString).
1251 if (!(bool) ini_get('file_uploads')) {
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. */
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.")
1259 do_hook('compose_bottom');
1260 echo '</body></html>' . "\n";
1264 function showComposeButtonRow() {
1265 global $use_javascript_addr_book, $save_as_draft,
1266 $default_use_priority, $mailprio, $default_use_mdn,
1267 $request_mdn, $request_dr,
1268 $data_dir, $username;
1270 echo ' <tr>' . "\n" .
1271 ' <td></td>' . "\n" .
1273 if ($default_use_priority) {
1274 if(!isset($mailprio)) {
1277 echo ' ' . _("Priority") .
1278 addSelect('mailprio', array(
1281 '5' => _("Low") ), $mailprio, TRUE);
1283 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1284 if ($default_use_mdn) {
1285 if ($mdn_user_support) {
1286 echo ' ' . _("Receipt") .': '.
1287 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1288 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1292 echo ' </td>' . "\n" .
1295 ' <td></td>' . "\n" .
1297 ' <input type="submit" name="sigappend" value="' . _("Signature") . '" />' . "\n";
1298 if ($use_javascript_addr_book) {
1299 echo " <script language=\"JavaScript\"><!--\n document.write(\"".
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").'" />'.
1307 echo ' <input type="submit" name="html_addr_search" value="'.
1308 _("Addresses").'" />' . "\n";
1311 if ($save_as_draft) {
1312 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\" />\n";
1315 echo ' <input type="submit" name="send" value="'. _("Send") . '" />' . "\n";
1316 do_hook('compose_button_row');
1318 echo ' </td>' . "\n" .
1322 function checkInput ($show) {
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
1329 global $body, $send_to, $send_to_bcc, $subject, $color;
1331 if ($send_to == '' && $send_to_bcc == '') {
1333 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1338 } /* function checkInput() */
1341 /* True if FAILURE */
1342 function saveAttachedFiles($session) {
1343 global $_FILES, $attachment_dir, $attachments, $username,
1344 $data_dir, $compose_messages;
1346 /* get out of here if no file was attached at all */
1347 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
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";
1359 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1360 // m_u_f works better with restricted PHP installs (safe_mode, open_basedir)
1361 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1362 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1366 $message = $compose_messages[$session];
1367 $type = strtolower($_FILES['attachfile']['type']);
1368 $name = $_FILES['attachfile']['name'];
1369 $message->initAttachment($type, $name, $full_localfilename);
1370 $compose_messages[$session] = $message;
1371 sqsession_register($compose_messages , 'compose_messages');
1374 function ClearAttachments($composeMessage) {
1375 if ($composeMessage->att_local_name
) {
1376 $attached_file = $composeMessage->att_local_name
;
1377 if (file_exists($attached_file)) {
1378 unlink($attached_file);
1381 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1382 ClearAttachments($composeMessage->entities
[$i]);
1386 /* parse values like 8M and 2k into bytes */
1387 function getByteSize($ini_size) {
1393 $ini_size = trim($ini_size);
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))) {
1398 switch(strtoupper(substr($ini_size, -1))) {
1400 $bytesize = 1073741824;
1403 $bytesize = 1048576;
1410 return ($bytesize * (int)substr($ini_size, 0, -1));
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.
1423 function deliverMessage($composeMessage, $draft=false) {
1424 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
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;
1428 global $imapServerAddress, $imapPort, $sent_folder, $key;
1430 $rfc822_header = $composeMessage->rfc822_header
;
1432 $abook = addressbook_init(false, true);
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'));
1436 $rfc822_header->priority
= $mailprio;
1437 $rfc822_header->subject
= $subject;
1439 $special_encoding='';
1440 if (strtolower($default_charset) == 'iso-2022-jp') {
1441 if (mb_detect_encoding($body) == 'ASCII') {
1442 $special_encoding = '8bit';
1444 $body = mb_convert_encoding($body, 'JIS');
1445 $special_encoding = '7bit';
1448 $composeMessage->setBody($body);
1450 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1451 $popuser = $usernamedata[1];
1452 $domain = $usernamedata[2];
1453 unset($usernamedata);
1455 $popuser = $username;
1458 $from_mail = $idents[$identity]['email_address'];
1459 $full_name = $idents[$identity]['full_name'];
1460 $reply_to = $idents[$identity]['reply_to'];
1462 $from_mail = "$popuser@$domain";
1464 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1466 $from = $rfc822_header->from
[0];
1467 if (!$from->host
) $from->host
= $domain;
1468 $full_name_encoded = encodeHeader($full_name);
1469 if ($full_name_encoded != $full_name) {
1470 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1472 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1474 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1477 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1479 /* Receipt: On Read */
1480 if (isset($request_mdn) && $request_mdn) {
1481 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1483 /* Receipt: On Delivery */
1484 if (isset($request_dr) && $request_dr) {
1485 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1487 /* multipart messages */
1488 if (count($composeMessage->entities
)) {
1489 $message_body = new Message();
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;
1498 $mime_header->encoding
= '8bit';
1500 if ($default_charset) {
1501 $mime_header->parameters
['charset'] = $default_charset;
1503 $message_body->mime_header
= $mime_header;
1504 array_unshift($composeMessage->entities
, $message_body);
1505 $content_type = new ContentType('multipart/mixed');
1507 $content_type = new ContentType('text/plain');
1508 if ($special_encoding) {
1509 $rfc822_header->encoding
= $special_encoding;
1511 $rfc822_header->encoding
= '8bit';
1513 if ($default_charset) {
1514 $content_type->properties
['charset']=$default_charset;
1518 $rfc822_header->content_type
= $content_type;
1519 $composeMessage->rfc822_header
= $rfc822_header;
1521 /* Here you can modify the message structure just before we hand
1522 it over to deliver */
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];
1529 if (!$useSendmail && !$draft) {
1530 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1531 $deliver = new Deliver_SMTP();
1532 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
1534 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1535 get_smtp_user($user, $pass);
1536 $stream = $deliver->initStream($composeMessage,$domain,0,
1537 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1538 } elseif (!$draft) {
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);
1544 global $draft_folder;
1545 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1546 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
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);
1559 $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
1560 plain_error_message($msg, $color);
1566 $length = $deliver->mail($composeMessage, $stream);
1567 $succes = $deliver->finalizeStream($stream);
1570 $msg = $deliver->dlv_msg
. '<br />' .
1571 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1572 $deliver->dlv_server_msg
;
1573 plain_error_message($msg, $color);
1576 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1577 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1579 /* Move to sent code */
1580 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1581 $svr_allow_sent = true;
1583 $svr_allow_sent = false;
1586 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1587 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1593 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1594 $lcl_allow_sent = true;
1596 $lcl_allow_sent = false;
1599 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
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;
1607 sqimap_append ($imap_stream, $sent_folder, $length);
1608 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1609 $imap_deliver = new Deliver_IMAP();
1610 $imap_deliver->mail($composeMessage, $imap_stream);
1611 sqimap_append_done ($imap_stream, $sent_folder);
1612 unset ($imap_deliver);
1614 global $passed_id, $mailbox, $action;
1615 ClearAttachments($composeMessage);
1616 if ($action == 'reply' ||
$action == 'reply_all') {
1617 sqimap_mailbox_select ($imap_stream, $mailbox);
1618 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1620 sqimap_logout($imap_stream);