6 * Copyright (c) 1999-2003 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');
36 /* --------------------- Get globals ------------------------------------- */
38 sqgetGlobalVar('key', $key, SQ_COOKIE
);
41 sqgetGlobalVar('username', $username, SQ_SESSION
);
42 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
43 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
44 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
46 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
47 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
49 /** SESSION/POST/GET VARS */
50 sqgetGlobalVar('smaction',$action);
51 sqgetGlobalVar('session',$session);
52 sqgetGlobalVar('mailbox',$mailbox);
53 if(!sqgetGlobalVar('identity',$identity)) {
56 if (sqgetGlobalVar('send_to',$send_to)) {
57 $send_to = decodeHeader($send_to);
59 if (sqgetGlobalVar('send_to_cc',$send_to_cc)) {
60 $send_to_cc = decodeHeader($send_to_cc);
62 if (sqgetGlobalVar('send_to_bcc',$send_to_bcc)) {
63 $send_to_bcc = decodeHeader($send_to_bcc);
65 if (sqgetGlobalVar('subject',$subject)) {
66 $subject = decodeHeader($subject);
68 if (sqgetGlobalVar('body',$body)) {
69 $body = decodeHeader($body);
71 sqgetGlobalVar('mailprio',$mailprio);
72 sqgetGlobalVar('request_mdn',$request_mdn);
73 sqgetGlobalVar('request_dr',$request_dr);
74 sqgetGlobalVar('html_addr_search',$html_addr_search);
75 sqgetGlobalVar('mail_sent',$mail_sent);
76 sqgetGlobalVar('passed_id',$passed_id);
77 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
78 sqgetGlobalVar('send',$send);
80 sqgetGlobalVar('attach',$attach);
82 sqgetGlobalVar('draft',$draft);
83 sqgetGlobalVar('draft_id',$draft_id);
84 sqgetGlobalVar('ent_num',$ent_num);
85 sqgetGlobalVar('saved_draft',$saved_draft);
86 sqgetGlobalVar('delete_draft',$delete_draft);
87 sqgetGlobalVar('startMessage',$startMessage);
90 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
91 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
92 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
93 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
94 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
95 sqgetGlobalVar('delete', $delete, SQ_POST
);
96 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
97 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
98 $html_addr_search_done = 'Use Addresses';
102 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
104 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
105 $location = get_location();
106 /* Identities (fetch only once) */
107 $idents = get_identities();
109 /* --------------------- Specific Functions ------------------------------ */
111 function replyAllString($header) {
112 global $include_self_reply_all, $idents;
115 * 1) Remove the addresses we'll be sending the message 'to'
117 $url_replytoall_avoid_addrs = '';
118 if (isset($header->replyto
)) {
119 $excl_ar = $header->getAddr_a('replyto');
122 * 2) Remove our identities from the CC list (they still can be in the
123 * TO list) only if $include_self_reply_all is turned off
125 if (!$include_self_reply_all) {
126 foreach($idents as $id) {
127 $excl_ar[strtolower(trim($id['email_address']))] = '';
132 * 3) get the addresses.
134 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
137 * 4) generate the string.
139 $url_replytoallcc = '';
140 foreach( $url_replytoall_ar as $email => $personal) {
142 // if personal name contains address separator then surround
143 // the personal name with double quotes.
144 if (strpos($personal,',') !== false) {
145 $personal = '"'.$personal.'"';
147 $url_replytoallcc .= ", $personal <$email>";
149 $url_replytoallcc .= ', '. $email;
152 $url_replytoallcc = substr($url_replytoallcc,2);
154 return $url_replytoallcc;
157 function getReplyCitation($orig_from, $orig_date) {
158 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
159 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
160 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
161 /* First, return an empty string when no citation style selected. */
162 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
166 /* Make sure our final value isn't an empty string. */
167 if ($orig_from == '') {
171 /* Otherwise, try to select the desired citation style. */
172 switch ($reply_citation_style) {
175 $end = ' ' . _("said") . ':';
178 $start = '<' . _("quote") . ' ' . _("who") . '="';
181 case 'date_time_author':
182 $start = 'On ' . getLongDateString($orig_date) . ', ';
183 $end = ' ' . _("said") . ':';
186 $start = $reply_citation_start .
187 ($reply_citation_start == '' ?
'' : ' ');
188 $end = $reply_citation_end;
194 /* Build and return the citation string. */
195 return ($start . $orig_from . $end . "\n");
198 function getforwardHeader($orig_header) {
201 $display = array( _("Subject") => strlen(_("Subject")),
202 _("From") => strlen(_("From")),
203 _("Date") => strlen(_("Date")),
204 _("To") => strlen(_("To")),
205 _("Cc") => strlen(_("Cc")) );
206 $maxsize = max($display);
207 $indent = str_pad('',$maxsize+
2);
208 foreach($display as $key => $val) {
209 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
211 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
212 $from = str_replace(' ',' ',$from);
213 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
214 $to = str_replace(' ',' ',$to);
215 $subject = decodeHeader($orig_header->subject
,false,false,true);
216 $subject = str_replace(' ',' ',$subject);
217 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
218 "\n". $display[_("Subject")] . $subject . "\n" .
219 $display[_("From")] . $from . "\n" .
220 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
221 $display[_("To")] . $to . "\n";
222 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
223 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
224 $cc = str_replace(' ',' ',$cc);
225 $bodyTop .= $display[_("Cc")] .$cc . "\n";
227 $bodyTop .= str_pad('', $editor_size -2 , '-') .
231 /* ----------------------------------------------------------------------- */
234 * If the session is expired during a post this restores the compose session
237 if (sqsession_is_registered('session_expired_post')) {
238 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
240 * extra check for username so we don't display previous post data from
241 * another user during this session.
243 if ($session_expired_post['username'] != $username) {
244 unset($session_expired_post);
245 sqsession_unregister('session_expired_post');
246 session_write_close();
248 foreach ($session_expired_post as $postvar => $val) {
255 $compose_messages = unserialize(urldecode($restoremessages));
256 sqsession_register($compose_messages,'compose_messages');
257 sqsession_register($composesession,'composesession');
261 $session_expired = true;
263 unset($session_expired_post);
264 sqsession_unregister('session_expired_post');
265 session_write_close();
266 if (!isset($mailbox)) {
269 if ($compose_new_win == '1') {
270 compose_Header($color, $mailbox);
272 displayPageHeader($color, $mailbox);
274 showInputForm($session, false);
277 if (!isset($composesession)) {
279 sqsession_register(0,'composesession');
282 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
283 sqsession_unregister('composesession');
284 $session = "$composesession" +
1;
285 $composesession = $session;
286 sqsession_register($composesession,'composesession');
288 if (!isset($compose_messages)) {
289 $compose_messages = array();
291 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
292 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
293 $composeMessage = new Message();
294 $rfc822_header = new Rfc822Header();
295 $composeMessage->rfc822_header
= $rfc822_header;
296 $composeMessage->reply_rfc822_header
= '';
297 $compose_messages[$session] = $composeMessage;
298 sqsession_register($compose_messages,'compose_messages');
300 $composeMessage=$compose_messages[$session];
303 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
309 * Set $default_charset to correspond with the user's selection
310 * of language interface.
313 $composeMessage=$compose_messages[$session];
314 if (! deliverMessage($composeMessage, true)) {
315 showInputForm($session);
318 unset($compose_messages[$session]);
319 $draft_message = _("Draft Email Saved");
320 /* If this is a resumed draft, then delete the original */
321 if(isset($delete_draft)) {
322 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
323 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
327 if ($compose_new_win == '1') {
328 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
332 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
333 "&startMessage=1¬e=".urlencode($draft_message));
341 if (isset($_FILES['attachfile']) &&
342 $_FILES['attachfile']['tmp_name'] &&
343 $_FILES['attachfile']['tmp_name'] != 'none') {
344 $AttachFailure = saveAttachedFiles($session);
346 if (checkInput(false) && !isset($AttachFailure)) {
347 if ($mailbox == "All Folders") {
348 /* We entered compose via the search results page */
349 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
351 $urlMailbox = urlencode (trim($mailbox));
352 if (! isset($passed_id)) {
356 * Set $default_charset to correspond with the user's selection
357 * of language interface.
361 * This is to change all newlines to \n
362 * We'll change them to \r\n later (in the sendMessage function)
364 $body = str_replace("\r\n", "\n", $body);
365 $body = str_replace("\r", "\n", $body);
368 * Rewrap $body so that no line is bigger than $editor_size
369 * This should only really kick in the sqWordWrap function
370 * if the browser doesn't support "VIRTUAL" as the wrap type.
372 $body = explode("\n", $body);
374 foreach ($body as $line) {
375 if( $line <> '-- ' ) {
376 $line = rtrim($line);
378 if (strlen($line) <= $editor_size +
1) {
379 $newBody .= $line . "\n";
381 sqWordWrap($line, $editor_size);
382 $newBody .= $line . "\n";
389 $composeMessage=$compose_messages[$session];
391 $Result = deliverMessage($composeMessage);
393 showInputForm($session);
396 unset($compose_messages[$session]);
397 if ( isset($delete_draft)) {
398 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
399 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
402 if ($compose_new_win == '1') {
404 Header("Location: $location/compose.php?mail_sent=yes");
407 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
408 "&startMessage=$startMessage&mail_sent=yes");
411 if ($compose_new_win == '1') {
412 compose_Header($color, $mailbox);
415 displayPageHeader($color, $mailbox);
417 if (isset($AttachFailure)) {
418 plain_error_message(_("Could not move/copy file. File not attached"),
422 showInputForm($session);
423 /* sqimap_logout($imapConnection); */
425 } elseif (isset($html_addr_search_done)) {
426 if ($compose_new_win == '1') {
427 compose_Header($color, $mailbox);
430 displayPageHeader($color, $mailbox);
433 if (isset($send_to_search) && is_array($send_to_search)) {
434 foreach ($send_to_search as $k => $v) {
435 if (substr($k, 0, 1) == 'T') {
441 elseif (substr($k, 0, 1) == 'C') {
447 elseif (substr($k, 0, 1) == 'B') {
449 $send_to_bcc .= ', ';
455 showInputForm($session);
456 } elseif (isset($html_addr_search)) {
457 if (isset($_FILES['attachfile']) &&
458 $_FILES['attachfile']['tmp_name'] &&
459 $_FILES['attachfile']['tmp_name'] != 'none') {
460 if(saveAttachedFiles($session)) {
461 plain_error_message(_("Could not move/copy file. File not attached"), $color);
465 * I am using an include so as to elminiate an extra unnecessary
466 * click. If you can think of a better way, please implement it.
468 include_once('./addrbook_search_html.php');
469 } elseif (isset($attach)) {
470 if (saveAttachedFiles($session)) {
471 plain_error_message(_("Could not move/copy file. File not attached"), $color);
473 if ($compose_new_win == '1') {
474 compose_Header($color, $mailbox);
477 displayPageHeader($color, $mailbox);
479 showInputForm($session);
481 elseif (isset($sigappend)) {
482 $signature = $idents[$identity]['signature'];
484 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
485 if ($compose_new_win == '1') {
486 compose_Header($color, $mailbox);
488 displayPageHeader($color, $mailbox);
490 showInputForm($session);
491 } elseif (isset($do_delete)) {
492 if ($compose_new_win == '1') {
493 compose_Header($color, $mailbox);
496 displayPageHeader($color, $mailbox);
499 if (isset($delete) && is_array($delete)) {
500 $composeMessage = $compose_messages[$session];
501 foreach($delete as $index) {
502 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
503 unlink ($attached_file);
504 unset ($composeMessage->entities
[$index]);
506 $new_entities = array();
507 foreach ($composeMessage->entities
as $entity) {
508 $new_entities[] = $entity;
510 $composeMessage->entities
= $new_entities;
511 $compose_messages[$session] = $composeMessage;
512 sqsession_register($compose_messages, 'compose_messages');
514 showInputForm($session);
517 * This handles the default case as well as the error case
518 * (they had the same code) --> if (isset($smtpErrors))
521 if ($compose_new_win == '1') {
522 compose_Header($color, $mailbox);
524 displayPageHeader($color, $mailbox);
529 if (!isset($passed_ent_id)) {
532 if (!isset($passed_id)) {
535 if (!isset($mailbox)) {
538 if (!isset($action)) {
542 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
544 /* in case the origin is not read_body.php */
545 if (isset($send_to)) {
546 $values['send_to'] = $send_to;
548 if (isset($send_to_cc)) {
549 $values['send_to_cc'] = $send_to_cc;
551 if (isset($send_to_bcc)) {
552 $values['send_to_bcc'] = $send_to_bcc;
554 if (isset($subject)) {
555 $values['subject'] = $subject;
557 showInputForm($session, $values);
562 /**************** Only function definitions go below *************/
564 function getforwardSubject($subject)
566 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
567 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
568 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
569 $subject = '[Fwd: ' . $subject . ']';
574 /* This function is used when not sending or adding attachments */
575 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
576 global $editor_size, $default_use_priority, $body, $idents,
577 $use_signature, $composesession, $data_dir, $username,
578 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
580 global $languages, $squirrelmail_language, $default_charset;
582 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
586 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
589 sqimap_mailbox_select($imapConnection, $mailbox);
590 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
593 if ($passed_ent_id) {
594 /* redefine the messsage in case of message/rfc822 */
595 $message = $message->getEntity($passed_ent_id);
596 /* message is an entity which contains the envelope and type0=message
597 * and type1=rfc822. The actual entities are childs from
598 * $message->entities[0]. That's where the encoding and is located
601 $entities = $message->entities
[0]->findDisplayEntity
602 (array(), $alt_order = array('text/plain'));
603 if (!count($entities)) {
604 $entities = $message->entities
[0]->findDisplayEntity
605 (array(), $alt_order = array('text/plain','html/plain'));
607 $orig_header = $message->rfc822_header
; /* here is the envelope located */
608 /* redefine the message for picking up the attachments */
609 $message = $message->entities
[0];
612 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
613 if (!count($entities)) {
614 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
616 $orig_header = $message->rfc822_header
;
619 $encoding = $message->header
->encoding
;
620 $type0 = $message->type0
;
621 $type1 = $message->type1
;
622 foreach ($entities as $ent) {
623 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
624 $body_part_entity = $message->getEntity($ent);
625 $bodypart = decodeBody($unencoded_bodypart,
626 $body_part_entity->header
->encoding
);
627 if ($type1 == 'html') {
628 $bodypart = str_replace("\n", ' ', $bodypart);
629 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
630 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
631 $bodypart = strip_tags($bodypart);
634 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
635 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
636 if (mb_detect_encoding($bodypart) != 'ASCII') {
637 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
641 if (isset($body_part_entity->header
->parameters
['charset'])) {
642 $actual = $body_part_entity->header
->parameters
['charset'];
644 $actual = 'us-ascii';
647 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
648 $bodypart = charset_decode($actual,$bodypart);
653 if ($default_use_priority) {
654 $mailprio = substr($orig_header->priority
,0,1);
661 //ClearAttachments($session);
664 $from_o = $orig_header->from
;
665 if (is_object($from_o)) {
666 $orig_from = $from_o->getAddress();
671 $identities = array();
672 if (count($idents) > 1) {
673 foreach($idents as $nr=>$data) {
674 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
675 if($enc_from_name == $orig_from) {
679 $identities[] = $enc_from_name;
682 $identity_match = $orig_header->findAddress($identities);
683 if ($identity_match) {
684 $identity = $identity_match;
686 // we need identiy here fore draft case #845290
687 // echo $identity."leer";
692 $use_signature = FALSE;
693 $composeMessage->rfc822_header
= $orig_header;
694 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
695 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
696 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
697 $send_from = $orig_header->getAddr_s('from');
698 $send_from_parts = new AddressStructure();
699 $send_from_parts = $orig_header->parseAddress($send_from);
700 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
701 $identities = get_identities();
702 if (count($identities) > 0) {
703 foreach($identities as $iddata) {
704 if ($send_from_add == $iddata['email_address']) {
705 $identity = $iddata['index'];
710 $subject = decodeHeader($orig_header->subject
,false,true,true);
711 // /* remember the references and in-reply-to headers in case of an reply */
712 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
713 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
714 $body_ary = explode("\n", $body);
715 $cnt = count($body_ary) ;
717 for ($i=0; $i < $cnt; $i++
) {
718 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
719 sqWordWrap($body_ary[$i], $editor_size );
720 $body .= $body_ary[$i] . "\n";
722 unset($body_ary[$i]);
725 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
727 case ('edit_as_new'):
728 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
729 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
730 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
731 $subject = decodeHeader($orig_header->subject
,false,true,true);
732 $mailprio = $orig_header->priority
;
734 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
739 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
740 $body = getforwardHeader($orig_header) . $body;
742 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
743 $body = "\n" . $body;
745 case ('forward_as_attachment'):
746 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
747 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
751 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
752 $send_to = $orig_header->getAddr_s('mail_followup_to');
754 $send_to_cc = replyAllString($orig_header);
755 $send_to_cc = decodeHeader($send_to_cc,false,true,true);
758 // skip this if send_to was already set right above here
760 $send_to = $orig_header->reply_to
;
761 if (is_array($send_to) && count($send_to)) {
762 $send_to = $orig_header->getAddr_s('reply_to');
763 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
764 $send_to = $orig_header->getAddr_s('reply_to');
766 $send_to = $orig_header->getAddr_s('from');
769 $send_to = decodeHeader($send_to,false,true,true);
770 $subject = decodeHeader($orig_header->subject
,false,true,true);
771 $subject = str_replace('"', "'", $subject);
772 $subject = trim($subject);
773 if (substr(strtolower($subject), 0, 3) != 're:') {
774 $subject = 'Re: ' . $subject;
776 /* this corrects some wrapping/quoting problems on replies */
777 $rewrap_body = explode("\n", $body);
778 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
779 sqUnWordWrap($body); // unwrap and then reset it?!
781 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
782 foreach ($rewrap_body as $line) {
783 if ($strip_sigs && substr($line,0,3) == '-- ') {
786 sqWordWrap($line, ($editor_size));
787 if (preg_match("/^(>+)/", $line, $matches)) {
789 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
791 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
794 $body = getReplyCitation($from , $orig_header->date
) . $body;
795 $composeMessage->reply_rfc822_header
= $orig_header;
801 $compose_messages[$session] = $composeMessage;
802 sqsession_register($compose_messages, 'compose_messages');
803 session_write_close();
804 sqimap_logout($imapConnection);
806 $ret = array( 'send_to' => $send_to,
807 'send_to_cc' => $send_to_cc,
808 'send_to_bcc' => $send_to_bcc,
809 'subject' => $subject,
810 'mailprio' => $mailprio,
812 'identity' => $identity );
815 } /* function newMail() */
817 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
818 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
819 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
820 if (!count($message->entities
) ||
821 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
822 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
823 switch ($message->type0
) {
825 if ($message->type1
== 'rfc822') {
826 $filename = $message->rfc822_header
->subject
;
827 if ($filename == "") {
828 $filename = "untitled-".$message->entity_id
;
832 $filename = $message->getFilename();
836 if (!$message->mime_header
) { /* temporary hack */
837 $message->mime_header
= $message->header
;
839 $filename = $message->getFilename();
842 $filename = str_replace(' ', ' ', decodeHeader($filename));
843 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
844 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
845 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
847 $localfilename = GenerateRandomString(32, '', 7);
848 $full_localfilename = "$hashed_attachment_dir/$localfilename";
849 while (file_exists($full_localfilename)) {
850 $localfilename = GenerateRandomString(32, '', 7);
851 $full_localfilename = "$hashed_attachment_dir/$localfilename";
853 $message->att_local_name
= $full_localfilename;
855 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
856 $full_localfilename);
858 /* Write Attachment to file */
859 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
860 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
861 $passed_id, $message->entity_id
),
862 $message->header
->encoding
));
866 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
867 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
870 return $composeMessage;
873 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
874 $passed_ent_id='', $imapConnection) {
875 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
876 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
877 if (!$passed_ent_id) {
878 $body_a = sqimap_run_command($imapConnection,
879 'FETCH '.$passed_id.' RFC822',
880 TRUE, $response, $readmessage,
883 $body_a = sqimap_run_command($imapConnection,
884 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
885 TRUE, $response, $readmessage, $uid_support);
886 $message = $message->parent
;
888 if ($response == 'OK') {
889 $subject = encodeHeader($message->rfc822_header
->subject
);
890 array_shift($body_a);
892 $body = implode('', $body_a) . "\r\n";
894 $localfilename = GenerateRandomString(32, 'FILE', 7);
895 $full_localfilename = "$hashed_attachment_dir/$localfilename";
897 $fp = fopen($full_localfilename, 'w');
900 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
901 $full_localfilename);
903 return $composeMessage;
906 function showInputForm ($session, $values=false) {
907 global $send_to, $send_to_cc, $body, $startMessage,
908 $passed_body, $color, $use_signature, $signature, $prefix_sig,
909 $editor_size, $attachments, $subject, $newmail,
910 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
911 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
912 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
913 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
914 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
915 $username, $compose_messages, $composesession, $default_charset;
917 $composeMessage = $compose_messages[$session];
920 $send_to = $values['send_to'];
921 $send_to_cc = $values['send_to_cc'];
922 $send_to_bcc = $values['send_to_bcc'];
923 $subject = $values['subject'];
924 $mailprio = $values['mailprio'];
925 $body = $values['body'];
926 $identity = (int) $values['identity'];
928 $send_to = decodeHeader($send_to);
929 $send_to_cc = decodeHeader($send_to_cc);
930 $send_to_bcc = decodeHeader($send_to_bcc);
933 if ($use_javascript_addr_book) {
934 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
935 'function open_abook() { ' . "\n" .
936 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
937 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
938 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
939 ' nwin.opener = document.windows;' . "\n" .
941 "// -->\n</SCRIPT>\n\n";
944 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
945 'enctype="multipart/form-data"';
946 do_hook('compose_form');
950 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
952 if ($action == 'draft') {
953 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
955 if (isset($delete_draft)) {
956 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
958 if (isset($session)) {
959 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
962 if (isset($passed_id)) {
963 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
966 if ($saved_draft == 'yes') {
967 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
969 if ($mail_sent == 'yes') {
970 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
972 echo '<table align="center" cellspacing="0" border="0">' . "\n";
973 if ($compose_new_win == '1') {
974 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
975 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
977 if ($location_of_buttons == 'top') {
978 showComposeButtonRow();
981 /* display select list for identities */
982 if (count($idents) > 1) {
983 echo ' <tr>' . "\n" .
984 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
985 _("From:") . '</td>' . "\n" .
986 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
987 ' <select name="identity">' . "\n" ;
988 foreach($idents as $id=>$data) {
989 echo '<option value="'.$id.'"';
990 if($id == $identity) {
993 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
997 echo '</select>' . "\n" .
1001 echo ' <tr>' . "\n" .
1002 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1003 _("To:") . '</TD>' . "\n" .
1004 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1005 ' <input type="text" name="send_to" value="' .
1006 $send_to . '" size="60" /><br />' . "\n" .
1010 html_tag( 'td', '', 'right', $color[4] ) .
1011 _("CC:") . '</td>' . "\n" .
1012 html_tag( 'td', '', 'left', $color[4] ) .
1013 ' <input type="text" name="send_to_cc" size="60" value="' .
1014 $send_to_cc . '" /><br />' . "\n" .
1018 html_tag( 'td', '', 'right', $color[4] ) .
1019 _("BCC:") . '</td>' . "\n" .
1020 html_tag( 'td', '', 'left', $color[4] ) .
1021 ' <input type="text" name="send_to_bcc" value="' .
1022 $send_to_bcc . '" size="60" /><br />' . "\n" .
1026 html_tag( 'td', '', 'right', $color[4] ) .
1027 _("Subject:") . '</td>' . "\n" .
1028 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1029 echo ' <input type="text" name="subject" size="60" value="' .
1030 $subject . '" />' . "\n" .
1034 if ($location_of_buttons == 'between') {
1035 showComposeButtonRow();
1038 /* why this distinction? */
1039 if ($compose_new_win == '1') {
1040 echo ' <TR>' . "\n" .
1041 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1042 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1043 $editor_size . '" WRAP="VIRTUAL">';
1046 echo ' <TR>' . "\n" .
1047 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1048 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1049 $editor_size . '" WRAP="VIRTUAL">';
1052 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1053 $signature = $idents[$identity]['signature'];
1055 if ($sig_first == '1') {
1056 if ($default_charset == 'iso-2022-jp') {
1057 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1059 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1061 echo "\n\n".decodeHeader($body,false,false);
1064 echo "\n\n".decodeHeader($body,false,false);
1065 if ($default_charset == 'iso-2022-jp') {
1066 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1068 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1073 echo decodeHeader($body,false,false);
1075 echo '</textarea><br />' . "\n" .
1080 if ($location_of_buttons == 'bottom') {
1081 showComposeButtonRow();
1083 echo ' <tr>' . "\n" .
1084 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1085 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1086 ' <br /><br />' . "\n" .
1091 /* This code is for attachments */
1092 if ((bool) ini_get('file_uploads')) {
1094 /* Calculate the max size for an uploaded file.
1095 * This is advisory for the user because we can't actually prevent
1096 * people to upload too large files. */
1098 /* php.ini vars which influence the max for uploads */
1099 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1100 foreach($configvars as $var) {
1101 /* skip 0 or empty values */
1102 if( $size = getByteSize(ini_get($var)) ) {
1107 if(count($sizes) > 0) {
1108 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1112 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1113 echo ' <tr>' . "\n" .
1114 ' <td colspan="2">' . "\n" .
1115 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1116 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1119 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1120 ' border="0">' . "\n" .
1122 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1123 _("Attach:") . '</td>' . "\n" .
1124 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1125 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1126 ' <input type="submit" name="attach"' .
1127 ' value="' . _("Add") .'">' . "\n" .
1134 if ($composeMessage->entities
) {
1135 foreach ($composeMessage->entities
as $key => $attachment) {
1136 $attached_file = $attachment->att_local_name
;
1137 if ($attachment->att_local_name ||
$attachment->body_part
) {
1138 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1139 $type = $attachment->mime_header
->type0
.'/'.
1140 $attachment->mime_header
->type1
;
1142 $s_a[] = '<table bgcolor="'.$color[0].
1143 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1144 $key . "\"></td><td>\n" . $attached_filename .
1145 '</td><td>-</td><td> ' . $type . '</td><td>('.
1146 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1151 foreach ($s_a as $s) {
1152 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1154 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1155 _("Delete selected attachments") . "\">\n" .
1158 echo ' </table>' . "\n" .
1161 ' </TABLE>' . "\n" .
1164 } // End of file_uploads if-block
1165 /* End of attachment code */
1166 if ($compose_new_win == '1') {
1167 echo '</TABLE>'."\n";
1170 echo '</TABLE>' . "\n" .
1171 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1172 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1173 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1176 store the complete ComposeMessages array in a hidden input value
1177 so we can restore them in case of a session timeout.
1179 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1180 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1181 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1182 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1184 if (!(bool) ini_get('file_uploads')) {
1185 /* File uploads are off, so we didn't show that part of the form.
1186 To avoid bogus bug reports, tell the user why. */
1187 echo 'Because PHP file uploads are turned off, you can not attach files ';
1188 echo "to this message. Please see your system administrator for details.\r\n";
1191 do_hook('compose_bottom');
1192 echo '</BODY></HTML>' . "\n";
1196 function showComposeButtonRow() {
1197 global $use_javascript_addr_book, $save_as_draft,
1198 $default_use_priority, $mailprio, $default_use_mdn,
1199 $request_mdn, $request_dr,
1200 $data_dir, $username;
1202 echo ' <TR>' . "\n" .
1203 ' <TD></TD>' . "\n" .
1205 if ($default_use_priority) {
1206 if(!isset($mailprio)) {
1209 echo ' ' . _("Priority") .': <select name="mailprio">'.
1210 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1211 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1212 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1215 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1216 if ($default_use_mdn) {
1217 if ($mdn_user_support) {
1218 echo ' ' . _("Receipt") .': '.
1219 '<input type="checkbox" name="request_mdn" value=1'.
1220 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1221 ' <input type="checkbox" name="request_dr" value=1'.
1222 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1226 echo ' </TD>' . "\n" .
1229 ' <TD></TD>' . "\n" .
1231 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1232 if ($use_javascript_addr_book) {
1233 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1234 " <input type=button value=\\\""._("Addresses").
1235 "\\\" onclick='javascript:open_abook();'>\");".
1236 " // --></SCRIPT><NOSCRIPT>\n".
1237 " <input type=submit name=\"html_addr_search\" value=\"".
1238 _("Addresses")."\">".
1241 echo ' <input type=submit name="html_addr_search" value="'.
1242 _("Addresses").'">' . "\n";
1245 if ($save_as_draft) {
1246 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1249 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1250 do_hook('compose_button_row');
1252 echo ' </TD>' . "\n" .
1256 function checkInput ($show) {
1258 * I implemented the $show variable because the error messages
1259 * were getting sent before the page header. So, I check once
1260 * using $show=false, and then when i'm ready to display the error
1261 * message, show=true
1263 global $body, $send_to, $send_to_bcc, $subject, $color;
1265 if ($send_to == '' && $send_to_bcc == '') {
1267 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1272 } /* function checkInput() */
1275 /* True if FAILURE */
1276 function saveAttachedFiles($session) {
1277 global $_FILES, $attachment_dir, $attachments, $username,
1278 $data_dir, $compose_messages;
1280 /* get out of here if no file was attached at all */
1281 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1285 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1286 $localfilename = GenerateRandomString(32, '', 7);
1287 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1288 while (file_exists($full_localfilename)) {
1289 $localfilename = GenerateRandomString(32, '', 7);
1290 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1293 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1294 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1295 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1296 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1300 $message = $compose_messages[$session];
1301 $type = strtolower($_FILES['attachfile']['type']);
1302 $name = $_FILES['attachfile']['name'];
1303 $message->initAttachment($type, $name, $full_localfilename);
1304 $compose_messages[$session] = $message;
1305 sqsession_register($compose_messages , 'compose_messages');
1308 function ClearAttachments($composeMessage) {
1309 if ($composeMessage->att_local_name
) {
1310 $attached_file = $composeMessage->att_local_name
;
1311 if (file_exists($attached_file)) {
1312 unlink($attached_file);
1315 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1316 ClearAttachments($composeMessage->entities
[$i]);
1320 /* parse values like 8M and 2k into bytes */
1321 function getByteSize($ini_size) {
1327 $ini_size = trim($ini_size);
1329 // if there's some kind of letter at the end of the string we need to multiply.
1330 if(!is_numeric(substr($ini_size, -1))) {
1332 switch(strtoupper(substr($ini_size, -1))) {
1334 $bytesize = 1073741824;
1337 $bytesize = 1048576;
1344 return ($bytesize * (int)substr($ini_size, 0, -1));
1351 /* temporary function to make use of the deliver class.
1352 In the future the responsable backend should be automaticly loaded
1353 and conf.pl should show a list of available backends.
1354 The message also should be constructed by the message class.
1357 function deliverMessage($composeMessage, $draft=false) {
1358 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1359 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1360 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1361 $domain, $action, $default_move_to_sent, $move_to_sent;
1362 global $imapServerAddress, $imapPort, $sent_folder, $key;
1364 /* some browsers replace <space> by nonbreaking spaces
1365 by replacing them back to spaces addressparsing works */
1366 /* FIXME: How to handle in case of other charsets where "\240"
1367 is not a non breaking space ??? */
1368 /* THEFIX: browsers don't replace space with nbsp. SM replaces
1369 space with nbsp when decodes headers. If problem still happens,
1370 use cleanup_nbsp() */
1372 // $send_to = str_replace("\240",' ',$send_to);
1373 // $send_to_cc = str_replace("\240",' ',$send_to_cc);
1374 // $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1376 $rfc822_header = $composeMessage->rfc822_header
;
1378 $abook = addressbook_init(false, true);
1379 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1380 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1381 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1382 $rfc822_header->priority
= $mailprio;
1383 $rfc822_header->subject
= $subject;
1384 $special_encoding='';
1385 if (strtolower($default_charset) == 'iso-2022-jp') {
1386 if (mb_detect_encoding($body) == 'ASCII') {
1387 $special_encoding = '8bit';
1389 $body = mb_convert_encoding($body, 'JIS');
1390 $special_encoding = '7bit';
1393 $composeMessage->setBody($body);
1395 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1396 $popuser = $usernamedata[1];
1397 $domain = $usernamedata[2];
1398 unset($usernamedata);
1400 $popuser = $username;
1403 $from_mail = $idents[$identity]['email_address'];
1404 $full_name = $idents[$identity]['full_name'];
1405 $reply_to = $idents[$identity]['reply_to'];
1407 $from_mail = "$popuser@$domain";
1409 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1411 $from = $rfc822_header->from
[0];
1412 if (!$from->host
) $from->host
= $domain;
1413 $full_name_encoded = encodeHeader($full_name);
1414 if ($full_name_encoded != $full_name) {
1415 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1417 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1419 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1422 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1424 /* Receipt: On Read */
1425 if (isset($request_mdn) && $request_mdn) {
1426 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1428 /* Receipt: On Delivery */
1429 if (isset($request_dr) && $request_dr) {
1430 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1432 /* multipart messages */
1433 if (count($composeMessage->entities
)) {
1434 $message_body = new Message();
1435 $message_body->body_part
= $composeMessage->body_part
;
1436 $composeMessage->body_part
= '';
1437 $mime_header = new MessageHeader
;
1438 $mime_header->type0
= 'text';
1439 $mime_header->type1
= 'plain';
1440 if ($special_encoding) {
1441 $mime_header->encoding
= $special_encoding;
1443 $mime_header->encoding
= '8bit';
1445 if ($default_charset) {
1446 $mime_header->parameters
['charset'] = $default_charset;
1448 $message_body->mime_header
= $mime_header;
1449 array_unshift($composeMessage->entities
, $message_body);
1450 $content_type = new ContentType('multipart/mixed');
1452 $content_type = new ContentType('text/plain');
1453 if ($special_encoding) {
1454 $rfc822_header->encoding
= $special_encoding;
1456 $rfc822_header->encoding
= '8bit';
1458 if ($default_charset) {
1459 $content_type->properties
['charset']=$default_charset;
1463 $rfc822_header->content_type
= $content_type;
1464 $composeMessage->rfc822_header
= $rfc822_header;
1466 /* Here you can modify the message structure just before we hand
1467 it over to deliver */
1468 $hookReturn = do_hook('compose_send', $composeMessage);
1469 /* Get any changes made by plugins to $composeMessage. */
1470 if ( is_object($hookReturn[1]) ) {
1471 $composeMessage = $hookReturn[1];
1474 if (!$useSendmail && !$draft) {
1475 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1476 $deliver = new Deliver_SMTP();
1477 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1479 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1480 get_smtp_user($user, $pass);
1481 $stream = $deliver->initStream($composeMessage,$domain,0,
1482 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1483 } elseif (!$draft) {
1484 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1485 global $sendmail_path;
1486 $deliver = new Deliver_SendMail();
1487 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1489 global $draft_folder;
1490 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1491 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1493 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1494 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1495 $imap_deliver = new Deliver_IMAP();
1496 $length = $imap_deliver->mail($composeMessage);
1497 sqimap_append ($imap_stream, $draft_folder, $length);
1498 $imap_deliver->mail($composeMessage, $imap_stream);
1499 sqimap_append_done ($imap_stream, $draft_folder);
1500 sqimap_logout($imap_stream);
1501 unset ($imap_deliver);
1504 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1505 plain_error_message($msg, $color);
1511 $length = $deliver->mail($composeMessage, $stream);
1512 $succes = $deliver->finalizeStream($stream);
1515 $msg = $deliver->dlv_msg
. '<br>' .
1516 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1517 $deliver->dlv_server_msg
;
1518 plain_error_message($msg, $color);
1521 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1522 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1524 /* Move to sent code */
1525 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1526 $svr_allow_sent = true;
1528 $svr_allow_sent = false;
1531 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1532 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1538 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1539 $lcl_allow_sent = true;
1541 $lcl_allow_sent = false;
1544 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1545 global $passed_id, $mailbox, $action;
1546 if ($action == 'reply' ||
$action == 'reply_all') {
1547 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1548 if ($save_reply_with_orig) {
1549 $sent_folder = $mailbox;
1552 sqimap_append ($imap_stream, $sent_folder, $length);
1553 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1554 $imap_deliver = new Deliver_IMAP();
1555 $imap_deliver->mail($composeMessage, $imap_stream);
1556 sqimap_append_done ($imap_stream, $sent_folder);
1557 unset ($imap_deliver);
1559 global $passed_id, $mailbox, $action;
1560 ClearAttachments($composeMessage);
1561 if ($action == 'reply' ||
$action == 'reply_all') {
1562 sqimap_mailbox_select ($imap_stream, $mailbox);
1563 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1565 sqimap_logout($imap_stream);