2b87c2f09c65da6e061277a8050074a89fd1fac2
6 * Copyright (c) 1999-2004 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
21 /** Path for SquirrelMail required files. */
22 define('SM_PATH','../');
24 /* SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 require_once(SM_PATH
. 'functions/global.php');
27 require_once(SM_PATH
. 'functions/imap.php');
28 require_once(SM_PATH
. 'functions/date.php');
29 require_once(SM_PATH
. 'functions/mime.php');
30 require_once(SM_PATH
. 'functions/plugin.php');
31 require_once(SM_PATH
. 'functions/display_messages.php');
32 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
33 require_once(SM_PATH
. 'functions/addressbook.php');
34 require_once(SM_PATH
. 'functions/identity.php');
35 require_once(SM_PATH
. 'functions/forms.php');
37 /* --------------------- Get globals ------------------------------------- */
39 sqgetGlobalVar('key', $key, SQ_COOKIE
);
42 sqgetGlobalVar('username', $username, SQ_SESSION
);
43 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
44 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
45 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
47 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
48 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
50 /** SESSION/POST/GET VARS */
51 sqgetGlobalVar('session',$session);
52 sqgetGlobalVar('mailbox',$mailbox);
53 if(!sqgetGlobalVar('identity',$identity)) {
56 sqgetGlobalVar('send_to',$send_to);
57 sqgetGlobalVar('send_to_cc',$send_to_cc);
58 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
59 sqgetGlobalVar('subject',$subject);
60 sqgetGlobalVar('body',$body);
61 sqgetGlobalVar('mailprio',$mailprio);
62 sqgetGlobalVar('request_mdn',$request_mdn);
63 sqgetGlobalVar('request_dr',$request_dr);
64 sqgetGlobalVar('html_addr_search',$html_addr_search);
65 sqgetGlobalVar('mail_sent',$mail_sent);
66 sqgetGlobalVar('passed_id',$passed_id);
67 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
68 sqgetGlobalVar('send',$send);
70 sqgetGlobalVar('attach',$attach);
72 sqgetGlobalVar('draft',$draft);
73 sqgetGlobalVar('draft_id',$draft_id);
74 sqgetGlobalVar('ent_num',$ent_num);
75 sqgetGlobalVar('saved_draft',$saved_draft);
76 sqgetGlobalVar('delete_draft',$delete_draft);
77 sqgetGlobalVar('startMessage',$startMessage);
80 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
81 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
82 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
83 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
84 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
85 sqgetGlobalVar('delete', $delete, SQ_POST
);
86 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
87 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
88 $html_addr_search_done = 'Use Addresses';
92 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
95 if ( !sqgetGlobalVar('smaction',$action) )
97 if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply';
98 if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all';
99 if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward';
100 if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment';
101 if ( sqgetGlobalVar('smaction_draft',$tmp) ) $action = 'draft';
102 if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action = 'edit_as_new';
107 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
108 $location = get_location();
109 /* Identities (fetch only once) */
110 $idents = get_identities();
112 /* --------------------- Specific Functions ------------------------------ */
114 function replyAllString($header) {
115 global $include_self_reply_all, $idents;
118 * 1) Remove the addresses we'll be sending the message 'to'
120 $url_replytoall_avoid_addrs = '';
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;
160 function getReplyCitation($orig_from, $orig_date) {
161 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
162 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
163 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
164 /* First, return an empty string when no citation style selected. */
165 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
169 /* Make sure our final value isn't an empty string. */
170 if ($orig_from == '') {
174 /* Otherwise, try to select the desired citation style. */
175 switch ($reply_citation_style) {
178 $end = ' ' . _("said") . ':';
181 $start = '<' . _("quote") . ' ' . _("who") . '="';
184 case 'date_time_author':
185 $start = 'On ' . getLongDateString($orig_date) . ', ';
186 $end = ' ' . _("said") . ':';
189 $start = $reply_citation_start .
190 ($reply_citation_start == '' ?
'' : ' ');
191 $end = $reply_citation_end;
197 /* Build and return the citation string. */
198 return ($start . $orig_from . $end . "\n");
201 function getforwardHeader($orig_header) {
204 $display = array( _("Subject") => strlen(_("Subject")),
205 _("From") => strlen(_("From")),
206 _("Date") => strlen(_("Date")),
207 _("To") => strlen(_("To")),
208 _("Cc") => strlen(_("Cc")) );
209 $maxsize = max($display);
210 $indent = str_pad('',$maxsize+
2);
211 foreach($display as $key => $val) {
212 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
214 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
215 $from = str_replace(' ',' ',$from);
216 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
217 $to = str_replace(' ',' ',$to);
218 $subject = decodeHeader($orig_header->subject
,false,false,true);
219 $subject = str_replace(' ',' ',$subject);
220 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
221 "\n". $display[_("Subject")] . $subject . "\n" .
222 $display[_("From")] . $from . "\n" .
223 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
224 $display[_("To")] . $to . "\n";
225 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
226 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
227 $cc = str_replace(' ',' ',$cc);
228 $bodyTop .= $display[_("Cc")] .$cc . "\n";
230 $bodyTop .= str_pad('', $editor_size -2 , '-') .
234 /* ----------------------------------------------------------------------- */
237 * If the session is expired during a post this restores the compose session
240 if (sqsession_is_registered('session_expired_post')) {
241 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
243 * extra check for username so we don't display previous post data from
244 * another user during this session.
246 if ($session_expired_post['username'] != $username) {
247 unset($session_expired_post);
248 sqsession_unregister('session_expired_post');
249 session_write_close();
251 foreach ($session_expired_post as $postvar => $val) {
258 $compose_messages = unserialize(urldecode($restoremessages));
259 sqsession_register($compose_messages,'compose_messages');
260 sqsession_register($composesession,'composesession');
264 $session_expired = true;
266 unset($session_expired_post);
267 sqsession_unregister('session_expired_post');
268 session_write_close();
269 if (!isset($mailbox)) {
272 if ($compose_new_win == '1') {
273 compose_Header($color, $mailbox);
275 displayPageHeader($color, $mailbox);
277 showInputForm($session, false);
280 if (!isset($composesession)) {
282 sqsession_register(0,'composesession');
285 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
286 sqsession_unregister('composesession');
287 $session = "$composesession" +
1;
288 $composesession = $session;
289 sqsession_register($composesession,'composesession');
291 if (!isset($compose_messages)) {
292 $compose_messages = array();
294 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
295 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
296 $composeMessage = new Message();
297 $rfc822_header = new Rfc822Header();
298 $composeMessage->rfc822_header
= $rfc822_header;
299 $composeMessage->reply_rfc822_header
= '';
300 $compose_messages[$session] = $composeMessage;
301 sqsession_register($compose_messages,'compose_messages');
303 $composeMessage=$compose_messages[$session];
306 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
312 * Set $default_charset to correspond with the user's selection
313 * of language interface.
316 $composeMessage=$compose_messages[$session];
317 if (! deliverMessage($composeMessage, true)) {
318 showInputForm($session);
321 unset($compose_messages[$session]);
322 $draft_message = _("Draft Email Saved");
323 /* If this is a resumed draft, then delete the original */
324 if(isset($delete_draft)) {
325 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
326 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
330 if ($compose_new_win == '1') {
331 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
335 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
336 "&startMessage=1¬e=".urlencode($draft_message));
344 if (isset($_FILES['attachfile']) &&
345 $_FILES['attachfile']['tmp_name'] &&
346 $_FILES['attachfile']['tmp_name'] != 'none') {
347 $AttachFailure = saveAttachedFiles($session);
349 if (checkInput(false) && !isset($AttachFailure)) {
350 if ($mailbox == "All Folders") {
351 /* We entered compose via the search results page */
352 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
354 $urlMailbox = urlencode (trim($mailbox));
355 if (! isset($passed_id)) {
359 * Set $default_charset to correspond with the user's selection
360 * of language interface.
364 * This is to change all newlines to \n
365 * We'll change them to \r\n later (in the sendMessage function)
367 $body = str_replace("\r\n", "\n", $body);
368 $body = str_replace("\r", "\n", $body);
371 * Rewrap $body so that no line is bigger than $editor_size
372 * This should only really kick in the sqWordWrap function
373 * if the browser doesn't support "VIRTUAL" as the wrap type.
375 $body = explode("\n", $body);
377 foreach ($body as $line) {
378 if( $line <> '-- ' ) {
379 $line = rtrim($line);
381 if (strlen($line) <= $editor_size +
1) {
382 $newBody .= $line . "\n";
384 sqWordWrap($line, $editor_size);
385 $newBody .= $line . "\n";
392 $composeMessage=$compose_messages[$session];
394 $Result = deliverMessage($composeMessage);
396 showInputForm($session);
399 unset($compose_messages[$session]);
400 if ( isset($delete_draft)) {
401 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
402 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
405 if ($compose_new_win == '1') {
407 Header("Location: $location/compose.php?mail_sent=yes");
410 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
411 "&startMessage=$startMessage&mail_sent=yes");
414 if ($compose_new_win == '1') {
415 compose_Header($color, $mailbox);
418 displayPageHeader($color, $mailbox);
420 if (isset($AttachFailure)) {
421 plain_error_message(_("Could not move/copy file. File not attached"),
425 showInputForm($session);
426 /* sqimap_logout($imapConnection); */
428 } elseif (isset($html_addr_search_done)) {
429 if ($compose_new_win == '1') {
430 compose_Header($color, $mailbox);
433 displayPageHeader($color, $mailbox);
436 if (isset($send_to_search) && is_array($send_to_search)) {
437 foreach ($send_to_search as $k => $v) {
438 if (substr($k, 0, 1) == 'T') {
444 elseif (substr($k, 0, 1) == 'C') {
450 elseif (substr($k, 0, 1) == 'B') {
452 $send_to_bcc .= ', ';
458 showInputForm($session);
459 } elseif (isset($html_addr_search)) {
460 if (isset($_FILES['attachfile']) &&
461 $_FILES['attachfile']['tmp_name'] &&
462 $_FILES['attachfile']['tmp_name'] != 'none') {
463 if(saveAttachedFiles($session)) {
464 plain_error_message(_("Could not move/copy file. File not attached"), $color);
468 * I am using an include so as to elminiate an extra unnecessary
469 * click. If you can think of a better way, please implement it.
471 include_once('./addrbook_search_html.php');
472 } elseif (isset($attach)) {
473 if (saveAttachedFiles($session)) {
474 plain_error_message(_("Could not move/copy file. File not attached"), $color);
476 if ($compose_new_win == '1') {
477 compose_Header($color, $mailbox);
480 displayPageHeader($color, $mailbox);
482 showInputForm($session);
484 elseif (isset($sigappend)) {
485 $signature = $idents[$identity]['signature'];
487 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
488 if ($compose_new_win == '1') {
489 compose_Header($color, $mailbox);
491 displayPageHeader($color, $mailbox);
493 showInputForm($session);
494 } elseif (isset($do_delete)) {
495 if ($compose_new_win == '1') {
496 compose_Header($color, $mailbox);
499 displayPageHeader($color, $mailbox);
502 if (isset($delete) && is_array($delete)) {
503 $composeMessage = $compose_messages[$session];
504 foreach($delete as $index) {
505 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
506 unlink ($attached_file);
507 unset ($composeMessage->entities
[$index]);
509 $new_entities = array();
510 foreach ($composeMessage->entities
as $entity) {
511 $new_entities[] = $entity;
513 $composeMessage->entities
= $new_entities;
514 $compose_messages[$session] = $composeMessage;
515 sqsession_register($compose_messages, 'compose_messages');
517 showInputForm($session);
520 * This handles the default case as well as the error case
521 * (they had the same code) --> if (isset($smtpErrors))
524 if ($compose_new_win == '1') {
525 compose_Header($color, $mailbox);
527 displayPageHeader($color, $mailbox);
532 if (!isset($passed_ent_id)) {
535 if (!isset($passed_id)) {
538 if (!isset($mailbox)) {
541 if (!isset($action)) {
545 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
547 /* in case the origin is not read_body.php */
548 if (isset($send_to)) {
549 $values['send_to'] = $send_to;
551 if (isset($send_to_cc)) {
552 $values['send_to_cc'] = $send_to_cc;
554 if (isset($send_to_bcc)) {
555 $values['send_to_bcc'] = $send_to_bcc;
557 if (isset($subject)) {
558 $values['subject'] = $subject;
560 showInputForm($session, $values);
565 /**************** Only function definitions go below *************/
567 function getforwardSubject($subject)
569 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
570 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
571 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
572 $subject = '[Fwd: ' . $subject . ']';
577 /* This function is used when not sending or adding attachments */
578 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
579 global $editor_size, $default_use_priority, $body, $idents,
580 $use_signature, $composesession, $data_dir, $username,
581 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
583 global $languages, $squirrelmail_language, $default_charset;
585 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
589 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
592 sqimap_mailbox_select($imapConnection, $mailbox);
593 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
596 if ($passed_ent_id) {
597 /* redefine the messsage in case of message/rfc822 */
598 $message = $message->getEntity($passed_ent_id);
599 /* message is an entity which contains the envelope and type0=message
600 * and type1=rfc822. The actual entities are childs from
601 * $message->entities[0]. That's where the encoding and is located
604 $entities = $message->entities
[0]->findDisplayEntity
605 (array(), $alt_order = array('text/plain'));
606 if (!count($entities)) {
607 $entities = $message->entities
[0]->findDisplayEntity
608 (array(), $alt_order = array('text/plain','html/plain'));
610 $orig_header = $message->rfc822_header
; /* here is the envelope located */
611 /* redefine the message for picking up the attachments */
612 $message = $message->entities
[0];
615 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
616 if (!count($entities)) {
617 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
619 $orig_header = $message->rfc822_header
;
622 $encoding = $message->header
->encoding
;
623 $type0 = $message->type0
;
624 $type1 = $message->type1
;
625 foreach ($entities as $ent) {
626 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
627 $body_part_entity = $message->getEntity($ent);
628 $bodypart = decodeBody($unencoded_bodypart,
629 $body_part_entity->header
->encoding
);
630 if ($type1 == 'html') {
631 $bodypart = str_replace("\n", ' ', $bodypart);
632 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
633 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
634 $bodypart = strip_tags($bodypart);
637 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
638 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
639 if (mb_detect_encoding($bodypart) != 'ASCII') {
640 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
644 if (isset($body_part_entity->header
->parameters
['charset'])) {
645 $actual = $body_part_entity->header
->parameters
['charset'];
647 $actual = 'us-ascii';
650 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
651 $bodypart = charset_decode($actual,$bodypart);
656 if ($default_use_priority) {
657 $mailprio = substr($orig_header->priority
,0,1);
664 //ClearAttachments($session);
667 $from_o = $orig_header->from
;
668 if (is_object($from_o)) {
669 $orig_from = $from_o->getAddress();
674 $identities = array();
675 if (count($idents) > 1) {
676 foreach($idents as $nr=>$data) {
677 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
678 if($enc_from_name == $orig_from) {
682 $identities[] = $enc_from_name;
685 $identity_match = $orig_header->findAddress($identities);
686 if ($identity_match) {
687 $identity = $identity_match;
689 // we need identiy here fore draft case #845290
690 // echo $identity."leer";
695 $use_signature = FALSE;
696 $composeMessage->rfc822_header
= $orig_header;
697 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
698 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
699 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
700 $send_from = $orig_header->getAddr_s('from');
701 $send_from_parts = new AddressStructure();
702 $send_from_parts = $orig_header->parseAddress($send_from);
703 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
704 $identities = get_identities();
705 if (count($identities) > 0) {
706 foreach($identities as $iddata) {
707 if ($send_from_add == $iddata['email_address']) {
708 $identity = $iddata['index'];
713 $subject = decodeHeader($orig_header->subject
,false,false,true);
714 // /* remember the references and in-reply-to headers in case of an reply */
715 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
716 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
717 $body_ary = explode("\n", $body);
718 $cnt = count($body_ary) ;
720 for ($i=0; $i < $cnt; $i++
) {
721 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
722 sqWordWrap($body_ary[$i], $editor_size );
723 $body .= $body_ary[$i] . "\n";
725 unset($body_ary[$i]);
728 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
730 case ('edit_as_new'):
731 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
732 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
733 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
734 $subject = decodeHeader($orig_header->subject
,false,false,true);
735 $mailprio = $orig_header->priority
;
737 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
742 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
743 $body = getforwardHeader($orig_header) . $body;
745 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
746 $body = "\n" . $body;
748 case ('forward_as_attachment'):
749 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
750 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
754 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
755 $send_to = $orig_header->getAddr_s('mail_followup_to');
757 $send_to_cc = replyAllString($orig_header);
758 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
761 // skip this if send_to was already set right above here
763 $send_to = $orig_header->reply_to
;
764 if (is_array($send_to) && count($send_to)) {
765 $send_to = $orig_header->getAddr_s('reply_to');
766 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
767 $send_to = $orig_header->getAddr_s('reply_to');
769 $send_to = $orig_header->getAddr_s('from');
772 $send_to = decodeHeader($send_to,false,false,true);
773 $subject = decodeHeader($orig_header->subject
,false,false,true);
774 $subject = str_replace('"', "'", $subject);
775 $subject = trim($subject);
776 if (substr(strtolower($subject), 0, 3) != 're:') {
777 $subject = 'Re: ' . $subject;
779 /* this corrects some wrapping/quoting problems on replies */
780 $rewrap_body = explode("\n", $body);
781 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
782 sqUnWordWrap($body); // unwrap and then reset it?!
784 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
785 foreach ($rewrap_body as $line) {
786 if ($strip_sigs && substr($line,0,3) == '-- ') {
789 sqWordWrap($line, ($editor_size));
790 if (preg_match("/^(>+)/", $line, $matches)) {
792 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
794 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
797 $body = getReplyCitation($from , $orig_header->date
) . $body;
798 $composeMessage->reply_rfc822_header
= $orig_header;
804 $compose_messages[$session] = $composeMessage;
805 sqsession_register($compose_messages, 'compose_messages');
806 session_write_close();
807 sqimap_logout($imapConnection);
809 $ret = array( 'send_to' => $send_to,
810 'send_to_cc' => $send_to_cc,
811 'send_to_bcc' => $send_to_bcc,
812 'subject' => $subject,
813 'mailprio' => $mailprio,
815 'identity' => $identity );
818 } /* function newMail() */
820 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
821 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
822 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
823 if (!count($message->entities
) ||
824 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
825 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
826 switch ($message->type0
) {
828 if ($message->type1
== 'rfc822') {
829 $filename = $message->rfc822_header
->subject
;
830 if ($filename == "") {
831 $filename = "untitled-".$message->entity_id
;
835 $filename = $message->getFilename();
839 if (!$message->mime_header
) { /* temporary hack */
840 $message->mime_header
= $message->header
;
842 $filename = $message->getFilename();
845 $filename = str_replace(' ', ' ', decodeHeader($filename));
846 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
847 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
848 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
850 $localfilename = GenerateRandomString(32, '', 7);
851 $full_localfilename = "$hashed_attachment_dir/$localfilename";
852 while (file_exists($full_localfilename)) {
853 $localfilename = GenerateRandomString(32, '', 7);
854 $full_localfilename = "$hashed_attachment_dir/$localfilename";
856 $message->att_local_name
= $full_localfilename;
858 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
859 $full_localfilename);
861 /* Write Attachment to file */
862 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
863 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
864 $passed_id, $message->entity_id
),
865 $message->header
->encoding
));
869 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
870 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
873 return $composeMessage;
876 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
877 $passed_ent_id='', $imapConnection) {
878 global $attachments, $attachment_dir, $username, $data_dir;
879 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
880 if (!$passed_ent_id) {
881 $body_a = sqimap_run_command($imapConnection,
882 'FETCH '.$passed_id.' RFC822',
883 TRUE, $response, $readmessage,
886 $body_a = sqimap_run_command($imapConnection,
887 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
888 TRUE, $response, $readmessage, TRUE);
889 $message = $message->parent
;
891 if ($response == 'OK') {
892 $subject = encodeHeader($message->rfc822_header
->subject
);
893 array_shift($body_a);
895 $body = implode('', $body_a) . "\r\n";
897 $localfilename = GenerateRandomString(32, 'FILE', 7);
898 $full_localfilename = "$hashed_attachment_dir/$localfilename";
900 $fp = fopen($full_localfilename, 'w');
903 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
904 $full_localfilename);
906 return $composeMessage;
909 function showInputForm ($session, $values=false) {
910 global $send_to, $send_to_cc, $body, $startMessage,
911 $passed_body, $color, $use_signature, $signature, $prefix_sig,
912 $editor_size, $editor_height, $attachments, $subject, $newmail,
913 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
914 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
915 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
916 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
917 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
918 $username, $compose_messages, $composesession, $default_charset;
920 $composeMessage = $compose_messages[$session];
922 $send_to = $values['send_to'];
923 $send_to_cc = $values['send_to_cc'];
924 $send_to_bcc = $values['send_to_bcc'];
925 $subject = $values['subject'];
926 $mailprio = $values['mailprio'];
927 $body = $values['body'];
928 $identity = (int) $values['identity'];
930 $send_to = decodeHeader($send_to, true, false);
931 $send_to_cc = decodeHeader($send_to_cc, true, false);
932 $send_to_bcc = decodeHeader($send_to_bcc, true, false);
935 if ($use_javascript_addr_book) {
936 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
937 'function open_abook() { ' . "\n" .
938 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
939 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
940 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
941 ' nwin.opener = document.windows;' . "\n" .
943 "// -->\n</SCRIPT>\n\n";
946 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
947 'enctype="multipart/form-data"';
948 do_hook('compose_form');
952 echo addHidden('startMessage', $startMessage);
954 if ($action == 'draft') {
955 echo addHidden('delete_draft', $passed_id);
957 if (isset($delete_draft)) {
958 echo addHidden('delete_draft', $delete_draft);
960 if (isset($session)) {
961 echo addHidden('session', $session);
964 if (isset($passed_id)) {
965 echo addHidden('passed_id', $passed_id);
968 if ($saved_draft == 'yes') {
969 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
971 if ($mail_sent == 'yes') {
972 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
974 echo '<table align="center" cellspacing="0" border="0">' . "\n";
975 if ($compose_new_win == '1') {
976 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
977 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
979 if ($location_of_buttons == 'top') {
980 showComposeButtonRow();
983 /* display select list for identities */
984 if (count($idents) > 1) {
985 $ident_list = array();
986 foreach($idents as $id => $data) {
988 $data['full_name'].' <'.$data['email_address'].'>';
990 echo ' <tr>' . "\n" .
991 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
992 _("From:") . '</td>' . "\n" .
993 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
995 addSelect('identity', $ident_list, $identity, TRUE);
997 echo ' </td>' . "\n" .
1000 echo ' <tr>' . "\n" .
1001 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1002 _("To:") . '</TD>' . "\n" .
1003 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1004 addInput('send_to', $send_to, 60). '<br />' . "\n" .
1008 html_tag( 'td', '', 'right', $color[4] ) .
1009 _("CC:") . '</td>' . "\n" .
1010 html_tag( 'td', '', 'left', $color[4] ) .
1011 addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
1015 html_tag( 'td', '', 'right', $color[4] ) .
1016 _("BCC:") . '</td>' . "\n" .
1017 html_tag( 'td', '', 'left', $color[4] ) .
1018 addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
1022 html_tag( 'td', '', 'right', $color[4] ) .
1023 _("Subject:") . '</td>' . "\n" .
1024 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1025 echo ' '.addInput('subject', $subject, 60).
1029 if ($location_of_buttons == 'between') {
1030 showComposeButtonRow();
1033 /* why this distinction? */
1034 if ($compose_new_win == '1') {
1035 echo ' <TR>' . "\n" .
1036 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1037 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1038 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1041 echo ' <TR>' . "\n" .
1042 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1043 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1044 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1047 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1048 $signature = $idents[$identity]['signature'];
1050 if ($sig_first == '1') {
1051 if ($default_charset == 'iso-2022-jp') {
1052 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1054 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1056 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1059 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1060 if ($default_charset == 'iso-2022-jp') {
1061 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1063 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1068 echo htmlspecialchars(decodeHeader($body,false,false));
1070 echo '</textarea><br />' . "\n" .
1075 if ($location_of_buttons == 'bottom') {
1076 showComposeButtonRow();
1078 echo ' <tr>' . "\n" .
1079 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1080 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1081 ' <br /><br />' . "\n" .
1086 /* This code is for attachments */
1087 if ((bool) ini_get('file_uploads')) {
1089 /* Calculate the max size for an uploaded file.
1090 * This is advisory for the user because we can't actually prevent
1091 * people to upload too large files. */
1093 /* php.ini vars which influence the max for uploads */
1094 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1095 foreach($configvars as $var) {
1096 /* skip 0 or empty values */
1097 if( $size = getByteSize(ini_get($var)) ) {
1102 if(count($sizes) > 0) {
1103 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1107 echo addHidden('MAX_FILE_SIZE', min( $sizes ));
1108 echo ' <tr>' . "\n" .
1109 ' <td colspan="2">' . "\n" .
1110 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1111 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1114 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1115 ' border="0">' . "\n" .
1117 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1118 _("Attach:") . '</td>' . "\n" .
1119 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1120 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1121 ' <input type="submit" name="attach"' .
1122 ' value="' . _("Add") .'">' . "\n" .
1129 if ($composeMessage->entities
) {
1130 foreach ($composeMessage->entities
as $key => $attachment) {
1131 $attached_file = $attachment->att_local_name
;
1132 if ($attachment->att_local_name ||
$attachment->body_part
) {
1133 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1134 $type = $attachment->mime_header
->type0
.'/'.
1135 $attachment->mime_header
->type1
;
1137 $s_a[] = '<table bgcolor="'.$color[0].
1138 '" border="0"><tr><td>'.
1139 addCheckBox('delete[]', FALSE, $key).
1140 "</td><td>\n" . $attached_filename .
1141 '</td><td>-</td><td> ' . $type . '</td><td>('.
1142 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1147 foreach ($s_a as $s) {
1148 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1150 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1151 _("Delete selected attachments") . "\">\n" .
1154 echo ' </table>' . "\n" .
1157 ' </TABLE>' . "\n" .
1160 } // End of file_uploads if-block
1161 /* End of attachment code */
1162 if ($compose_new_win == '1') {
1163 echo '</TABLE>'."\n";
1166 echo '</TABLE>' . "\n" .
1167 addHidden('username', $username).
1168 addHidden('smaction', $action).
1169 addHidden('mailbox', $mailbox);
1171 store the complete ComposeMessages array in a hidden input value
1172 so we can restore them in case of a session timeout.
1174 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1175 echo addHidden('restoremessages', serialize($compose_messages)).
1176 addHidden('composesession', $composesession).
1177 addHidden('querystring', $queryString).
1179 if (!(bool) ini_get('file_uploads')) {
1180 /* File uploads are off, so we didn't show that part of the form.
1181 To avoid bogus bug reports, tell the user why. */
1182 echo 'Because PHP file uploads are turned off, you can not attach files ';
1183 echo "to this message. Please see your system administrator for details.\r\n";
1186 do_hook('compose_bottom');
1187 echo '</BODY></HTML>' . "\n";
1191 function showComposeButtonRow() {
1192 global $use_javascript_addr_book, $save_as_draft,
1193 $default_use_priority, $mailprio, $default_use_mdn,
1194 $request_mdn, $request_dr,
1195 $data_dir, $username;
1197 echo ' <TR>' . "\n" .
1198 ' <TD></TD>' . "\n" .
1200 if ($default_use_priority) {
1201 if(!isset($mailprio)) {
1204 echo ' ' . _("Priority") .
1205 addSelect('mailprio', array(
1208 '5' => _("Low") ), $mailprio, TRUE);
1210 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1211 if ($default_use_mdn) {
1212 if ($mdn_user_support) {
1213 echo ' ' . _("Receipt") .': '.
1214 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1215 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1219 echo ' </TD>' . "\n" .
1222 ' <TD></TD>' . "\n" .
1224 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1225 if ($use_javascript_addr_book) {
1226 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1227 " <input type=button value=\\\""._("Addresses").
1228 "\\\" onclick='javascript:open_abook();'>\");".
1229 " // --></SCRIPT><NOSCRIPT>\n".
1230 " <input type=submit name=\"html_addr_search\" value=\"".
1231 _("Addresses")."\">".
1234 echo ' <input type=submit name="html_addr_search" value="'.
1235 _("Addresses").'">' . "\n";
1238 if ($save_as_draft) {
1239 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1242 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1243 do_hook('compose_button_row');
1245 echo ' </TD>' . "\n" .
1249 function checkInput ($show) {
1251 * I implemented the $show variable because the error messages
1252 * were getting sent before the page header. So, I check once
1253 * using $show=false, and then when i'm ready to display the error
1254 * message, show=true
1256 global $body, $send_to, $send_to_bcc, $subject, $color;
1258 if ($send_to == '' && $send_to_bcc == '') {
1260 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1265 } /* function checkInput() */
1268 /* True if FAILURE */
1269 function saveAttachedFiles($session) {
1270 global $_FILES, $attachment_dir, $attachments, $username,
1271 $data_dir, $compose_messages;
1273 /* get out of here if no file was attached at all */
1274 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1278 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1279 $localfilename = GenerateRandomString(32, '', 7);
1280 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1281 while (file_exists($full_localfilename)) {
1282 $localfilename = GenerateRandomString(32, '', 7);
1283 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1286 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1287 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1288 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1289 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1293 $message = $compose_messages[$session];
1294 $type = strtolower($_FILES['attachfile']['type']);
1295 $name = $_FILES['attachfile']['name'];
1296 $message->initAttachment($type, $name, $full_localfilename);
1297 $compose_messages[$session] = $message;
1298 sqsession_register($compose_messages , 'compose_messages');
1301 function ClearAttachments($composeMessage) {
1302 if ($composeMessage->att_local_name
) {
1303 $attached_file = $composeMessage->att_local_name
;
1304 if (file_exists($attached_file)) {
1305 unlink($attached_file);
1308 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1309 ClearAttachments($composeMessage->entities
[$i]);
1313 /* parse values like 8M and 2k into bytes */
1314 function getByteSize($ini_size) {
1320 $ini_size = trim($ini_size);
1322 // if there's some kind of letter at the end of the string we need to multiply.
1323 if(!is_numeric(substr($ini_size, -1))) {
1325 switch(strtoupper(substr($ini_size, -1))) {
1327 $bytesize = 1073741824;
1330 $bytesize = 1048576;
1337 return ($bytesize * (int)substr($ini_size, 0, -1));
1344 /* temporary function to make use of the deliver class.
1345 In the future the responsable backend should be automaticly loaded
1346 and conf.pl should show a list of available backends.
1347 The message also should be constructed by the message class.
1350 function deliverMessage($composeMessage, $draft=false) {
1351 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1352 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1353 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1354 $domain, $action, $default_move_to_sent, $move_to_sent;
1355 global $imapServerAddress, $imapPort, $sent_folder, $key;
1357 /* some browsers replace <space> by nonbreaking spaces
1358 by replacing them back to spaces addressparsing works */
1359 /* FIXME: How to handle in case of other charsets where "\240"
1360 is not a non breaking space ??? */
1361 /* THEFIX: browsers don't replace space with nbsp. SM replaces
1362 space with nbsp when decodes headers. If problem still happens,
1363 use cleanup_nbsp() */
1365 // $send_to = str_replace("\240",' ',$send_to);
1366 // $send_to_cc = str_replace("\240",' ',$send_to_cc);
1367 // $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1369 $rfc822_header = $composeMessage->rfc822_header
;
1371 $abook = addressbook_init(false, true);
1372 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1373 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1374 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1375 $rfc822_header->priority
= $mailprio;
1376 $rfc822_header->subject
= $subject;
1377 $special_encoding='';
1378 if (strtolower($default_charset) == 'iso-2022-jp') {
1379 if (mb_detect_encoding($body) == 'ASCII') {
1380 $special_encoding = '8bit';
1382 $body = mb_convert_encoding($body, 'JIS');
1383 $special_encoding = '7bit';
1386 $composeMessage->setBody($body);
1388 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1389 $popuser = $usernamedata[1];
1390 $domain = $usernamedata[2];
1391 unset($usernamedata);
1393 $popuser = $username;
1396 $from_mail = $idents[$identity]['email_address'];
1397 $full_name = $idents[$identity]['full_name'];
1398 $reply_to = $idents[$identity]['reply_to'];
1400 $from_mail = "$popuser@$domain";
1402 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1404 $from = $rfc822_header->from
[0];
1405 if (!$from->host
) $from->host
= $domain;
1406 $full_name_encoded = encodeHeader($full_name);
1407 if ($full_name_encoded != $full_name) {
1408 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1410 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1412 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1415 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1417 /* Receipt: On Read */
1418 if (isset($request_mdn) && $request_mdn) {
1419 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1421 /* Receipt: On Delivery */
1422 if (isset($request_dr) && $request_dr) {
1423 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1425 /* multipart messages */
1426 if (count($composeMessage->entities
)) {
1427 $message_body = new Message();
1428 $message_body->body_part
= $composeMessage->body_part
;
1429 $composeMessage->body_part
= '';
1430 $mime_header = new MessageHeader
;
1431 $mime_header->type0
= 'text';
1432 $mime_header->type1
= 'plain';
1433 if ($special_encoding) {
1434 $mime_header->encoding
= $special_encoding;
1436 $mime_header->encoding
= '8bit';
1438 if ($default_charset) {
1439 $mime_header->parameters
['charset'] = $default_charset;
1441 $message_body->mime_header
= $mime_header;
1442 array_unshift($composeMessage->entities
, $message_body);
1443 $content_type = new ContentType('multipart/mixed');
1445 $content_type = new ContentType('text/plain');
1446 if ($special_encoding) {
1447 $rfc822_header->encoding
= $special_encoding;
1449 $rfc822_header->encoding
= '8bit';
1451 if ($default_charset) {
1452 $content_type->properties
['charset']=$default_charset;
1456 $rfc822_header->content_type
= $content_type;
1457 $composeMessage->rfc822_header
= $rfc822_header;
1459 /* Here you can modify the message structure just before we hand
1460 it over to deliver */
1461 $hookReturn = do_hook('compose_send', $composeMessage);
1462 /* Get any changes made by plugins to $composeMessage. */
1463 if ( is_object($hookReturn[1]) ) {
1464 $composeMessage = $hookReturn[1];
1467 if (!$useSendmail && !$draft) {
1468 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1469 $deliver = new Deliver_SMTP();
1470 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1472 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1473 get_smtp_user($user, $pass);
1474 $stream = $deliver->initStream($composeMessage,$domain,0,
1475 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1476 } elseif (!$draft) {
1477 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1478 global $sendmail_path;
1479 $deliver = new Deliver_SendMail();
1480 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1482 global $draft_folder;
1483 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1484 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1486 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1487 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1488 $imap_deliver = new Deliver_IMAP();
1489 $length = $imap_deliver->mail($composeMessage);
1490 sqimap_append ($imap_stream, $draft_folder, $length);
1491 $imap_deliver->mail($composeMessage, $imap_stream);
1492 sqimap_append_done ($imap_stream, $draft_folder);
1493 sqimap_logout($imap_stream);
1494 unset ($imap_deliver);
1497 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1498 plain_error_message($msg, $color);
1504 $length = $deliver->mail($composeMessage, $stream);
1505 $succes = $deliver->finalizeStream($stream);
1508 $msg = $deliver->dlv_msg
. '<br>' .
1509 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1510 $deliver->dlv_server_msg
;
1511 plain_error_message($msg, $color);
1514 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1515 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1517 /* Move to sent code */
1518 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1519 $svr_allow_sent = true;
1521 $svr_allow_sent = false;
1524 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1525 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1531 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1532 $lcl_allow_sent = true;
1534 $lcl_allow_sent = false;
1537 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1538 global $passed_id, $mailbox, $action;
1539 if ($action == 'reply' ||
$action == 'reply_all') {
1540 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1541 if ($save_reply_with_orig) {
1542 $sent_folder = $mailbox;
1545 sqimap_append ($imap_stream, $sent_folder, $length);
1546 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1547 $imap_deliver = new Deliver_IMAP();
1548 $imap_deliver->mail($composeMessage, $imap_stream);
1549 sqimap_append_done ($imap_stream, $sent_folder);
1550 unset ($imap_deliver);
1552 global $passed_id, $mailbox, $action;
1553 ClearAttachments($composeMessage);
1554 if ($action == 'reply' ||
$action == 'reply_all') {
1555 sqimap_mailbox_select ($imap_stream, $mailbox);
1556 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1558 sqimap_logout($imap_stream);