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 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
);
94 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
95 $location = get_location();
96 /* Identities (fetch only once) */
97 $idents = get_identities();
99 /* --------------------- Specific Functions ------------------------------ */
101 function replyAllString($header) {
102 global $include_self_reply_all, $idents;
105 * 1) Remove the addresses we'll be sending the message 'to'
107 $url_replytoall_avoid_addrs = '';
108 if (isset($header->replyto
)) {
109 $excl_ar = $header->getAddr_a('replyto');
112 * 2) Remove our identities from the CC list (they still can be in the
113 * TO list) only if $include_self_reply_all is turned off
115 if (!$include_self_reply_all) {
116 foreach($idents as $id) {
117 $excl_ar[strtolower(trim($id['email_address']))] = '';
122 * 3) get the addresses.
124 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
127 * 4) generate the string.
129 $url_replytoallcc = '';
130 foreach( $url_replytoall_ar as $email => $personal) {
132 // if personal name contains address separator then surround
133 // the personal name with double quotes.
134 if (strpos($personal,',') !== false) {
135 $personal = '"'.$personal.'"';
137 $url_replytoallcc .= ", $personal <$email>";
139 $url_replytoallcc .= ', '. $email;
142 $url_replytoallcc = substr($url_replytoallcc,2);
144 return $url_replytoallcc;
147 function getReplyCitation($orig_from, $orig_date) {
148 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
149 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
150 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
151 /* First, return an empty string when no citation style selected. */
152 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
156 /* Make sure our final value isn't an empty string. */
157 if ($orig_from == '') {
161 /* Otherwise, try to select the desired citation style. */
162 switch ($reply_citation_style) {
165 $end = ' ' . _("said") . ':';
168 $start = '<' . _("quote") . ' ' . _("who") . '="';
171 case 'date_time_author':
172 $start = 'On ' . getLongDateString($orig_date) . ', ';
173 $end = ' ' . _("said") . ':';
176 $start = $reply_citation_start .
177 ($reply_citation_start == '' ?
'' : ' ');
178 $end = $reply_citation_end;
184 /* Build and return the citation string. */
185 return ($start . $orig_from . $end . "\n");
188 function getforwardHeader($orig_header) {
191 $display = array( _("Subject") => strlen(_("Subject")),
192 _("From") => strlen(_("From")),
193 _("Date") => strlen(_("Date")),
194 _("To") => strlen(_("To")),
195 _("Cc") => strlen(_("Cc")) );
196 $maxsize = max($display);
197 $indent = str_pad('',$maxsize+
2);
198 foreach($display as $key => $val) {
199 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
201 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
202 $from = str_replace(' ',' ',$from);
203 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
204 $to = str_replace(' ',' ',$to);
205 $subject = decodeHeader($orig_header->subject
,false,false,true);
206 $subject = str_replace(' ',' ',$subject);
207 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
208 "\n". $display[_("Subject")] . $subject . "\n" .
209 $display[_("From")] . $from . "\n" .
210 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
211 $display[_("To")] . $to . "\n";
212 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
213 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
214 $cc = str_replace(' ',' ',$cc);
215 $bodyTop .= $display[_("Cc")] .$cc . "\n";
217 $bodyTop .= str_pad('', $editor_size -2 , '-') .
221 /* ----------------------------------------------------------------------- */
224 * If the session is expired during a post this restores the compose session
227 if (sqsession_is_registered('session_expired_post')) {
228 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
230 * extra check for username so we don't display previous post data from
231 * another user during this session.
233 if ($session_expired_post['username'] != $username) {
234 unset($session_expired_post);
235 sqsession_unregister('session_expired_post');
236 session_write_close();
238 foreach ($session_expired_post as $postvar => $val) {
245 $compose_messages = unserialize(urldecode($restoremessages));
246 sqsession_register($compose_messages,'compose_messages');
247 sqsession_register($composesession,'composesession');
251 $session_expired = true;
253 unset($session_expired_post);
254 sqsession_unregister('session_expired_post');
255 session_write_close();
256 if (!isset($mailbox)) {
259 if ($compose_new_win == '1') {
260 compose_Header($color, $mailbox);
262 displayPageHeader($color, $mailbox);
264 showInputForm($session, false);
267 if (!isset($composesession)) {
269 sqsession_register(0,'composesession');
272 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
273 sqsession_unregister('composesession');
274 $session = "$composesession" +
1;
275 $composesession = $session;
276 sqsession_register($composesession,'composesession');
278 if (!isset($compose_messages)) {
279 $compose_messages = array();
281 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
282 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
283 $composeMessage = new Message();
284 $rfc822_header = new Rfc822Header();
285 $composeMessage->rfc822_header
= $rfc822_header;
286 $composeMessage->reply_rfc822_header
= '';
287 $compose_messages[$session] = $composeMessage;
288 sqsession_register($compose_messages,'compose_messages');
290 $composeMessage=$compose_messages[$session];
293 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
299 * Set $default_charset to correspond with the user's selection
300 * of language interface.
303 $composeMessage=$compose_messages[$session];
304 if (! deliverMessage($composeMessage, true)) {
305 showInputForm($session);
308 unset($compose_messages[$session]);
309 $draft_message = _("Draft Email Saved");
310 /* If this is a resumed draft, then delete the original */
311 if(isset($delete_draft)) {
312 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
313 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
317 if ($compose_new_win == '1') {
318 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
322 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
323 "&startMessage=1¬e=".urlencode($draft_message));
331 if (isset($_FILES['attachfile']) &&
332 $_FILES['attachfile']['tmp_name'] &&
333 $_FILES['attachfile']['tmp_name'] != 'none') {
334 $AttachFailure = saveAttachedFiles($session);
336 if (checkInput(false) && !isset($AttachFailure)) {
337 if ($mailbox == "All Folders") {
338 /* We entered compose via the search results page */
339 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
341 $urlMailbox = urlencode (trim($mailbox));
342 if (! isset($passed_id)) {
346 * Set $default_charset to correspond with the user's selection
347 * of language interface.
351 * This is to change all newlines to \n
352 * We'll change them to \r\n later (in the sendMessage function)
354 $body = str_replace("\r\n", "\n", $body);
355 $body = str_replace("\r", "\n", $body);
358 * Rewrap $body so that no line is bigger than $editor_size
359 * This should only really kick in the sqWordWrap function
360 * if the browser doesn't support "VIRTUAL" as the wrap type.
362 $body = explode("\n", $body);
364 foreach ($body as $line) {
365 if( $line <> '-- ' ) {
366 $line = rtrim($line);
368 if (strlen($line) <= $editor_size +
1) {
369 $newBody .= $line . "\n";
371 sqWordWrap($line, $editor_size);
372 $newBody .= $line . "\n";
379 $composeMessage=$compose_messages[$session];
381 $Result = deliverMessage($composeMessage);
383 showInputForm($session);
386 unset($compose_messages[$session]);
387 if ( isset($delete_draft)) {
388 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
389 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
392 if ($compose_new_win == '1') {
394 Header("Location: $location/compose.php?mail_sent=yes");
397 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
398 "&startMessage=$startMessage&mail_sent=yes");
401 if ($compose_new_win == '1') {
402 compose_Header($color, $mailbox);
405 displayPageHeader($color, $mailbox);
407 if (isset($AttachFailure)) {
408 plain_error_message(_("Could not move/copy file. File not attached"),
412 showInputForm($session);
413 /* sqimap_logout($imapConnection); */
415 } elseif (isset($html_addr_search_done)) {
416 if ($compose_new_win == '1') {
417 compose_Header($color, $mailbox);
420 displayPageHeader($color, $mailbox);
423 if (isset($send_to_search) && is_array($send_to_search)) {
424 foreach ($send_to_search as $k => $v) {
425 if (substr($k, 0, 1) == 'T') {
431 elseif (substr($k, 0, 1) == 'C') {
437 elseif (substr($k, 0, 1) == 'B') {
439 $send_to_bcc .= ', ';
445 showInputForm($session);
446 } elseif (isset($html_addr_search)) {
447 if (isset($_FILES['attachfile']) &&
448 $_FILES['attachfile']['tmp_name'] &&
449 $_FILES['attachfile']['tmp_name'] != 'none') {
450 if(saveAttachedFiles($session)) {
451 plain_error_message(_("Could not move/copy file. File not attached"), $color);
455 * I am using an include so as to elminiate an extra unnecessary
456 * click. If you can think of a better way, please implement it.
458 include_once('./addrbook_search_html.php');
459 } elseif (isset($attach)) {
460 if (saveAttachedFiles($session)) {
461 plain_error_message(_("Could not move/copy file. File not attached"), $color);
463 if ($compose_new_win == '1') {
464 compose_Header($color, $mailbox);
467 displayPageHeader($color, $mailbox);
469 showInputForm($session);
471 elseif (isset($sigappend)) {
472 $signature = $idents[$identity]['signature'];
474 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
475 if ($compose_new_win == '1') {
476 compose_Header($color, $mailbox);
478 displayPageHeader($color, $mailbox);
480 showInputForm($session);
481 } elseif (isset($do_delete)) {
482 if ($compose_new_win == '1') {
483 compose_Header($color, $mailbox);
486 displayPageHeader($color, $mailbox);
489 if (isset($delete) && is_array($delete)) {
490 $composeMessage = $compose_messages[$session];
491 foreach($delete as $index) {
492 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
493 unlink ($attached_file);
494 unset ($composeMessage->entities
[$index]);
496 $new_entities = array();
497 foreach ($composeMessage->entities
as $entity) {
498 $new_entities[] = $entity;
500 $composeMessage->entities
= $new_entities;
501 $compose_messages[$session] = $composeMessage;
502 sqsession_register($compose_messages, 'compose_messages');
504 showInputForm($session);
507 * This handles the default case as well as the error case
508 * (they had the same code) --> if (isset($smtpErrors))
511 if ($compose_new_win == '1') {
512 compose_Header($color, $mailbox);
514 displayPageHeader($color, $mailbox);
519 if (!isset($passed_ent_id)) {
522 if (!isset($passed_id)) {
525 if (!isset($mailbox)) {
528 if (!isset($action)) {
532 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
534 /* in case the origin is not read_body.php */
535 if (isset($send_to)) {
536 $values['send_to'] = $send_to;
538 if (isset($send_to_cc)) {
539 $values['send_to_cc'] = $send_to_cc;
541 if (isset($send_to_bcc)) {
542 $values['send_to_bcc'] = $send_to_bcc;
544 if (isset($subject)) {
545 $values['subject'] = $subject;
547 showInputForm($session, $values);
552 /**************** Only function definitions go below *************/
554 function getforwardSubject($subject)
556 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
557 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
558 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
559 $subject = '[Fwd: ' . $subject . ']';
564 /* This function is used when not sending or adding attachments */
565 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
566 global $editor_size, $default_use_priority, $body, $idents,
567 $use_signature, $composesession, $data_dir, $username,
568 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
570 global $languages, $squirrelmail_language, $default_charset;
572 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
576 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
579 sqimap_mailbox_select($imapConnection, $mailbox);
580 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
583 if ($passed_ent_id) {
584 /* redefine the messsage in case of message/rfc822 */
585 $message = $message->getEntity($passed_ent_id);
586 /* message is an entity which contains the envelope and type0=message
587 * and type1=rfc822. The actual entities are childs from
588 * $message->entities[0]. That's where the encoding and is located
591 $entities = $message->entities
[0]->findDisplayEntity
592 (array(), $alt_order = array('text/plain'));
593 if (!count($entities)) {
594 $entities = $message->entities
[0]->findDisplayEntity
595 (array(), $alt_order = array('text/plain','html/plain'));
597 $orig_header = $message->rfc822_header
; /* here is the envelope located */
598 /* redefine the message for picking up the attachments */
599 $message = $message->entities
[0];
602 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
603 if (!count($entities)) {
604 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
606 $orig_header = $message->rfc822_header
;
609 $encoding = $message->header
->encoding
;
610 $type0 = $message->type0
;
611 $type1 = $message->type1
;
612 foreach ($entities as $ent) {
613 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
614 $body_part_entity = $message->getEntity($ent);
615 $bodypart = decodeBody($unencoded_bodypart,
616 $body_part_entity->header
->encoding
);
617 if ($type1 == 'html') {
618 $bodypart = str_replace("\n", ' ', $bodypart);
619 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
620 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
621 $bodypart = strip_tags($bodypart);
624 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
625 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
626 if (mb_detect_encoding($bodypart) != 'ASCII') {
627 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
631 if (isset($body_part_entity->header
->parameters
['charset'])) {
632 $actual = $body_part_entity->header
->parameters
['charset'];
634 $actual = 'us-ascii';
637 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
638 $bodypart = charset_decode($actual,$bodypart);
643 if ($default_use_priority) {
644 $mailprio = substr($orig_header->priority
,0,1);
651 //ClearAttachments($session);
654 $from_o = $orig_header->from
;
655 if (is_object($from_o)) {
656 $orig_from = $from_o->getAddress();
661 $identities = array();
662 if (count($idents) > 1) {
663 foreach($idents as $nr=>$data) {
664 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
665 if($enc_from_name == $orig_from) {
669 $identities[] = $enc_from_name;
672 $identity_match = $orig_header->findAddress($identities);
673 if ($identity_match) {
674 $identity = $identity_match;
676 // we need identiy here fore draft case #845290
677 // echo $identity."leer";
682 $use_signature = FALSE;
683 $composeMessage->rfc822_header
= $orig_header;
684 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
685 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
686 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
687 $send_from = $orig_header->getAddr_s('from');
688 $send_from_parts = new AddressStructure();
689 $send_from_parts = $orig_header->parseAddress($send_from);
690 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
691 $identities = get_identities();
692 if (count($identities) > 0) {
693 foreach($identities as $iddata) {
694 if ($send_from_add == $iddata['email_address']) {
695 $identity = $iddata['index'];
700 $subject = decodeHeader($orig_header->subject
,false,true,true);
701 // /* remember the references and in-reply-to headers in case of an reply */
702 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
703 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
704 $body_ary = explode("\n", $body);
705 $cnt = count($body_ary) ;
707 for ($i=0; $i < $cnt; $i++
) {
708 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
709 sqWordWrap($body_ary[$i], $editor_size );
710 $body .= $body_ary[$i] . "\n";
712 unset($body_ary[$i]);
715 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
717 case ('edit_as_new'):
718 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
719 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
720 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
721 $subject = decodeHeader($orig_header->subject
,false,true,true);
722 $mailprio = $orig_header->priority
;
724 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
729 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
730 $body = getforwardHeader($orig_header) . $body;
732 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
733 $body = "\n" . $body;
735 case ('forward_as_attachment'):
736 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
737 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
741 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
742 $send_to = $orig_header->getAddr_s('mail_followup_to');
744 $send_to_cc = replyAllString($orig_header);
745 $send_to_cc = decodeHeader($send_to_cc,false,true,true);
748 // skip this if send_to was already set right above here
750 $send_to = $orig_header->reply_to
;
751 if (is_array($send_to) && count($send_to)) {
752 $send_to = $orig_header->getAddr_s('reply_to');
753 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
754 $send_to = $orig_header->getAddr_s('reply_to');
756 $send_to = $orig_header->getAddr_s('from');
759 $send_to = decodeHeader($send_to,false,true,true);
760 $subject = decodeHeader($orig_header->subject
,false,true,true);
761 $subject = str_replace('"', "'", $subject);
762 $subject = trim($subject);
763 if (substr(strtolower($subject), 0, 3) != 're:') {
764 $subject = 'Re: ' . $subject;
766 /* this corrects some wrapping/quoting problems on replies */
767 $rewrap_body = explode("\n", $body);
768 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
769 sqUnWordWrap($body); // unwrap and then reset it?!
771 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
772 foreach ($rewrap_body as $line) {
773 if ($strip_sigs && substr($line,0,3) == '-- ') {
776 sqWordWrap($line, ($editor_size));
777 if (preg_match("/^(>+)/", $line, $matches)) {
779 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
781 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
784 $body = getReplyCitation($from , $orig_header->date
) . $body;
785 $composeMessage->reply_rfc822_header
= $orig_header;
791 $compose_messages[$session] = $composeMessage;
792 sqsession_register($compose_messages, 'compose_messages');
793 session_write_close();
794 sqimap_logout($imapConnection);
796 $ret = array( 'send_to' => $send_to,
797 'send_to_cc' => $send_to_cc,
798 'send_to_bcc' => $send_to_bcc,
799 'subject' => $subject,
800 'mailprio' => $mailprio,
802 'identity' => $identity );
805 } /* function newMail() */
807 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
808 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
809 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
810 if (!count($message->entities
) ||
811 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
812 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
813 switch ($message->type0
) {
815 if ($message->type1
== 'rfc822') {
816 $filename = $message->rfc822_header
->subject
;
817 if ($filename == "") {
818 $filename = "untitled-".$message->entity_id
;
822 $filename = $message->getFilename();
826 if (!$message->mime_header
) { /* temporary hack */
827 $message->mime_header
= $message->header
;
829 $filename = $message->getFilename();
832 $filename = str_replace(' ', ' ', decodeHeader($filename));
833 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
834 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
835 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
837 $localfilename = GenerateRandomString(32, '', 7);
838 $full_localfilename = "$hashed_attachment_dir/$localfilename";
839 while (file_exists($full_localfilename)) {
840 $localfilename = GenerateRandomString(32, '', 7);
841 $full_localfilename = "$hashed_attachment_dir/$localfilename";
843 $message->att_local_name
= $full_localfilename;
845 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
846 $full_localfilename);
848 /* Write Attachment to file */
849 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
850 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
851 $passed_id, $message->entity_id
),
852 $message->header
->encoding
));
856 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
857 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
860 return $composeMessage;
863 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
864 $passed_ent_id='', $imapConnection) {
865 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
866 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
867 if (!$passed_ent_id) {
868 $body_a = sqimap_run_command($imapConnection,
869 'FETCH '.$passed_id.' RFC822',
870 TRUE, $response, $readmessage,
873 $body_a = sqimap_run_command($imapConnection,
874 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
875 TRUE, $response, $readmessage, $uid_support);
876 $message = $message->parent
;
878 if ($response == 'OK') {
879 $subject = encodeHeader($message->rfc822_header
->subject
);
880 array_shift($body_a);
882 $body = implode('', $body_a) . "\r\n";
884 $localfilename = GenerateRandomString(32, 'FILE', 7);
885 $full_localfilename = "$hashed_attachment_dir/$localfilename";
887 $fp = fopen($full_localfilename, 'w');
890 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
891 $full_localfilename);
893 return $composeMessage;
896 function showInputForm ($session, $values=false) {
897 global $send_to, $send_to_cc, $body, $startMessage,
898 $passed_body, $color, $use_signature, $signature, $prefix_sig,
899 $editor_size, $editor_height, $attachments, $subject, $newmail,
900 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
901 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
902 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
903 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
904 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
905 $username, $compose_messages, $composesession, $default_charset;
907 $composeMessage = $compose_messages[$session];
910 $send_to = $values['send_to'];
911 $send_to_cc = $values['send_to_cc'];
912 $send_to_bcc = $values['send_to_bcc'];
913 $subject = $values['subject'];
914 $mailprio = $values['mailprio'];
915 $body = $values['body'];
916 $identity = (int) $values['identity'];
918 $send_to = decodeHeader($send_to);
919 $send_to_cc = decodeHeader($send_to_cc);
920 $send_to_bcc = decodeHeader($send_to_bcc);
923 if ($use_javascript_addr_book) {
924 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
925 'function open_abook() { ' . "\n" .
926 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
927 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
928 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
929 ' nwin.opener = document.windows;' . "\n" .
931 "// -->\n</SCRIPT>\n\n";
934 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
935 'enctype="multipart/form-data"';
936 do_hook('compose_form');
940 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
942 if ($action == 'draft') {
943 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
945 if (isset($delete_draft)) {
946 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
948 if (isset($session)) {
949 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
952 if (isset($passed_id)) {
953 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
956 if ($saved_draft == 'yes') {
957 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
959 if ($mail_sent == 'yes') {
960 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
962 echo '<table align="center" cellspacing="0" border="0">' . "\n";
963 if ($compose_new_win == '1') {
964 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
965 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
967 if ($location_of_buttons == 'top') {
968 showComposeButtonRow();
971 /* display select list for identities */
972 if (count($idents) > 1) {
973 echo ' <tr>' . "\n" .
974 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
975 _("From:") . '</td>' . "\n" .
976 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
977 ' <select name="identity">' . "\n" ;
978 foreach($idents as $id=>$data) {
979 echo '<option value="'.$id.'"';
980 if($id == $identity) {
983 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
987 echo '</select>' . "\n" .
991 echo ' <tr>' . "\n" .
992 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
993 _("To:") . '</TD>' . "\n" .
994 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
995 ' <input type="text" name="send_to" value="' .
996 $send_to . '" size="60" /><br />' . "\n" .
1000 html_tag( 'td', '', 'right', $color[4] ) .
1001 _("CC:") . '</td>' . "\n" .
1002 html_tag( 'td', '', 'left', $color[4] ) .
1003 ' <input type="text" name="send_to_cc" size="60" value="' .
1004 $send_to_cc . '" /><br />' . "\n" .
1008 html_tag( 'td', '', 'right', $color[4] ) .
1009 _("BCC:") . '</td>' . "\n" .
1010 html_tag( 'td', '', 'left', $color[4] ) .
1011 ' <input type="text" name="send_to_bcc" value="' .
1012 $send_to_bcc . '" size="60" /><br />' . "\n" .
1016 html_tag( 'td', '', 'right', $color[4] ) .
1017 _("Subject:") . '</td>' . "\n" .
1018 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1019 echo ' <input type="text" name="subject" size="60" value="' .
1020 $subject . '" />' . "\n" .
1024 if ($location_of_buttons == 'between') {
1025 showComposeButtonRow();
1028 /* why this distinction? */
1029 if ($compose_new_win == '1') {
1030 echo ' <TR>' . "\n" .
1031 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1032 ' <TEXTAREA NAME="body" ID="body" ROWS="' . $editor_height .
1033 '" COLS="' . $editor_size . '" WRAP="VIRTUAL">';
1036 echo ' <TR>' . "\n" .
1037 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1038 ' <TEXTAREA NAME="body" ID="body" ROWS="' . $editor_height .
1039 '" COLS="' . $editor_size . '" WRAP="VIRTUAL">';
1042 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1043 $signature = $idents[$identity]['signature'];
1045 if ($sig_first == '1') {
1046 if ($default_charset == 'iso-2022-jp') {
1047 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1049 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1051 echo "\n\n".decodeHeader($body,false,false);
1054 echo "\n\n".decodeHeader($body,false,false);
1055 if ($default_charset == 'iso-2022-jp') {
1056 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1058 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1063 echo decodeHeader($body,false,false);
1065 echo '</textarea><br />' . "\n" .
1070 if ($location_of_buttons == 'bottom') {
1071 showComposeButtonRow();
1073 echo ' <tr>' . "\n" .
1074 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1075 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1076 ' <br /><br />' . "\n" .
1081 /* This code is for attachments */
1082 if ((bool) ini_get('file_uploads')) {
1084 /* Calculate the max size for an uploaded file.
1085 * This is advisory for the user because we can't actually prevent
1086 * people to upload too large files. */
1088 /* php.ini vars which influence the max for uploads */
1089 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1090 foreach($configvars as $var) {
1091 /* skip 0 or empty values */
1092 if( $size = getByteSize(ini_get($var)) ) {
1097 if(count($sizes) > 0) {
1098 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1102 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1103 echo ' <tr>' . "\n" .
1104 ' <td colspan="2">' . "\n" .
1105 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1106 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1109 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1110 ' border="0">' . "\n" .
1112 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1113 _("Attach:") . '</td>' . "\n" .
1114 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1115 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1116 ' <input type="submit" name="attach"' .
1117 ' value="' . _("Add") .'">' . "\n" .
1124 if ($composeMessage->entities
) {
1125 foreach ($composeMessage->entities
as $key => $attachment) {
1126 $attached_file = $attachment->att_local_name
;
1127 if ($attachment->att_local_name ||
$attachment->body_part
) {
1128 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1129 $type = $attachment->mime_header
->type0
.'/'.
1130 $attachment->mime_header
->type1
;
1132 $s_a[] = '<table bgcolor="'.$color[0].
1133 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1134 $key . "\"></td><td>\n" . $attached_filename .
1135 '</td><td>-</td><td> ' . $type . '</td><td>('.
1136 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1141 foreach ($s_a as $s) {
1142 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1144 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1145 _("Delete selected attachments") . "\">\n" .
1148 echo ' </table>' . "\n" .
1151 ' </TABLE>' . "\n" .
1154 } // End of file_uploads if-block
1155 /* End of attachment code */
1156 if ($compose_new_win == '1') {
1157 echo '</TABLE>'."\n";
1160 echo '</TABLE>' . "\n" .
1161 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1162 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1163 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1166 store the complete ComposeMessages array in a hidden input value
1167 so we can restore them in case of a session timeout.
1169 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1170 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1171 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1172 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1174 if (!(bool) ini_get('file_uploads')) {
1175 /* File uploads are off, so we didn't show that part of the form.
1176 To avoid bogus bug reports, tell the user why. */
1177 echo 'Because PHP file uploads are turned off, you can not attach files ';
1178 echo "to this message. Please see your system administrator for details.\r\n";
1181 do_hook('compose_bottom');
1182 echo '</BODY></HTML>' . "\n";
1186 function showComposeButtonRow() {
1187 global $use_javascript_addr_book, $save_as_draft,
1188 $default_use_priority, $mailprio, $default_use_mdn,
1189 $request_mdn, $request_dr,
1190 $data_dir, $username;
1192 echo ' <TR>' . "\n" .
1193 ' <TD></TD>' . "\n" .
1195 if ($default_use_priority) {
1196 if(!isset($mailprio)) {
1199 echo ' ' . _("Priority") .': <select name="mailprio">'.
1200 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1201 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1202 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1205 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1206 if ($default_use_mdn) {
1207 if ($mdn_user_support) {
1208 echo ' ' . _("Receipt") .': '.
1209 '<input type="checkbox" name="request_mdn" value=1'.
1210 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1211 ' <input type="checkbox" name="request_dr" value=1'.
1212 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1216 echo ' </TD>' . "\n" .
1219 ' <TD></TD>' . "\n" .
1221 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1222 if ($use_javascript_addr_book) {
1223 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1224 " <input type=button value=\\\""._("Addresses").
1225 "\\\" onclick='javascript:open_abook();'>\");".
1226 " // --></SCRIPT><NOSCRIPT>\n".
1227 " <input type=submit name=\"html_addr_search\" value=\"".
1228 _("Addresses")."\">".
1231 echo ' <input type=submit name="html_addr_search" value="'.
1232 _("Addresses").'">' . "\n";
1235 if ($save_as_draft) {
1236 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1239 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1240 do_hook('compose_button_row');
1242 echo ' </TD>' . "\n" .
1246 function checkInput ($show) {
1248 * I implemented the $show variable because the error messages
1249 * were getting sent before the page header. So, I check once
1250 * using $show=false, and then when i'm ready to display the error
1251 * message, show=true
1253 global $body, $send_to, $send_to_bcc, $subject, $color;
1255 if ($send_to == '' && $send_to_bcc == '') {
1257 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1262 } /* function checkInput() */
1265 /* True if FAILURE */
1266 function saveAttachedFiles($session) {
1267 global $_FILES, $attachment_dir, $attachments, $username,
1268 $data_dir, $compose_messages;
1270 /* get out of here if no file was attached at all */
1271 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1275 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1276 $localfilename = GenerateRandomString(32, '', 7);
1277 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1278 while (file_exists($full_localfilename)) {
1279 $localfilename = GenerateRandomString(32, '', 7);
1280 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1283 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1284 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1285 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1286 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1290 $message = $compose_messages[$session];
1291 $type = strtolower($_FILES['attachfile']['type']);
1292 $name = $_FILES['attachfile']['name'];
1293 $message->initAttachment($type, $name, $full_localfilename);
1294 $compose_messages[$session] = $message;
1295 sqsession_register($compose_messages , 'compose_messages');
1298 function ClearAttachments($composeMessage) {
1299 if ($composeMessage->att_local_name
) {
1300 $attached_file = $composeMessage->att_local_name
;
1301 if (file_exists($attached_file)) {
1302 unlink($attached_file);
1305 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1306 ClearAttachments($composeMessage->entities
[$i]);
1310 /* parse values like 8M and 2k into bytes */
1311 function getByteSize($ini_size) {
1317 $ini_size = trim($ini_size);
1319 // if there's some kind of letter at the end of the string we need to multiply.
1320 if(!is_numeric(substr($ini_size, -1))) {
1322 switch(strtoupper(substr($ini_size, -1))) {
1324 $bytesize = 1073741824;
1327 $bytesize = 1048576;
1334 return ($bytesize * (int)substr($ini_size, 0, -1));
1341 /* temporary function to make use of the deliver class.
1342 In the future the responsable backend should be automaticly loaded
1343 and conf.pl should show a list of available backends.
1344 The message also should be constructed by the message class.
1347 function deliverMessage($composeMessage, $draft=false) {
1348 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1349 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1350 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1351 $domain, $action, $default_move_to_sent, $move_to_sent;
1352 global $imapServerAddress, $imapPort, $sent_folder, $key;
1354 /* some browsers replace <space> by nonbreaking spaces
1355 by replacing them back to spaces addressparsing works */
1356 /* FIXME: How to handle in case of other charsets where "\240"
1357 is not a non breaking space ??? */
1358 /* THEFIX: browsers don't replace space with nbsp. SM replaces
1359 space with nbsp when decodes headers. If problem still happens,
1360 use cleanup_nbsp() */
1362 // $send_to = str_replace("\240",' ',$send_to);
1363 // $send_to_cc = str_replace("\240",' ',$send_to_cc);
1364 // $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1366 $rfc822_header = $composeMessage->rfc822_header
;
1368 $abook = addressbook_init(false, true);
1369 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1370 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1371 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1372 $rfc822_header->priority
= $mailprio;
1373 $rfc822_header->subject
= $subject;
1374 $special_encoding='';
1375 if (strtolower($default_charset) == 'iso-2022-jp') {
1376 if (mb_detect_encoding($body) == 'ASCII') {
1377 $special_encoding = '8bit';
1379 $body = mb_convert_encoding($body, 'JIS');
1380 $special_encoding = '7bit';
1383 $composeMessage->setBody($body);
1385 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1386 $popuser = $usernamedata[1];
1387 $domain = $usernamedata[2];
1388 unset($usernamedata);
1390 $popuser = $username;
1393 $from_mail = $idents[$identity]['email_address'];
1394 $full_name = $idents[$identity]['full_name'];
1395 $reply_to = $idents[$identity]['reply_to'];
1397 $from_mail = "$popuser@$domain";
1399 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1401 $from = $rfc822_header->from
[0];
1402 if (!$from->host
) $from->host
= $domain;
1403 $full_name_encoded = encodeHeader($full_name);
1404 if ($full_name_encoded != $full_name) {
1405 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1407 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1409 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1412 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1414 /* Receipt: On Read */
1415 if (isset($request_mdn) && $request_mdn) {
1416 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1418 /* Receipt: On Delivery */
1419 if (isset($request_dr) && $request_dr) {
1420 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1422 /* multipart messages */
1423 if (count($composeMessage->entities
)) {
1424 $message_body = new Message();
1425 $message_body->body_part
= $composeMessage->body_part
;
1426 $composeMessage->body_part
= '';
1427 $mime_header = new MessageHeader
;
1428 $mime_header->type0
= 'text';
1429 $mime_header->type1
= 'plain';
1430 if ($special_encoding) {
1431 $mime_header->encoding
= $special_encoding;
1433 $mime_header->encoding
= '8bit';
1435 if ($default_charset) {
1436 $mime_header->parameters
['charset'] = $default_charset;
1438 $message_body->mime_header
= $mime_header;
1439 array_unshift($composeMessage->entities
, $message_body);
1440 $content_type = new ContentType('multipart/mixed');
1442 $content_type = new ContentType('text/plain');
1443 if ($special_encoding) {
1444 $rfc822_header->encoding
= $special_encoding;
1446 $rfc822_header->encoding
= '8bit';
1448 if ($default_charset) {
1449 $content_type->properties
['charset']=$default_charset;
1453 $rfc822_header->content_type
= $content_type;
1454 $composeMessage->rfc822_header
= $rfc822_header;
1456 /* Here you can modify the message structure just before we hand
1457 it over to deliver */
1458 $hookReturn = do_hook('compose_send', $composeMessage);
1459 /* Get any changes made by plugins to $composeMessage. */
1460 if ( is_object($hookReturn[1]) ) {
1461 $composeMessage = $hookReturn[1];
1464 if (!$useSendmail && !$draft) {
1465 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1466 $deliver = new Deliver_SMTP();
1467 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1469 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1470 get_smtp_user($user, $pass);
1471 $stream = $deliver->initStream($composeMessage,$domain,0,
1472 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1473 } elseif (!$draft) {
1474 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1475 global $sendmail_path;
1476 $deliver = new Deliver_SendMail();
1477 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1479 global $draft_folder;
1480 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1481 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1483 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1484 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1485 $imap_deliver = new Deliver_IMAP();
1486 $length = $imap_deliver->mail($composeMessage);
1487 sqimap_append ($imap_stream, $draft_folder, $length);
1488 $imap_deliver->mail($composeMessage, $imap_stream);
1489 sqimap_append_done ($imap_stream, $draft_folder);
1490 sqimap_logout($imap_stream);
1491 unset ($imap_deliver);
1494 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1495 plain_error_message($msg, $color);
1501 $length = $deliver->mail($composeMessage, $stream);
1502 $succes = $deliver->finalizeStream($stream);
1505 $msg = $deliver->dlv_msg
. '<br>' .
1506 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1507 $deliver->dlv_server_msg
;
1508 plain_error_message($msg, $color);
1511 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1512 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1514 /* Move to sent code */
1515 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1516 $svr_allow_sent = true;
1518 $svr_allow_sent = false;
1521 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1522 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1528 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1529 $lcl_allow_sent = true;
1531 $lcl_allow_sent = false;
1534 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1535 global $passed_id, $mailbox, $action;
1536 if ($action == 'reply' ||
$action == 'reply_all') {
1537 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1538 if ($save_reply_with_orig) {
1539 $sent_folder = $mailbox;
1542 sqimap_append ($imap_stream, $sent_folder, $length);
1543 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1544 $imap_deliver = new Deliver_IMAP();
1545 $imap_deliver->mail($composeMessage, $imap_stream);
1546 sqimap_append_done ($imap_stream, $sent_folder);
1547 unset ($imap_deliver);
1549 global $passed_id, $mailbox, $action;
1550 ClearAttachments($composeMessage);
1551 if ($action == 'reply' ||
$action == 'reply_all') {
1552 sqimap_mailbox_select ($imap_stream, $mailbox);
1553 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1555 sqimap_logout($imap_stream);