a28d0782e918fb8b621f27e56e183fff2dd9c41c
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
18 * @package squirrelmail
22 * Path for SquirrelMail required files.
25 define('SM_PATH','../');
27 /* SquirrelMail required files. */
28 require_once(SM_PATH
. 'include/validate.php');
29 require_once(SM_PATH
. 'functions/global.php');
30 require_once(SM_PATH
. 'functions/imap.php');
31 require_once(SM_PATH
. 'functions/date.php');
32 require_once(SM_PATH
. 'functions/mime.php');
33 require_once(SM_PATH
. 'functions/plugin.php');
34 require_once(SM_PATH
. 'functions/display_messages.php');
35 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
36 require_once(SM_PATH
. 'functions/addressbook.php');
37 require_once(SM_PATH
. 'functions/identity.php');
38 require_once(SM_PATH
. 'functions/forms.php');
40 /* --------------------- Get globals ------------------------------------- */
42 sqgetGlobalVar('key', $key, SQ_COOKIE
);
45 sqgetGlobalVar('username', $username, SQ_SESSION
);
46 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
47 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
50 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
51 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
53 /** SESSION/POST/GET VARS */
54 sqgetGlobalVar('session',$session);
55 sqgetGlobalVar('mailbox',$mailbox);
56 if(!sqgetGlobalVar('identity',$identity)) {
59 sqgetGlobalVar('send_to',$send_to);
60 sqgetGlobalVar('send_to_cc',$send_to_cc);
61 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
62 sqgetGlobalVar('subject',$subject);
63 sqgetGlobalVar('body',$body);
64 sqgetGlobalVar('mailprio',$mailprio);
65 sqgetGlobalVar('request_mdn',$request_mdn);
66 sqgetGlobalVar('request_dr',$request_dr);
67 sqgetGlobalVar('html_addr_search',$html_addr_search);
68 sqgetGlobalVar('mail_sent',$mail_sent);
69 sqgetGlobalVar('passed_id',$passed_id);
70 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
71 sqgetGlobalVar('send',$send);
73 sqgetGlobalVar('attach',$attach);
75 sqgetGlobalVar('draft',$draft);
76 sqgetGlobalVar('draft_id',$draft_id);
77 sqgetGlobalVar('ent_num',$ent_num);
78 sqgetGlobalVar('saved_draft',$saved_draft);
79 sqgetGlobalVar('delete_draft',$delete_draft);
80 sqgetGlobalVar('startMessage',$startMessage);
83 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
84 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
85 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
86 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
87 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
88 sqgetGlobalVar('delete', $delete, SQ_POST
);
89 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
90 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
91 $html_addr_search_done = 'Use Addresses';
95 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
98 if ( !sqgetGlobalVar('smaction',$action) )
100 if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply';
101 if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all';
102 if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward';
103 if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment';
104 if ( sqgetGlobalVar('smaction_draft',$tmp) ) $action = 'draft';
105 if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action = 'edit_as_new';
108 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
109 $location = get_location();
110 /* Identities (fetch only once) */
111 $idents = get_identities();
113 /* --------------------- Specific Functions ------------------------------ */
115 function replyAllString($header) {
116 global $include_self_reply_all, $idents;
119 * 1) Remove the addresses we'll be sending the message 'to'
121 $url_replytoall_avoid_addrs = '';
122 if (isset($header->replyto
)) {
123 $excl_ar = $header->getAddr_a('replyto');
126 * 2) Remove our identities from the CC list (they still can be in the
127 * TO list) only if $include_self_reply_all is turned off
129 if (!$include_self_reply_all) {
130 foreach($idents as $id) {
131 $excl_ar[strtolower(trim($id['email_address']))] = '';
136 * 3) get the addresses.
138 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
141 * 4) generate the string.
143 $url_replytoallcc = '';
144 foreach( $url_replytoall_ar as $email => $personal) {
146 // if personal name contains address separator then surround
147 // the personal name with double quotes.
148 if (strpos($personal,',') !== false) {
149 $personal = '"'.$personal.'"';
151 $url_replytoallcc .= ", $personal <$email>";
153 $url_replytoallcc .= ', '. $email;
156 $url_replytoallcc = substr($url_replytoallcc,2);
158 return $url_replytoallcc;
161 function getReplyCitation($orig_from, $orig_date) {
162 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
163 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
164 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
165 /* First, return an empty string when no citation style selected. */
166 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
170 /* Make sure our final value isn't an empty string. */
171 if ($orig_from == '') {
175 /* Otherwise, try to select the desired citation style. */
176 switch ($reply_citation_style) {
179 $end = ' ' . _("said") . ':';
182 $start = '<' . _("quote") . ' ' . _("who") . '="';
185 case 'date_time_author':
186 $start = 'On ' . getLongDateString($orig_date) . ', ';
187 $end = ' ' . _("said") . ':';
190 $start = $reply_citation_start .
191 ($reply_citation_start == '' ?
'' : ' ');
192 $end = $reply_citation_end;
198 /* Build and return the citation string. */
199 return ($start . $orig_from . $end . "\n");
202 function getforwardHeader($orig_header) {
205 $display = array( _("Subject") => strlen(_("Subject")),
206 _("From") => strlen(_("From")),
207 _("Date") => strlen(_("Date")),
208 _("To") => strlen(_("To")),
209 _("Cc") => strlen(_("Cc")) );
210 $maxsize = max($display);
211 $indent = str_pad('',$maxsize+
2);
212 foreach($display as $key => $val) {
213 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
215 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
216 $from = str_replace(' ',' ',$from);
217 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
218 $to = str_replace(' ',' ',$to);
219 $subject = decodeHeader($orig_header->subject
,false,false,true);
220 $subject = str_replace(' ',' ',$subject);
221 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
222 "\n". $display[_("Subject")] . $subject . "\n" .
223 $display[_("From")] . $from . "\n" .
224 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
225 $display[_("To")] . $to . "\n";
226 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
227 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
228 $cc = str_replace(' ',' ',$cc);
229 $bodyTop .= $display[_("Cc")] .$cc . "\n";
231 $bodyTop .= str_pad('', $editor_size -2 , '-') .
235 /* ----------------------------------------------------------------------- */
238 * If the session is expired during a post this restores the compose session
241 if (sqsession_is_registered('session_expired_post')) {
242 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
244 * extra check for username so we don't display previous post data from
245 * another user during this session.
247 if ($session_expired_post['username'] != $username) {
248 unset($session_expired_post);
249 sqsession_unregister('session_expired_post');
250 session_write_close();
252 foreach ($session_expired_post as $postvar => $val) {
259 $compose_messages = unserialize(urldecode($restoremessages));
260 sqsession_register($compose_messages,'compose_messages');
261 sqsession_register($composesession,'composesession');
265 $session_expired = true;
267 unset($session_expired_post);
268 sqsession_unregister('session_expired_post');
269 session_write_close();
270 if (!isset($mailbox)) {
273 if ($compose_new_win == '1') {
274 compose_Header($color, $mailbox);
276 displayPageHeader($color, $mailbox);
278 showInputForm($session, false);
281 if (!isset($composesession)) {
283 sqsession_register(0,'composesession');
286 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
287 sqsession_unregister('composesession');
288 $session = "$composesession" +
1;
289 $composesession = $session;
290 sqsession_register($composesession,'composesession');
292 if (!isset($compose_messages)) {
293 $compose_messages = array();
295 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
296 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
297 $composeMessage = new Message();
298 $rfc822_header = new Rfc822Header();
299 $composeMessage->rfc822_header
= $rfc822_header;
300 $composeMessage->reply_rfc822_header
= '';
301 $compose_messages[$session] = $composeMessage;
302 sqsession_register($compose_messages,'compose_messages');
304 $composeMessage=$compose_messages[$session];
307 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
313 * Set $default_charset to correspond with the user's selection
314 * of language interface.
317 $composeMessage=$compose_messages[$session];
318 if (! deliverMessage($composeMessage, true)) {
319 showInputForm($session);
322 unset($compose_messages[$session]);
323 $draft_message = _("Draft Email Saved");
324 /* If this is a resumed draft, then delete the original */
325 if(isset($delete_draft)) {
326 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
327 "&message=$delete_draft&startMessage=1&saved_draft=yes");
331 if ($compose_new_win == '1') {
332 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
336 Header("Location: $location/right_main.php?mailbox=$draft_folder".
337 "&startMessage=1¬e=".urlencode($draft_message));
345 if (isset($_FILES['attachfile']) &&
346 $_FILES['attachfile']['tmp_name'] &&
347 $_FILES['attachfile']['tmp_name'] != 'none') {
348 $AttachFailure = saveAttachedFiles($session);
350 if (checkInput(false) && !isset($AttachFailure)) {
351 if ($mailbox == "All Folders") {
352 /* We entered compose via the search results page */
353 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
355 $urlMailbox = urlencode (trim($mailbox));
356 if (! isset($passed_id)) {
360 * Set $default_charset to correspond with the user's selection
361 * of language interface.
365 * This is to change all newlines to \n
366 * We'll change them to \r\n later (in the sendMessage function)
368 $body = str_replace("\r\n", "\n", $body);
369 $body = str_replace("\r", "\n", $body);
372 * If the browser doesn't support "VIRTUAL" as the wrap type.
373 * then the line length will be longer than $editor_size
374 * almost all browsers support VIRTUAL, so remove the line by line checking
375 * If this causes a problem, call sqBodyWrap
377 // sqBodyWrap($body, $editor_size);
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&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".
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,
569 $composeMessage, $body_quote;
570 global $languages, $squirrelmail_language, $default_charset;
573 * Set $default_charset to correspond with the user's selection
574 * of language interface. $default_charset global is not correct,
575 * if message is composed in new window.
579 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
583 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
586 sqimap_mailbox_select($imapConnection, $mailbox);
587 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
590 if ($passed_ent_id) {
591 /* redefine the messsage in case of message/rfc822 */
592 $message = $message->getEntity($passed_ent_id);
593 /* message is an entity which contains the envelope and type0=message
594 * and type1=rfc822. The actual entities are childs from
595 * $message->entities[0]. That's where the encoding and is located
598 $entities = $message->entities
[0]->findDisplayEntity
599 (array(), $alt_order = array('text/plain'));
600 if (!count($entities)) {
601 $entities = $message->entities
[0]->findDisplayEntity
602 (array(), $alt_order = array('text/plain','html/plain'));
604 $orig_header = $message->rfc822_header
; /* here is the envelope located */
605 /* redefine the message for picking up the attachments */
606 $message = $message->entities
[0];
609 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
610 if (!count($entities)) {
611 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
613 $orig_header = $message->rfc822_header
;
616 $encoding = $message->header
->encoding
;
617 $type0 = $message->type0
;
618 $type1 = $message->type1
;
619 foreach ($entities as $ent) {
620 $msg = $message->getEntity($ent);
621 $type0 = $msg->type0
;
622 $type1 = $msg->type1
;
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','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
631 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
632 $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_convert($actual,$bodypart,$default_charset);
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_array($from_o)) {
666 if (isset($from_o[0])) {
667 $from_o = $from_o[0];
670 if (is_object($from_o)) {
671 $orig_from = $from_o->getAddress();
676 $identities = array();
677 if (count($idents) > 1) {
678 foreach($idents as $nr=>$data) {
679 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
680 if($enc_from_name == $orig_from) {
684 $identities[] = $enc_from_name;
687 $identity_match = $orig_header->findAddress($identities);
688 if ($identity_match) {
689 $identity = $identity_match;
695 $use_signature = FALSE;
696 $composeMessage->rfc822_header
= $orig_header;
697 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
698 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
699 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
700 $send_from = $orig_header->getAddr_s('from');
701 $send_from_parts = new AddressStructure();
702 $send_from_parts = $orig_header->parseAddress($send_from);
703 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
704 $identities = get_identities();
705 if (count($identities) > 0) {
706 foreach($identities as $iddata) {
707 if ($send_from_add == $iddata['email_address']) {
708 $identity = $iddata['index'];
713 $subject = decodeHeader($orig_header->subject
,false,false,true);
714 ///* remember the references and in-reply-to headers in case of an reply */
715 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
716 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
717 //rewrap the body to clean up quotations and line lengths
718 sqBodyWrap($body, $editor_size);
719 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
721 case ('edit_as_new'):
722 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
723 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
724 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
725 $subject = decodeHeader($orig_header->subject
,false,false,true);
726 $mailprio = $orig_header->priority
;
728 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
729 //rewrap the body to clean up quotations and line lengths
730 sqBodyWrap($body, $editor_size);
734 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
735 $body = getforwardHeader($orig_header) . $body;
736 // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines
737 // forwarded message text should be as undisturbed as possible, so commenting out this call
738 // sqUnWordWrap($body);
739 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
740 //add a blank line after the forward headers
741 $body = "\n" . $body;
743 case ('forward_as_attachment'):
744 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
745 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
749 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
750 $send_to = $orig_header->getAddr_s('mail_followup_to');
752 $send_to_cc = replyAllString($orig_header);
753 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
756 // skip this if send_to was already set right above here
758 $send_to = $orig_header->reply_to
;
759 if (is_array($send_to) && count($send_to)) {
760 $send_to = $orig_header->getAddr_s('reply_to');
761 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
762 $send_to = $orig_header->getAddr_s('reply_to');
764 $send_to = $orig_header->getAddr_s('from');
767 $send_to = decodeHeader($send_to,false,false,true);
768 $subject = decodeHeader($orig_header->subject
,false,false,true);
769 $subject = str_replace('"', "'", $subject);
770 $subject = trim($subject);
771 if (substr(strtolower($subject), 0, 3) != 're:') {
772 $subject = 'Re: ' . $subject;
774 /* this corrects some wrapping/quoting problems on replies */
775 $rewrap_body = explode("\n", $body);
776 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
778 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
779 foreach ($rewrap_body as $line) {
780 if ($strip_sigs && substr($line,0,3) == '-- ') {
783 if (preg_match("/^(>+)/", $line, $matches)) {
785 $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n";
787 $body .= $body_quote . (!empty($body_quote) ?
' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ?
' ' : ''), rtrim($line)) . "\n";
791 //rewrap the body to clean up quotations and line lengths
792 $body = sqBodyWrap ($body, $editor_size);
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;
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, TRUE);
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, $editor_height, $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];
919 $send_to = $values['send_to'];
920 $send_to_cc = $values['send_to_cc'];
921 $send_to_bcc = $values['send_to_bcc'];
922 $subject = $values['subject'];
923 $mailprio = $values['mailprio'];
924 $body = $values['body'];
925 $identity = (int) $values['identity'];
927 $send_to = decodeHeader($send_to, true, false);
928 $send_to_cc = decodeHeader($send_to_cc, true, false);
929 $send_to_bcc = decodeHeader($send_to_bcc, true, false);
932 if ($use_javascript_addr_book) {
933 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
934 'function open_abook() { ' . "\n" .
935 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
936 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
937 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
938 ' nwin.opener = document.windows;' . "\n" .
940 "// -->\n</SCRIPT>\n\n";
943 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
944 'enctype="multipart/form-data"';
945 do_hook('compose_form');
949 echo addHidden('startMessage', $startMessage);
951 if ($action == 'draft') {
952 echo addHidden('delete_draft', $passed_id);
954 if (isset($delete_draft)) {
955 echo addHidden('delete_draft', $delete_draft);
957 if (isset($session)) {
958 echo addHidden('session', $session);
961 if (isset($passed_id)) {
962 echo addHidden('passed_id', $passed_id);
965 if ($saved_draft == 'yes') {
966 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
968 if ($mail_sent == 'yes') {
969 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
971 echo '<table align="center" cellspacing="0" border="0">' . "\n";
972 if ($compose_new_win == '1') {
973 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
974 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
976 if ($location_of_buttons == 'top') {
977 showComposeButtonRow();
980 /* display select list for identities */
981 if (count($idents) > 1) {
982 $ident_list = array();
983 foreach($idents as $id => $data) {
985 $data['full_name'].' <'.$data['email_address'].'>';
987 echo ' <tr>' . "\n" .
988 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
989 _("From:") . '</td>' . "\n" .
990 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
992 addSelect('identity', $ident_list, $identity, TRUE);
994 echo ' </td>' . "\n" .
998 echo ' <tr>' . "\n" .
999 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1000 _("To:") . '</TD>' . "\n" .
1001 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1002 addInput('send_to', $send_to, 60). '<br />' . "\n" .
1006 html_tag( 'td', '', 'right', $color[4] ) .
1007 _("CC:") . '</td>' . "\n" .
1008 html_tag( 'td', '', 'left', $color[4] ) .
1009 addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
1013 html_tag( 'td', '', 'right', $color[4] ) .
1014 _("BCC:") . '</td>' . "\n" .
1015 html_tag( 'td', '', 'left', $color[4] ) .
1016 addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
1020 html_tag( 'td', '', 'right', $color[4] ) .
1021 _("Subject:") . '</td>' . "\n" .
1022 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1023 echo ' '.addInput('subject', $subject, 60).
1027 if ($location_of_buttons == 'between') {
1028 showComposeButtonRow();
1031 /* why this distinction? */
1032 if ($compose_new_win == '1') {
1033 echo ' <TR>' . "\n" .
1034 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1035 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1036 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1039 echo ' <TR>' . "\n" .
1040 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1041 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1042 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1045 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1046 $signature = $idents[$identity]['signature'];
1048 if ($sig_first == '1') {
1049 if ($default_charset == 'iso-2022-jp') {
1050 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1052 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1054 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1057 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1058 if ($default_charset == 'iso-2022-jp') {
1059 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1061 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1066 echo htmlspecialchars(decodeHeader($body,false,false));
1068 echo '</textarea><br />' . "\n" .
1073 if ($location_of_buttons == 'bottom') {
1074 showComposeButtonRow();
1076 echo ' <tr>' . "\n" .
1077 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1078 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1079 ' <br /><br />' . "\n" .
1084 /* This code is for attachments */
1085 if ((bool) ini_get('file_uploads')) {
1087 /* Calculate the max size for an uploaded file.
1088 * This is advisory for the user because we can't actually prevent
1089 * people to upload too large files. */
1091 /* php.ini vars which influence the max for uploads */
1092 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1093 foreach($configvars as $var) {
1094 /* skip 0 or empty values */
1095 if( $size = getByteSize(ini_get($var)) ) {
1100 if(count($sizes) > 0) {
1101 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1105 echo addHidden('MAX_FILE_SIZE', min( $sizes ));
1106 echo ' <tr>' . "\n" .
1107 ' <td colspan="2">' . "\n" .
1108 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1109 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1112 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1113 ' border="0">' . "\n" .
1115 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1116 _("Attach:") . '</td>' . "\n" .
1117 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1118 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1119 ' <input type="submit" name="attach"' .
1120 ' value="' . _("Add") .'">' . "\n" .
1127 if ($composeMessage->entities
) {
1128 foreach ($composeMessage->entities
as $key => $attachment) {
1129 $attached_file = $attachment->att_local_name
;
1130 if ($attachment->att_local_name ||
$attachment->body_part
) {
1131 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1132 $type = $attachment->mime_header
->type0
.'/'.
1133 $attachment->mime_header
->type1
;
1135 $s_a[] = '<table bgcolor="'.$color[0].
1136 '" border="0"><tr><td>'.
1137 addCheckBox('delete[]', FALSE, $key).
1138 "</td><td>\n" . $attached_filename .
1139 '</td><td>-</td><td> ' . $type . '</td><td>('.
1140 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1145 foreach ($s_a as $s) {
1146 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1148 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1149 _("Delete selected attachments") . "\">\n" .
1152 echo ' </table>' . "\n" .
1155 ' </TABLE>' . "\n" .
1158 } // End of file_uploads if-block
1159 /* End of attachment code */
1160 if ($compose_new_win == '1') {
1161 echo '</TABLE>'."\n";
1164 echo '</TABLE>' . "\n" .
1165 addHidden('username', $username).
1166 addHidden('smaction', $action).
1167 addHidden('mailbox', $mailbox);
1169 store the complete ComposeMessages array in a hidden input value
1170 so we can restore them in case of a session timeout.
1172 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1173 echo addHidden('restoremessages', serialize($compose_messages)).
1174 addHidden('composesession', $composesession).
1175 addHidden('querystring', $queryString).
1177 if (!(bool) ini_get('file_uploads')) {
1178 /* File uploads are off, so we didn't show that part of the form.
1179 To avoid bogus bug reports, tell the user why. */
1180 echo 'Because PHP file uploads are turned off, you can not attach files ';
1181 echo "to this message. Please see your system administrator for details.\r\n";
1184 do_hook('compose_bottom');
1185 echo '</BODY></HTML>' . "\n";
1189 function showComposeButtonRow() {
1190 global $use_javascript_addr_book, $save_as_draft,
1191 $default_use_priority, $mailprio, $default_use_mdn,
1192 $request_mdn, $request_dr,
1193 $data_dir, $username;
1195 echo ' <TR>' . "\n" .
1196 ' <TD></TD>' . "\n" .
1198 if ($default_use_priority) {
1199 if(!isset($mailprio)) {
1202 echo ' ' . _("Priority") .
1203 addSelect('mailprio', array(
1206 '5' => _("Low") ), $mailprio, TRUE);
1208 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1209 if ($default_use_mdn) {
1210 if ($mdn_user_support) {
1211 echo ' ' . _("Receipt") .': '.
1212 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1213 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1217 echo ' </TD>' . "\n" .
1220 ' <TD></TD>' . "\n" .
1222 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1223 if ($use_javascript_addr_book) {
1224 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1225 " <input type=button value=\\\""._("Addresses").
1226 "\\\" onclick='javascript:open_abook();'>\");".
1227 " // --></SCRIPT><NOSCRIPT>\n".
1228 " <input type=submit name=\"html_addr_search\" value=\"".
1229 _("Addresses")."\">".
1232 echo ' <input type=submit name="html_addr_search" value="'.
1233 _("Addresses").'">' . "\n";
1236 if ($save_as_draft) {
1237 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1240 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1241 do_hook('compose_button_row');
1243 echo ' </TD>' . "\n" .
1247 function checkInput ($show) {
1249 * I implemented the $show variable because the error messages
1250 * were getting sent before the page header. So, I check once
1251 * using $show=false, and then when i'm ready to display the error
1252 * message, show=true
1254 global $body, $send_to, $send_to_bcc, $subject, $color;
1256 if ($send_to == '' && $send_to_bcc == '') {
1258 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1263 } /* function checkInput() */
1266 /* True if FAILURE */
1267 function saveAttachedFiles($session) {
1268 global $_FILES, $attachment_dir, $attachments, $username,
1269 $data_dir, $compose_messages;
1271 /* get out of here if no file was attached at all */
1272 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1276 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1277 $localfilename = GenerateRandomString(32, '', 7);
1278 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1279 while (file_exists($full_localfilename)) {
1280 $localfilename = GenerateRandomString(32, '', 7);
1281 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1284 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1285 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1286 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1287 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1291 $message = $compose_messages[$session];
1292 $type = strtolower($_FILES['attachfile']['type']);
1293 $name = $_FILES['attachfile']['name'];
1294 $message->initAttachment($type, $name, $full_localfilename);
1295 $compose_messages[$session] = $message;
1296 sqsession_register($compose_messages , 'compose_messages');
1299 function ClearAttachments($composeMessage) {
1300 if ($composeMessage->att_local_name
) {
1301 $attached_file = $composeMessage->att_local_name
;
1302 if (file_exists($attached_file)) {
1303 unlink($attached_file);
1306 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1307 ClearAttachments($composeMessage->entities
[$i]);
1311 /* parse values like 8M and 2k into bytes */
1312 function getByteSize($ini_size) {
1318 $ini_size = trim($ini_size);
1320 // if there's some kind of letter at the end of the string we need to multiply.
1321 if(!is_numeric(substr($ini_size, -1))) {
1323 switch(strtoupper(substr($ini_size, -1))) {
1325 $bytesize = 1073741824;
1328 $bytesize = 1048576;
1335 return ($bytesize * (int)substr($ini_size, 0, -1));
1342 /* temporary function to make use of the deliver class.
1343 In the future the responsable backend should be automaticly loaded
1344 and conf.pl should show a list of available backends.
1345 The message also should be constructed by the message class.
1348 function deliverMessage($composeMessage, $draft=false) {
1349 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1350 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1351 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1352 $domain, $action, $default_move_to_sent, $move_to_sent;
1353 global $imapServerAddress, $imapPort, $sent_folder, $key;
1355 $rfc822_header = $composeMessage->rfc822_header
;
1357 $abook = addressbook_init(false, true);
1358 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1359 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1360 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1361 $rfc822_header->priority
= $mailprio;
1362 $rfc822_header->subject
= $subject;
1364 $special_encoding='';
1365 if (strtolower($default_charset) == 'iso-2022-jp') {
1366 if (mb_detect_encoding($body) == 'ASCII') {
1367 $special_encoding = '8bit';
1369 $body = mb_convert_encoding($body, 'JIS');
1370 $special_encoding = '7bit';
1373 $composeMessage->setBody($body);
1375 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1376 $popuser = $usernamedata[1];
1377 $domain = $usernamedata[2];
1378 unset($usernamedata);
1380 $popuser = $username;
1383 $from_mail = $idents[$identity]['email_address'];
1384 $full_name = $idents[$identity]['full_name'];
1385 $reply_to = $idents[$identity]['reply_to'];
1387 $from_mail = "$popuser@$domain";
1389 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1391 $from = $rfc822_header->from
[0];
1392 if (!$from->host
) $from->host
= $domain;
1393 $full_name_encoded = encodeHeader($full_name);
1394 if ($full_name_encoded != $full_name) {
1395 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1397 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1399 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1402 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1404 /* Receipt: On Read */
1405 if (isset($request_mdn) && $request_mdn) {
1406 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1408 /* Receipt: On Delivery */
1409 if (isset($request_dr) && $request_dr) {
1410 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1412 /* multipart messages */
1413 if (count($composeMessage->entities
)) {
1414 $message_body = new Message();
1415 $message_body->body_part
= $composeMessage->body_part
;
1416 $composeMessage->body_part
= '';
1417 $mime_header = new MessageHeader
;
1418 $mime_header->type0
= 'text';
1419 $mime_header->type1
= 'plain';
1420 if ($special_encoding) {
1421 $mime_header->encoding
= $special_encoding;
1423 $mime_header->encoding
= '8bit';
1425 if ($default_charset) {
1426 $mime_header->parameters
['charset'] = $default_charset;
1428 $message_body->mime_header
= $mime_header;
1429 array_unshift($composeMessage->entities
, $message_body);
1430 $content_type = new ContentType('multipart/mixed');
1432 $content_type = new ContentType('text/plain');
1433 if ($special_encoding) {
1434 $rfc822_header->encoding
= $special_encoding;
1436 $rfc822_header->encoding
= '8bit';
1438 if ($default_charset) {
1439 $content_type->properties
['charset']=$default_charset;
1443 $rfc822_header->content_type
= $content_type;
1444 $composeMessage->rfc822_header
= $rfc822_header;
1446 /* Here you can modify the message structure just before we hand
1447 it over to deliver */
1448 $hookReturn = do_hook('compose_send', $composeMessage);
1449 /* Get any changes made by plugins to $composeMessage. */
1450 if ( is_object($hookReturn[1]) ) {
1451 $composeMessage = $hookReturn[1];
1454 if (!$useSendmail && !$draft) {
1455 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1456 $deliver = new Deliver_SMTP();
1457 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1459 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1460 get_smtp_user($user, $pass);
1461 $stream = $deliver->initStream($composeMessage,$domain,0,
1462 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1463 } elseif (!$draft) {
1464 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1465 global $sendmail_path;
1466 $deliver = new Deliver_SendMail();
1467 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1469 global $draft_folder;
1470 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1471 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1473 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1474 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1475 $imap_deliver = new Deliver_IMAP();
1476 $length = $imap_deliver->mail($composeMessage);
1477 sqimap_append ($imap_stream, $draft_folder, $length);
1478 $imap_deliver->mail($composeMessage, $imap_stream);
1479 sqimap_append_done ($imap_stream, $draft_folder);
1480 sqimap_logout($imap_stream);
1481 unset ($imap_deliver);
1484 $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
1485 plain_error_message($msg, $color);
1491 $length = $deliver->mail($composeMessage, $stream);
1492 $succes = $deliver->finalizeStream($stream);
1495 $msg = $deliver->dlv_msg
. '<br />' .
1496 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1497 $deliver->dlv_server_msg
;
1498 plain_error_message($msg, $color);
1501 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1502 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1504 /* Move to sent code */
1505 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1506 $svr_allow_sent = true;
1508 $svr_allow_sent = false;
1511 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1512 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1518 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1519 $lcl_allow_sent = true;
1521 $lcl_allow_sent = false;
1524 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1525 global $passed_id, $mailbox, $action;
1526 if ($action == 'reply' ||
$action == 'reply_all') {
1527 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1528 if ($save_reply_with_orig) {
1529 $sent_folder = $mailbox;
1532 sqimap_append ($imap_stream, $sent_folder, $length);
1533 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1534 $imap_deliver = new Deliver_IMAP();
1535 $imap_deliver->mail($composeMessage, $imap_stream);
1536 sqimap_append_done ($imap_stream, $sent_folder);
1537 unset ($imap_deliver);
1539 global $passed_id, $mailbox, $action;
1540 ClearAttachments($composeMessage);
1541 if ($action == 'reply' ||
$action == 'reply_all') {
1542 sqimap_mailbox_select ($imap_stream, $mailbox);
1543 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1545 sqimap_logout($imap_stream);