9b83c0168eaf0205e2c619c2dde86e54391a4be4
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 * Rewrap $body so that no line is bigger than $editor_size
373 * This should only really kick in the sqWordWrap function
374 * if the browser doesn't support "VIRTUAL" as the wrap type.
376 * (braverock:) It is unclear if this code should be replaced
377 * with sqBodyWrap or removed entirely.
379 $body = explode("\n", $body);
381 foreach ($body as $line) {
382 if( $line <> '-- ' ) {
383 $line = rtrim($line);
385 if (strlen($line) <= $editor_size +
1) {
386 $newBody .= $line . "\n";
388 sqWordWrap($line, $editor_size);
389 $newBody .= $line . "\n";
395 $composeMessage=$compose_messages[$session];
397 $Result = deliverMessage($composeMessage);
399 showInputForm($session);
402 unset($compose_messages[$session]);
403 if ( isset($delete_draft)) {
404 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
405 "&message=$delete_draft&startMessage=1&mail_sent=yes");
408 if ($compose_new_win == '1') {
410 Header("Location: $location/compose.php?mail_sent=yes");
413 Header("Location: $location/right_main.php?mailbox=$urlMailbox".
414 "&startMessage=$startMessage&mail_sent=yes");
417 if ($compose_new_win == '1') {
418 compose_Header($color, $mailbox);
421 displayPageHeader($color, $mailbox);
423 if (isset($AttachFailure)) {
424 plain_error_message(_("Could not move/copy file. File not attached"),
428 showInputForm($session);
429 /* sqimap_logout($imapConnection); */
431 } elseif (isset($html_addr_search_done)) {
432 if ($compose_new_win == '1') {
433 compose_Header($color, $mailbox);
436 displayPageHeader($color, $mailbox);
439 if (isset($send_to_search) && is_array($send_to_search)) {
440 foreach ($send_to_search as $k => $v) {
441 if (substr($k, 0, 1) == 'T') {
447 elseif (substr($k, 0, 1) == 'C') {
453 elseif (substr($k, 0, 1) == 'B') {
455 $send_to_bcc .= ', ';
461 showInputForm($session);
462 } elseif (isset($html_addr_search)) {
463 if (isset($_FILES['attachfile']) &&
464 $_FILES['attachfile']['tmp_name'] &&
465 $_FILES['attachfile']['tmp_name'] != 'none') {
466 if(saveAttachedFiles($session)) {
467 plain_error_message(_("Could not move/copy file. File not attached"), $color);
471 * I am using an include so as to elminiate an extra unnecessary
472 * click. If you can think of a better way, please implement it.
474 include_once('./addrbook_search_html.php');
475 } elseif (isset($attach)) {
476 if (saveAttachedFiles($session)) {
477 plain_error_message(_("Could not move/copy file. File not attached"), $color);
479 if ($compose_new_win == '1') {
480 compose_Header($color, $mailbox);
483 displayPageHeader($color, $mailbox);
485 showInputForm($session);
487 elseif (isset($sigappend)) {
488 $signature = $idents[$identity]['signature'];
490 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
491 if ($compose_new_win == '1') {
492 compose_Header($color, $mailbox);
494 displayPageHeader($color, $mailbox);
496 showInputForm($session);
497 } elseif (isset($do_delete)) {
498 if ($compose_new_win == '1') {
499 compose_Header($color, $mailbox);
502 displayPageHeader($color, $mailbox);
505 if (isset($delete) && is_array($delete)) {
506 $composeMessage = $compose_messages[$session];
507 foreach($delete as $index) {
508 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
509 unlink ($attached_file);
510 unset ($composeMessage->entities
[$index]);
512 $new_entities = array();
513 foreach ($composeMessage->entities
as $entity) {
514 $new_entities[] = $entity;
516 $composeMessage->entities
= $new_entities;
517 $compose_messages[$session] = $composeMessage;
518 sqsession_register($compose_messages, 'compose_messages');
520 showInputForm($session);
523 * This handles the default case as well as the error case
524 * (they had the same code) --> if (isset($smtpErrors))
527 if ($compose_new_win == '1') {
528 compose_Header($color, $mailbox);
530 displayPageHeader($color, $mailbox);
535 if (!isset($passed_ent_id)) {
538 if (!isset($passed_id)) {
541 if (!isset($mailbox)) {
544 if (!isset($action)) {
548 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
550 /* in case the origin is not read_body.php */
551 if (isset($send_to)) {
552 $values['send_to'] = $send_to;
554 if (isset($send_to_cc)) {
555 $values['send_to_cc'] = $send_to_cc;
557 if (isset($send_to_bcc)) {
558 $values['send_to_bcc'] = $send_to_bcc;
560 if (isset($subject)) {
561 $values['subject'] = $subject;
563 showInputForm($session, $values);
568 /**************** Only function definitions go below *************/
570 function getforwardSubject($subject)
572 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
573 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
574 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
575 $subject = '[Fwd: ' . $subject . ']';
580 /* This function is used when not sending or adding attachments */
581 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
582 global $editor_size, $default_use_priority, $body, $idents,
583 $use_signature, $composesession, $data_dir, $username,
584 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
585 $composeMessage, $body_quote;
586 global $languages, $squirrelmail_language, $default_charset;
589 * Set $default_charset to correspond with the user's selection
590 * of language interface. $default_charset global is not correct,
591 * if message is composed in new window.
595 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
599 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
602 sqimap_mailbox_select($imapConnection, $mailbox);
603 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
606 if ($passed_ent_id) {
607 /* redefine the messsage in case of message/rfc822 */
608 $message = $message->getEntity($passed_ent_id);
609 /* message is an entity which contains the envelope and type0=message
610 * and type1=rfc822. The actual entities are childs from
611 * $message->entities[0]. That's where the encoding and is located
614 $entities = $message->entities
[0]->findDisplayEntity
615 (array(), $alt_order = array('text/plain'));
616 if (!count($entities)) {
617 $entities = $message->entities
[0]->findDisplayEntity
618 (array(), $alt_order = array('text/plain','html/plain'));
620 $orig_header = $message->rfc822_header
; /* here is the envelope located */
621 /* redefine the message for picking up the attachments */
622 $message = $message->entities
[0];
625 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
626 if (!count($entities)) {
627 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
629 $orig_header = $message->rfc822_header
;
632 $encoding = $message->header
->encoding
;
633 $type0 = $message->type0
;
634 $type1 = $message->type1
;
635 foreach ($entities as $ent) {
636 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
637 $body_part_entity = $message->getEntity($ent);
638 $bodypart = decodeBody($unencoded_bodypart,
639 $body_part_entity->header
->encoding
);
640 if ($type1 == 'html') {
641 $bodypart = str_replace("\n", ' ', $bodypart);
642 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
643 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
644 $bodypart = strip_tags($bodypart);
647 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
648 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
649 if (mb_detect_encoding($bodypart) != 'ASCII') {
650 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
654 if (isset($body_part_entity->header
->parameters
['charset'])) {
655 $actual = $body_part_entity->header
->parameters
['charset'];
657 $actual = 'us-ascii';
660 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
661 $bodypart = charset_convert($actual,$bodypart,$default_charset);
666 if ($default_use_priority) {
667 $mailprio = substr($orig_header->priority
,0,1);
674 //ClearAttachments($session);
677 $from_o = $orig_header->from
;
678 if (is_array($from_o)) {
679 if (isset($from_o[0])) {
680 $from_o = $from_o[0];
683 if (is_object($from_o)) {
684 $orig_from = $from_o->getAddress();
689 $identities = array();
690 if (count($idents) > 1) {
691 foreach($idents as $nr=>$data) {
692 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
693 if($enc_from_name == $orig_from) {
697 $identities[] = $enc_from_name;
700 $identity_match = $orig_header->findAddress($identities);
701 if ($identity_match) {
702 $identity = $identity_match;
708 $use_signature = FALSE;
709 $composeMessage->rfc822_header
= $orig_header;
710 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
711 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
712 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
713 $send_from = $orig_header->getAddr_s('from');
714 $send_from_parts = new AddressStructure();
715 $send_from_parts = $orig_header->parseAddress($send_from);
716 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
717 $identities = get_identities();
718 if (count($identities) > 0) {
719 foreach($identities as $iddata) {
720 if ($send_from_add == $iddata['email_address']) {
721 $identity = $iddata['index'];
726 $subject = decodeHeader($orig_header->subject
,false,false,true);
727 // /* remember the references and in-reply-to headers in case of an reply */
728 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
729 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
730 $body_ary = explode("\n", $body);
731 $cnt = count($body_ary) ;
733 for ($i=0; $i < $cnt; $i++
) {
734 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
735 sqWordWrap($body_ary[$i], $editor_size );
736 $body .= $body_ary[$i] . "\n";
738 unset($body_ary[$i]);
741 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
743 case ('edit_as_new'):
744 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
745 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
746 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
747 $subject = decodeHeader($orig_header->subject
,false,false,true);
748 $mailprio = $orig_header->priority
;
750 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
755 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
756 $body = getforwardHeader($orig_header) . $body;
758 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
759 $body = "\n" . $body;
761 case ('forward_as_attachment'):
762 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
763 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
767 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
768 $send_to = $orig_header->getAddr_s('mail_followup_to');
770 $send_to_cc = replyAllString($orig_header);
771 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
774 // skip this if send_to was already set right above here
776 $send_to = $orig_header->reply_to
;
777 if (is_array($send_to) && count($send_to)) {
778 $send_to = $orig_header->getAddr_s('reply_to');
779 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
780 $send_to = $orig_header->getAddr_s('reply_to');
782 $send_to = $orig_header->getAddr_s('from');
785 $send_to = decodeHeader($send_to,false,false,true);
786 $subject = decodeHeader($orig_header->subject
,false,false,true);
787 $subject = str_replace('"', "'", $subject);
788 $subject = trim($subject);
789 if (substr(strtolower($subject), 0, 3) != 're:') {
790 $subject = 'Re: ' . $subject;
792 /* this corrects some wrapping/quoting problems on replies */
793 $rewrap_body = explode("\n", $body);
794 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
796 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
797 foreach ($rewrap_body as $line) {
798 if ($strip_sigs && substr($line,0,3) == '-- ') {
801 if (preg_match("/^(>+)/", $line, $matches)) {
803 $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n";
805 $body .= $body_quote . (!empty($body_quote) ?
' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ?
' ' : ''), rtrim($line)) . "\n";
809 //rewrap the body to clean up quotations and line lengths
810 $body = sqBodyWrap ($body, $editor_size);
812 $body = getReplyCitation($from , $orig_header->date
) . $body;
813 $composeMessage->reply_rfc822_header
= $orig_header;
819 $compose_messages[$session] = $composeMessage;
820 sqsession_register($compose_messages, 'compose_messages');
821 session_write_close();
822 sqimap_logout($imapConnection);
824 $ret = array( 'send_to' => $send_to,
825 'send_to_cc' => $send_to_cc,
826 'send_to_bcc' => $send_to_bcc,
827 'subject' => $subject,
828 'mailprio' => $mailprio,
830 'identity' => $identity );
833 } /* function newMail() */
835 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
836 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
837 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
838 if (!count($message->entities
) ||
839 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
840 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
841 switch ($message->type0
) {
843 if ($message->type1
== 'rfc822') {
844 $filename = $message->rfc822_header
->subject
;
845 if ($filename == "") {
846 $filename = "untitled-".$message->entity_id
;
850 $filename = $message->getFilename();
854 if (!$message->mime_header
) { /* temporary hack */
855 $message->mime_header
= $message->header
;
857 $filename = $message->getFilename();
860 $filename = str_replace(' ', ' ', decodeHeader($filename));
861 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
862 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
863 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
865 $localfilename = GenerateRandomString(32, '', 7);
866 $full_localfilename = "$hashed_attachment_dir/$localfilename";
867 while (file_exists($full_localfilename)) {
868 $localfilename = GenerateRandomString(32, '', 7);
869 $full_localfilename = "$hashed_attachment_dir/$localfilename";
871 $message->att_local_name
= $full_localfilename;
873 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
874 $full_localfilename);
876 /* Write Attachment to file */
877 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
878 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
879 $passed_id, $message->entity_id
),
880 $message->header
->encoding
));
884 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
885 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
888 return $composeMessage;
891 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
892 $passed_ent_id='', $imapConnection) {
893 global $attachments, $attachment_dir, $username, $data_dir;
894 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
895 if (!$passed_ent_id) {
896 $body_a = sqimap_run_command($imapConnection,
897 'FETCH '.$passed_id.' RFC822',
898 TRUE, $response, $readmessage,
901 $body_a = sqimap_run_command($imapConnection,
902 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
903 TRUE, $response, $readmessage, TRUE);
904 $message = $message->parent
;
906 if ($response == 'OK') {
907 $subject = encodeHeader($message->rfc822_header
->subject
);
908 array_shift($body_a);
910 $body = implode('', $body_a) . "\r\n";
912 $localfilename = GenerateRandomString(32, 'FILE', 7);
913 $full_localfilename = "$hashed_attachment_dir/$localfilename";
915 $fp = fopen($full_localfilename, 'w');
918 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
919 $full_localfilename);
921 return $composeMessage;
924 function showInputForm ($session, $values=false) {
925 global $send_to, $send_to_cc, $body, $startMessage,
926 $passed_body, $color, $use_signature, $signature, $prefix_sig,
927 $editor_size, $editor_height, $attachments, $subject, $newmail,
928 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
929 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
930 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
931 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
932 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
933 $username, $compose_messages, $composesession, $default_charset;
935 $composeMessage = $compose_messages[$session];
937 $send_to = $values['send_to'];
938 $send_to_cc = $values['send_to_cc'];
939 $send_to_bcc = $values['send_to_bcc'];
940 $subject = $values['subject'];
941 $mailprio = $values['mailprio'];
942 $body = $values['body'];
943 $identity = (int) $values['identity'];
945 $send_to = decodeHeader($send_to, true, false);
946 $send_to_cc = decodeHeader($send_to_cc, true, false);
947 $send_to_bcc = decodeHeader($send_to_bcc, true, false);
950 if ($use_javascript_addr_book) {
951 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
952 'function open_abook() { ' . "\n" .
953 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
954 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
955 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
956 ' nwin.opener = document.windows;' . "\n" .
958 "// -->\n</SCRIPT>\n\n";
961 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
962 'enctype="multipart/form-data"';
963 do_hook('compose_form');
967 echo addHidden('startMessage', $startMessage);
969 if ($action == 'draft') {
970 echo addHidden('delete_draft', $passed_id);
972 if (isset($delete_draft)) {
973 echo addHidden('delete_draft', $delete_draft);
975 if (isset($session)) {
976 echo addHidden('session', $session);
979 if (isset($passed_id)) {
980 echo addHidden('passed_id', $passed_id);
983 if ($saved_draft == 'yes') {
984 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
986 if ($mail_sent == 'yes') {
987 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
989 echo '<table align="center" cellspacing="0" border="0">' . "\n";
990 if ($compose_new_win == '1') {
991 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
992 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
994 if ($location_of_buttons == 'top') {
995 showComposeButtonRow();
998 /* display select list for identities */
999 if (count($idents) > 1) {
1000 $ident_list = array();
1001 foreach($idents as $id => $data) {
1003 $data['full_name'].' <'.$data['email_address'].'>';
1005 echo ' <tr>' . "\n" .
1006 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1007 _("From:") . '</td>' . "\n" .
1008 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1010 addSelect('identity', $ident_list, $identity, TRUE);
1012 echo ' </td>' . "\n" .
1016 echo ' <tr>' . "\n" .
1017 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1018 _("To:") . '</TD>' . "\n" .
1019 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1020 addInput('send_to', $send_to, 60). '<br />' . "\n" .
1024 html_tag( 'td', '', 'right', $color[4] ) .
1025 _("CC:") . '</td>' . "\n" .
1026 html_tag( 'td', '', 'left', $color[4] ) .
1027 addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
1031 html_tag( 'td', '', 'right', $color[4] ) .
1032 _("BCC:") . '</td>' . "\n" .
1033 html_tag( 'td', '', 'left', $color[4] ) .
1034 addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
1038 html_tag( 'td', '', 'right', $color[4] ) .
1039 _("Subject:") . '</td>' . "\n" .
1040 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1041 echo ' '.addInput('subject', $subject, 60).
1045 if ($location_of_buttons == 'between') {
1046 showComposeButtonRow();
1049 /* why this distinction? */
1050 if ($compose_new_win == '1') {
1051 echo ' <TR>' . "\n" .
1052 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1053 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1054 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1057 echo ' <TR>' . "\n" .
1058 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1059 ' <TEXTAREA NAME="body" ID="body" ROWS="' . (int)$editor_height .
1060 '" COLS="' . (int)$editor_size . '" WRAP="VIRTUAL">';
1063 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1064 $signature = $idents[$identity]['signature'];
1066 if ($sig_first == '1') {
1067 if ($default_charset == 'iso-2022-jp') {
1068 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1070 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1072 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1075 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1076 if ($default_charset == 'iso-2022-jp') {
1077 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1079 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1084 echo htmlspecialchars(decodeHeader($body,false,false));
1086 echo '</textarea><br />' . "\n" .
1091 if ($location_of_buttons == 'bottom') {
1092 showComposeButtonRow();
1094 echo ' <tr>' . "\n" .
1095 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1096 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1097 ' <br /><br />' . "\n" .
1102 /* This code is for attachments */
1103 if ((bool) ini_get('file_uploads')) {
1105 /* Calculate the max size for an uploaded file.
1106 * This is advisory for the user because we can't actually prevent
1107 * people to upload too large files. */
1109 /* php.ini vars which influence the max for uploads */
1110 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1111 foreach($configvars as $var) {
1112 /* skip 0 or empty values */
1113 if( $size = getByteSize(ini_get($var)) ) {
1118 if(count($sizes) > 0) {
1119 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1123 echo addHidden('MAX_FILE_SIZE', min( $sizes ));
1124 echo ' <tr>' . "\n" .
1125 ' <td colspan="2">' . "\n" .
1126 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1127 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1130 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1131 ' border="0">' . "\n" .
1133 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1134 _("Attach:") . '</td>' . "\n" .
1135 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1136 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1137 ' <input type="submit" name="attach"' .
1138 ' value="' . _("Add") .'">' . "\n" .
1145 if ($composeMessage->entities
) {
1146 foreach ($composeMessage->entities
as $key => $attachment) {
1147 $attached_file = $attachment->att_local_name
;
1148 if ($attachment->att_local_name ||
$attachment->body_part
) {
1149 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1150 $type = $attachment->mime_header
->type0
.'/'.
1151 $attachment->mime_header
->type1
;
1153 $s_a[] = '<table bgcolor="'.$color[0].
1154 '" border="0"><tr><td>'.
1155 addCheckBox('delete[]', FALSE, $key).
1156 "</td><td>\n" . $attached_filename .
1157 '</td><td>-</td><td> ' . $type . '</td><td>('.
1158 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1163 foreach ($s_a as $s) {
1164 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1166 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1167 _("Delete selected attachments") . "\">\n" .
1170 echo ' </table>' . "\n" .
1173 ' </TABLE>' . "\n" .
1176 } // End of file_uploads if-block
1177 /* End of attachment code */
1178 if ($compose_new_win == '1') {
1179 echo '</TABLE>'."\n";
1182 echo '</TABLE>' . "\n" .
1183 addHidden('username', $username).
1184 addHidden('smaction', $action).
1185 addHidden('mailbox', $mailbox);
1187 store the complete ComposeMessages array in a hidden input value
1188 so we can restore them in case of a session timeout.
1190 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1191 echo addHidden('restoremessages', serialize($compose_messages)).
1192 addHidden('composesession', $composesession).
1193 addHidden('querystring', $queryString).
1195 if (!(bool) ini_get('file_uploads')) {
1196 /* File uploads are off, so we didn't show that part of the form.
1197 To avoid bogus bug reports, tell the user why. */
1198 echo 'Because PHP file uploads are turned off, you can not attach files ';
1199 echo "to this message. Please see your system administrator for details.\r\n";
1202 do_hook('compose_bottom');
1203 echo '</BODY></HTML>' . "\n";
1207 function showComposeButtonRow() {
1208 global $use_javascript_addr_book, $save_as_draft,
1209 $default_use_priority, $mailprio, $default_use_mdn,
1210 $request_mdn, $request_dr,
1211 $data_dir, $username;
1213 echo ' <TR>' . "\n" .
1214 ' <TD></TD>' . "\n" .
1216 if ($default_use_priority) {
1217 if(!isset($mailprio)) {
1220 echo ' ' . _("Priority") .
1221 addSelect('mailprio', array(
1224 '5' => _("Low") ), $mailprio, TRUE);
1226 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1227 if ($default_use_mdn) {
1228 if ($mdn_user_support) {
1229 echo ' ' . _("Receipt") .': '.
1230 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1231 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1235 echo ' </TD>' . "\n" .
1238 ' <TD></TD>' . "\n" .
1240 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1241 if ($use_javascript_addr_book) {
1242 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1243 " <input type=button value=\\\""._("Addresses").
1244 "\\\" onclick='javascript:open_abook();'>\");".
1245 " // --></SCRIPT><NOSCRIPT>\n".
1246 " <input type=submit name=\"html_addr_search\" value=\"".
1247 _("Addresses")."\">".
1250 echo ' <input type=submit name="html_addr_search" value="'.
1251 _("Addresses").'">' . "\n";
1254 if ($save_as_draft) {
1255 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1258 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1259 do_hook('compose_button_row');
1261 echo ' </TD>' . "\n" .
1265 function checkInput ($show) {
1267 * I implemented the $show variable because the error messages
1268 * were getting sent before the page header. So, I check once
1269 * using $show=false, and then when i'm ready to display the error
1270 * message, show=true
1272 global $body, $send_to, $send_to_bcc, $subject, $color;
1274 if ($send_to == '' && $send_to_bcc == '') {
1276 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1281 } /* function checkInput() */
1284 /* True if FAILURE */
1285 function saveAttachedFiles($session) {
1286 global $_FILES, $attachment_dir, $attachments, $username,
1287 $data_dir, $compose_messages;
1289 /* get out of here if no file was attached at all */
1290 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1294 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1295 $localfilename = GenerateRandomString(32, '', 7);
1296 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1297 while (file_exists($full_localfilename)) {
1298 $localfilename = GenerateRandomString(32, '', 7);
1299 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1302 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1303 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1304 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1305 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1309 $message = $compose_messages[$session];
1310 $type = strtolower($_FILES['attachfile']['type']);
1311 $name = $_FILES['attachfile']['name'];
1312 $message->initAttachment($type, $name, $full_localfilename);
1313 $compose_messages[$session] = $message;
1314 sqsession_register($compose_messages , 'compose_messages');
1317 function ClearAttachments($composeMessage) {
1318 if ($composeMessage->att_local_name
) {
1319 $attached_file = $composeMessage->att_local_name
;
1320 if (file_exists($attached_file)) {
1321 unlink($attached_file);
1324 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1325 ClearAttachments($composeMessage->entities
[$i]);
1329 /* parse values like 8M and 2k into bytes */
1330 function getByteSize($ini_size) {
1336 $ini_size = trim($ini_size);
1338 // if there's some kind of letter at the end of the string we need to multiply.
1339 if(!is_numeric(substr($ini_size, -1))) {
1341 switch(strtoupper(substr($ini_size, -1))) {
1343 $bytesize = 1073741824;
1346 $bytesize = 1048576;
1353 return ($bytesize * (int)substr($ini_size, 0, -1));
1360 /* temporary function to make use of the deliver class.
1361 In the future the responsable backend should be automaticly loaded
1362 and conf.pl should show a list of available backends.
1363 The message also should be constructed by the message class.
1366 function deliverMessage($composeMessage, $draft=false) {
1367 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1368 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1369 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1370 $domain, $action, $default_move_to_sent, $move_to_sent;
1371 global $imapServerAddress, $imapPort, $sent_folder, $key;
1373 $rfc822_header = $composeMessage->rfc822_header
;
1375 $abook = addressbook_init(false, true);
1376 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1377 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1378 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1379 $rfc822_header->priority
= $mailprio;
1380 $rfc822_header->subject
= $subject;
1382 $special_encoding='';
1383 if (strtolower($default_charset) == 'iso-2022-jp') {
1384 if (mb_detect_encoding($body) == 'ASCII') {
1385 $special_encoding = '8bit';
1387 $body = mb_convert_encoding($body, 'JIS');
1388 $special_encoding = '7bit';
1391 $composeMessage->setBody($body);
1393 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1394 $popuser = $usernamedata[1];
1395 $domain = $usernamedata[2];
1396 unset($usernamedata);
1398 $popuser = $username;
1401 $from_mail = $idents[$identity]['email_address'];
1402 $full_name = $idents[$identity]['full_name'];
1403 $reply_to = $idents[$identity]['reply_to'];
1405 $from_mail = "$popuser@$domain";
1407 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1409 $from = $rfc822_header->from
[0];
1410 if (!$from->host
) $from->host
= $domain;
1411 $full_name_encoded = encodeHeader($full_name);
1412 if ($full_name_encoded != $full_name) {
1413 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1415 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1417 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1420 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1422 /* Receipt: On Read */
1423 if (isset($request_mdn) && $request_mdn) {
1424 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1426 /* Receipt: On Delivery */
1427 if (isset($request_dr) && $request_dr) {
1428 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1430 /* multipart messages */
1431 if (count($composeMessage->entities
)) {
1432 $message_body = new Message();
1433 $message_body->body_part
= $composeMessage->body_part
;
1434 $composeMessage->body_part
= '';
1435 $mime_header = new MessageHeader
;
1436 $mime_header->type0
= 'text';
1437 $mime_header->type1
= 'plain';
1438 if ($special_encoding) {
1439 $mime_header->encoding
= $special_encoding;
1441 $mime_header->encoding
= '8bit';
1443 if ($default_charset) {
1444 $mime_header->parameters
['charset'] = $default_charset;
1446 $message_body->mime_header
= $mime_header;
1447 array_unshift($composeMessage->entities
, $message_body);
1448 $content_type = new ContentType('multipart/mixed');
1450 $content_type = new ContentType('text/plain');
1451 if ($special_encoding) {
1452 $rfc822_header->encoding
= $special_encoding;
1454 $rfc822_header->encoding
= '8bit';
1456 if ($default_charset) {
1457 $content_type->properties
['charset']=$default_charset;
1461 $rfc822_header->content_type
= $content_type;
1462 $composeMessage->rfc822_header
= $rfc822_header;
1464 /* Here you can modify the message structure just before we hand
1465 it over to deliver */
1466 $hookReturn = do_hook('compose_send', $composeMessage);
1467 /* Get any changes made by plugins to $composeMessage. */
1468 if ( is_object($hookReturn[1]) ) {
1469 $composeMessage = $hookReturn[1];
1472 if (!$useSendmail && !$draft) {
1473 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1474 $deliver = new Deliver_SMTP();
1475 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1477 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1478 get_smtp_user($user, $pass);
1479 $stream = $deliver->initStream($composeMessage,$domain,0,
1480 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1481 } elseif (!$draft) {
1482 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1483 global $sendmail_path;
1484 $deliver = new Deliver_SendMail();
1485 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1487 global $draft_folder;
1488 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1489 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1491 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1492 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1493 $imap_deliver = new Deliver_IMAP();
1494 $length = $imap_deliver->mail($composeMessage);
1495 sqimap_append ($imap_stream, $draft_folder, $length);
1496 $imap_deliver->mail($composeMessage, $imap_stream);
1497 sqimap_append_done ($imap_stream, $draft_folder);
1498 sqimap_logout($imap_stream);
1499 unset ($imap_deliver);
1502 $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
1503 plain_error_message($msg, $color);
1509 $length = $deliver->mail($composeMessage, $stream);
1510 $succes = $deliver->finalizeStream($stream);
1513 $msg = $deliver->dlv_msg
. '<br />' .
1514 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1515 $deliver->dlv_server_msg
;
1516 plain_error_message($msg, $color);
1519 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1520 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1522 /* Move to sent code */
1523 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1524 $svr_allow_sent = true;
1526 $svr_allow_sent = false;
1529 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1530 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1536 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1537 $lcl_allow_sent = true;
1539 $lcl_allow_sent = false;
1542 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1543 global $passed_id, $mailbox, $action;
1544 if ($action == 'reply' ||
$action == 'reply_all') {
1545 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1546 if ($save_reply_with_orig) {
1547 $sent_folder = $mailbox;
1550 sqimap_append ($imap_stream, $sent_folder, $length);
1551 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1552 $imap_deliver = new Deliver_IMAP();
1553 $imap_deliver->mail($composeMessage, $imap_stream);
1554 sqimap_append_done ($imap_stream, $sent_folder);
1555 unset ($imap_deliver);
1557 global $passed_id, $mailbox, $action;
1558 ClearAttachments($composeMessage);
1559 if ($action == 'reply' ||
$action == 'reply_all') {
1560 sqimap_mailbox_select ($imap_stream, $mailbox);
1561 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1563 sqimap_logout($imap_stream);