d780f225a2a6364ba0f84bd31893608e5f41d103
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 if (isset($header->replyto
)) {
122 $excl_ar = $header->getAddr_a('replyto');
125 * 2) Remove our identities from the CC list (they still can be in the
126 * TO list) only if $include_self_reply_all is turned off
128 if (!$include_self_reply_all) {
129 foreach($idents as $id) {
130 $excl_ar[strtolower(trim($id['email_address']))] = '';
135 * 3) get the addresses.
137 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
140 * 4) generate the string.
142 $url_replytoallcc = '';
143 foreach( $url_replytoall_ar as $email => $personal) {
145 // if personal name contains address separator then surround
146 // the personal name with double quotes.
147 if (strpos($personal,',') !== false) {
148 $personal = '"'.$personal.'"';
150 $url_replytoallcc .= ", $personal <$email>";
152 $url_replytoallcc .= ', '. $email;
155 $url_replytoallcc = substr($url_replytoallcc,2);
157 return $url_replytoallcc;
160 function getReplyCitation($orig_from, $orig_date) {
161 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
162 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
163 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
164 /* First, return an empty string when no citation style selected. */
165 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
169 /* Make sure our final value isn't an empty string. */
170 if ($orig_from == '') {
174 /* Otherwise, try to select the desired citation style. */
175 switch ($reply_citation_style) {
178 $end = ' ' . _("said") . ':';
181 $start = '<' . _("quote") . ' ' . _("who") . '="';
184 case 'date_time_author':
185 $start = 'On ' . getLongDateString($orig_date) . ', ';
186 $end = ' ' . _("said") . ':';
189 $start = $reply_citation_start .
190 ($reply_citation_start == '' ?
'' : ' ');
191 $end = $reply_citation_end;
197 /* Build and return the citation string. */
198 return ($start . $orig_from . $end . "\n");
201 function getforwardHeader($orig_header) {
204 $display = array( _("Subject") => strlen(_("Subject")),
205 _("From") => strlen(_("From")),
206 _("Date") => strlen(_("Date")),
207 _("To") => strlen(_("To")),
208 _("Cc") => strlen(_("Cc")) );
209 $maxsize = max($display);
210 $indent = str_pad('',$maxsize+
2);
211 foreach($display as $key => $val) {
212 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
214 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
215 $from = str_replace(' ',' ',$from);
216 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
217 $to = str_replace(' ',' ',$to);
218 $subject = decodeHeader($orig_header->subject
,false,false,true);
219 $subject = str_replace(' ',' ',$subject);
220 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
221 "\n". $display[_("Subject")] . $subject . "\n" .
222 $display[_("From")] . $from . "\n" .
223 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
224 $display[_("To")] . $to . "\n";
225 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
226 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
227 $cc = str_replace(' ',' ',$cc);
228 $bodyTop .= $display[_("Cc")] .$cc . "\n";
230 $bodyTop .= str_pad('', $editor_size -2 , '-') .
234 /* ----------------------------------------------------------------------- */
237 * If the session is expired during a post this restores the compose session
240 if (sqsession_is_registered('session_expired_post')) {
241 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
243 * extra check for username so we don't display previous post data from
244 * another user during this session.
246 if ($session_expired_post['username'] != $username) {
247 unset($session_expired_post);
248 sqsession_unregister('session_expired_post');
249 session_write_close();
251 foreach ($session_expired_post as $postvar => $val) {
258 $compose_messages = unserialize(urldecode($restoremessages));
259 sqsession_register($compose_messages,'compose_messages');
260 sqsession_register($composesession,'composesession');
264 $session_expired = true;
266 unset($session_expired_post);
267 sqsession_unregister('session_expired_post');
268 session_write_close();
269 if (!isset($mailbox)) {
272 if ($compose_new_win == '1') {
273 compose_Header($color, $mailbox);
275 displayPageHeader($color, $mailbox);
277 showInputForm($session, false);
280 if (!isset($composesession)) {
282 sqsession_register(0,'composesession');
285 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
286 sqsession_unregister('composesession');
287 $session = "$composesession" +
1;
288 $composesession = $session;
289 sqsession_register($composesession,'composesession');
291 if (!isset($compose_messages)) {
292 $compose_messages = array();
294 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
295 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
296 $composeMessage = new Message();
297 $rfc822_header = new Rfc822Header();
298 $composeMessage->rfc822_header
= $rfc822_header;
299 $composeMessage->reply_rfc822_header
= '';
300 $compose_messages[$session] = $composeMessage;
301 sqsession_register($compose_messages,'compose_messages');
303 $composeMessage=$compose_messages[$session];
306 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
312 * Set $default_charset to correspond with the user's selection
313 * of language interface.
316 $composeMessage=$compose_messages[$session];
317 if (! deliverMessage($composeMessage, true)) {
318 showInputForm($session);
321 unset($compose_messages[$session]);
322 $draft_message = _("Draft Email Saved");
323 /* If this is a resumed draft, then delete the original */
324 if(isset($delete_draft)) {
325 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
326 "&message=$delete_draft&startMessage=1&saved_draft=yes");
330 if ($compose_new_win == '1') {
331 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
335 Header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
336 "&startMessage=1¬e=".urlencode($draft_message));
344 if (isset($_FILES['attachfile']) &&
345 $_FILES['attachfile']['tmp_name'] &&
346 $_FILES['attachfile']['tmp_name'] != 'none') {
347 $AttachFailure = saveAttachedFiles($session);
349 if (checkInput(false) && !isset($AttachFailure)) {
350 if ($mailbox == "All Folders") {
351 /* We entered compose via the search results page */
352 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
354 $urlMailbox = urlencode (trim($mailbox));
355 if (! isset($passed_id)) {
359 * Set $default_charset to correspond with the user's selection
360 * of language interface.
364 * This is to change all newlines to \n
365 * We'll change them to \r\n later (in the sendMessage function)
367 $body = str_replace("\r\n", "\n", $body);
368 $body = str_replace("\r", "\n", $body);
371 * Rewrap $body so that no line is bigger than $editor_size
373 $body = explode("\n", $body);
375 foreach ($body as $line) {
376 if( $line <> '-- ' ) {
377 $line = rtrim($line);
379 if (strlen($line) <= $editor_size +
1) {
380 $newBody .= $line . "\n";
382 sqWordWrap($line, $editor_size);
383 $newBody .= $line . "\n";
390 $composeMessage=$compose_messages[$session];
392 $Result = deliverMessage($composeMessage);
394 showInputForm($session);
397 unset($compose_messages[$session]);
398 if ( isset($delete_draft)) {
399 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
400 "&message=$delete_draft&startMessage=1&mail_sent=yes");
403 if ($compose_new_win == '1') {
405 Header("Location: $location/compose.php?mail_sent=yes");
408 Header("Location: $location/right_main.php?mailbox=$urlMailbox".
409 "&startMessage=$startMessage&mail_sent=yes");
412 if ($compose_new_win == '1') {
413 compose_Header($color, $mailbox);
416 displayPageHeader($color, $mailbox);
418 if (isset($AttachFailure)) {
419 plain_error_message(_("Could not move/copy file. File not attached"),
423 showInputForm($session);
424 /* sqimap_logout($imapConnection); */
426 } elseif (isset($html_addr_search_done)) {
427 if ($compose_new_win == '1') {
428 compose_Header($color, $mailbox);
431 displayPageHeader($color, $mailbox);
434 if (isset($send_to_search) && is_array($send_to_search)) {
435 foreach ($send_to_search as $k => $v) {
436 if (substr($k, 0, 1) == 'T') {
442 elseif (substr($k, 0, 1) == 'C') {
448 elseif (substr($k, 0, 1) == 'B') {
450 $send_to_bcc .= ', ';
456 showInputForm($session);
457 } elseif (isset($html_addr_search)) {
458 if (isset($_FILES['attachfile']) &&
459 $_FILES['attachfile']['tmp_name'] &&
460 $_FILES['attachfile']['tmp_name'] != 'none') {
461 if(saveAttachedFiles($session)) {
462 plain_error_message(_("Could not move/copy file. File not attached"), $color);
466 * I am using an include so as to elminiate an extra unnecessary
467 * click. If you can think of a better way, please implement it.
469 include_once('./addrbook_search_html.php');
470 } elseif (isset($attach)) {
471 if (saveAttachedFiles($session)) {
472 plain_error_message(_("Could not move/copy file. File not attached"), $color);
474 if ($compose_new_win == '1') {
475 compose_Header($color, $mailbox);
477 displayPageHeader($color, $mailbox);
479 showInputForm($session);
481 elseif (isset($sigappend)) {
482 $signature = $idents[$identity]['signature'];
484 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
485 if ($compose_new_win == '1') {
486 compose_Header($color, $mailbox);
488 displayPageHeader($color, $mailbox);
490 showInputForm($session);
491 } elseif (isset($do_delete)) {
492 if ($compose_new_win == '1') {
493 compose_Header($color, $mailbox);
495 displayPageHeader($color, $mailbox);
498 if (isset($delete) && is_array($delete)) {
499 $composeMessage = $compose_messages[$session];
500 foreach($delete as $index) {
501 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
502 unlink ($attached_file);
503 unset ($composeMessage->entities
[$index]);
505 $new_entities = array();
506 foreach ($composeMessage->entities
as $entity) {
507 $new_entities[] = $entity;
509 $composeMessage->entities
= $new_entities;
510 $compose_messages[$session] = $composeMessage;
511 sqsession_register($compose_messages, 'compose_messages');
513 showInputForm($session);
516 * This handles the default case as well as the error case
517 * (they had the same code) --> if (isset($smtpErrors))
520 if ($compose_new_win == '1') {
521 compose_Header($color, $mailbox);
523 displayPageHeader($color, $mailbox);
528 if (!isset($passed_ent_id)) {
531 if (!isset($passed_id)) {
534 if (!isset($mailbox)) {
537 if (!isset($action)) {
541 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
543 /* in case the origin is not read_body.php */
544 if (isset($send_to)) {
545 $values['send_to'] = $send_to;
547 if (isset($send_to_cc)) {
548 $values['send_to_cc'] = $send_to_cc;
550 if (isset($send_to_bcc)) {
551 $values['send_to_bcc'] = $send_to_bcc;
553 if (isset($subject)) {
554 $values['subject'] = $subject;
556 showInputForm($session, $values);
561 /**************** Only function definitions go below *************/
563 function getforwardSubject($subject)
565 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
566 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
567 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
568 $subject = '[Fwd: ' . $subject . ']';
573 /* This function is used when not sending or adding attachments */
574 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
575 global $editor_size, $default_use_priority, $body, $idents,
576 $use_signature, $data_dir, $username,
577 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
578 $composeMessage, $body_quote;
579 global $languages, $squirrelmail_language, $default_charset;
582 * Set $default_charset to correspond with the user's selection
583 * of language interface. $default_charset global is not correct,
584 * if message is composed in new window.
588 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
592 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
595 sqimap_mailbox_select($imapConnection, $mailbox);
596 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
599 if ($passed_ent_id) {
600 /* redefine the messsage in case of message/rfc822 */
601 $message = $message->getEntity($passed_ent_id);
602 /* message is an entity which contains the envelope and type0=message
603 * and type1=rfc822. The actual entities are childs from
604 * $message->entities[0]. That's where the encoding and is located
607 $entities = $message->entities
[0]->findDisplayEntity
608 (array(), $alt_order = array('text/plain'));
609 if (!count($entities)) {
610 $entities = $message->entities
[0]->findDisplayEntity
611 (array(), $alt_order = array('text/plain','html/plain'));
613 $orig_header = $message->rfc822_header
; /* here is the envelope located */
614 /* redefine the message for picking up the attachments */
615 $message = $message->entities
[0];
618 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
619 if (!count($entities)) {
620 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
622 $orig_header = $message->rfc822_header
;
625 $type0 = $message->type0
;
626 $type1 = $message->type1
;
627 foreach ($entities as $ent) {
628 $msg = $message->getEntity($ent);
629 $type0 = $msg->type0
;
630 $type1 = $msg->type1
;
631 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
632 $body_part_entity = $message->getEntity($ent);
633 $bodypart = decodeBody($unencoded_bodypart,
634 $body_part_entity->header
->encoding
);
635 if ($type1 == 'html') {
636 $bodypart = str_replace("\n", ' ', $bodypart);
637 $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
638 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
639 $bodypart = strip_tags($bodypart);
641 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
642 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
643 if (mb_detect_encoding($bodypart) != 'ASCII') {
644 $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart);
648 if (isset($body_part_entity->header
->parameters
['charset'])) {
649 $actual = $body_part_entity->header
->parameters
['charset'];
651 $actual = 'us-ascii';
654 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
655 $bodypart = charset_convert($actual,$bodypart,$default_charset,false);
660 if ($default_use_priority) {
661 $mailprio = substr($orig_header->priority
,0,1);
668 //ClearAttachments($session);
671 $from_o = $orig_header->from
;
672 if (is_array($from_o)) {
673 if (isset($from_o[0])) {
674 $from_o = $from_o[0];
677 if (is_object($from_o)) {
678 $orig_from = $from_o->getAddress();
683 $identities = array();
684 if (count($idents) > 1) {
685 foreach($idents as $nr=>$data) {
686 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
687 if($enc_from_name == $orig_from) {
691 $identities[] = $enc_from_name;
694 $identity_match = $orig_header->findAddress($identities);
695 if ($identity_match) {
696 $identity = $identity_match;
702 $use_signature = FALSE;
703 $composeMessage->rfc822_header
= $orig_header;
704 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
705 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
706 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
707 $send_from = $orig_header->getAddr_s('from');
708 $send_from_parts = new AddressStructure();
709 $send_from_parts = $orig_header->parseAddress($send_from);
710 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
711 $identities = get_identities();
712 if (count($identities) > 0) {
713 foreach($identities as $iddata) {
714 if ($send_from_add == $iddata['email_address']) {
715 $identity = $iddata['index'];
720 $subject = decodeHeader($orig_header->subject
,false,false,true);
721 /* remember the references and in-reply-to headers in case of an reply */
722 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
723 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
724 // rewrap the body to clean up quotations and line lengths
725 sqBodyWrap($body, $editor_size);
726 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
728 case ('edit_as_new'):
729 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
730 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
731 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
732 $subject = decodeHeader($orig_header->subject
,false,false,true);
733 $mailprio = $orig_header->priority
;
735 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
736 // rewrap the body to clean up quotations and line lengths
737 sqBodyWrap($body, $editor_size);
741 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
742 $body = getforwardHeader($orig_header) . $body;
743 // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines
744 // forwarded message text should be as undisturbed as possible, so commenting out this call
745 // sqUnWordWrap($body);
746 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
747 //add a blank line after the forward headers
748 $body = "\n" . $body;
750 case ('forward_as_attachment'):
751 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
752 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
756 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
757 $send_to = $orig_header->getAddr_s('mail_followup_to');
759 $send_to_cc = replyAllString($orig_header);
760 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
763 // skip this if send_to was already set right above here
765 $send_to = $orig_header->reply_to
;
766 if (is_array($send_to) && count($send_to)) {
767 $send_to = $orig_header->getAddr_s('reply_to');
768 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
769 $send_to = $orig_header->getAddr_s('reply_to');
771 $send_to = $orig_header->getAddr_s('from');
774 $send_to = decodeHeader($send_to,false,false,true);
775 $subject = decodeHeader($orig_header->subject
,false,false,true);
776 $subject = str_replace('"', "'", $subject);
777 $subject = trim($subject);
778 if (substr(strtolower($subject), 0, 3) != 're:') {
779 $subject = 'Re: ' . $subject;
781 /* this corrects some wrapping/quoting problems on replies */
782 $rewrap_body = explode("\n", $body);
783 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
785 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
786 foreach ($rewrap_body as $line) {
787 if ($strip_sigs && substr($line,0,3) == '-- ') {
790 if (preg_match("/^(>+)/", $line, $matches)) {
792 $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n";
794 $body .= $body_quote . (!empty($body_quote) ?
' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ?
' ' : ''), rtrim($line)) . "\n";
798 //rewrap the body to clean up quotations and line lengths
799 $body = sqBodyWrap ($body, $editor_size);
801 $body = getReplyCitation($from , $orig_header->date
) . $body;
802 $composeMessage->reply_rfc822_header
= $orig_header;
808 $compose_messages[$session] = $composeMessage;
809 sqsession_register($compose_messages, 'compose_messages');
810 session_write_close();
811 sqimap_logout($imapConnection);
813 $ret = array( 'send_to' => $send_to,
814 'send_to_cc' => $send_to_cc,
815 'send_to_bcc' => $send_to_bcc,
816 'subject' => $subject,
817 'mailprio' => $mailprio,
819 'identity' => $identity );
822 } /* function newMail() */
824 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
825 global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages;
826 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
827 if (!count($message->entities
) ||
828 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
829 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
830 switch ($message->type0
) {
832 if ($message->type1
== 'rfc822') {
833 $filename = $message->rfc822_header
->subject
;
834 if ($filename == "") {
835 $filename = "untitled-".$message->entity_id
;
839 $filename = $message->getFilename();
843 if (!$message->mime_header
) { /* temporary hack */
844 $message->mime_header
= $message->header
;
846 $filename = $message->getFilename();
849 $filename = str_replace(' ', ' ', decodeHeader($filename));
850 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
851 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
852 $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename);
854 $localfilename = GenerateRandomString(32, '', 7);
855 $full_localfilename = "$hashed_attachment_dir/$localfilename";
856 while (file_exists($full_localfilename)) {
857 $localfilename = GenerateRandomString(32, '', 7);
858 $full_localfilename = "$hashed_attachment_dir/$localfilename";
860 $message->att_local_name
= $full_localfilename;
862 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
863 $full_localfilename);
865 /* Write Attachment to file */
866 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
867 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
868 $passed_id, $message->entity_id
),
869 $message->header
->encoding
));
873 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
874 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
877 return $composeMessage;
880 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
881 $passed_ent_id='', $imapConnection) {
882 global $attachment_dir, $username, $data_dir;
883 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
884 if (!$passed_ent_id) {
885 $body_a = sqimap_run_command($imapConnection,
886 'FETCH '.$passed_id.' RFC822',
887 TRUE, $response, $readmessage,
890 $body_a = sqimap_run_command($imapConnection,
891 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
892 TRUE, $response, $readmessage, TRUE);
893 $message = $message->parent
;
895 if ($response == 'OK') {
896 $subject = encodeHeader($message->rfc822_header
->subject
);
897 array_shift($body_a);
899 $body = implode('', $body_a) . "\r\n";
901 $localfilename = GenerateRandomString(32, 'FILE', 7);
902 $full_localfilename = "$hashed_attachment_dir/$localfilename";
904 $fp = fopen($full_localfilename, 'w');
907 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
908 $full_localfilename);
910 return $composeMessage;
913 function showInputForm ($session, $values=false) {
914 global $send_to, $send_to_cc, $body, $startMessage, $action,
915 $color, $use_signature, $signature, $prefix_sig,
916 $editor_size, $editor_height, $subject, $newmail,
917 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
918 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
919 $username, $data_dir, $identity, $idents, $delete_draft,
920 $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first,
921 $username, $compose_messages, $composesession, $default_charset;
923 $composeMessage = $compose_messages[$session];
925 $send_to = $values['send_to'];
926 $send_to_cc = $values['send_to_cc'];
927 $send_to_bcc = $values['send_to_bcc'];
928 $subject = $values['subject'];
929 $mailprio = $values['mailprio'];
930 $body = $values['body'];
931 $identity = (int) $values['identity'];
933 $send_to = decodeHeader($send_to, true, false);
934 $send_to_cc = decodeHeader($send_to_cc, true, false);
935 $send_to_bcc = decodeHeader($send_to_bcc, true, false);
938 if ($use_javascript_addr_book) {
939 echo "\n". '<script language="JavaScript">'."\n<!--\n" .
940 'function open_abook() { ' . "\n" .
941 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
942 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
943 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
944 ' nwin.opener = document.windows;' . "\n" .
946 "// -->\n</script>\n\n";
949 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
950 'enctype="multipart/form-data"';
951 do_hook('compose_form');
955 echo addHidden('startMessage', $startMessage);
957 if ($action == 'draft') {
958 echo addHidden('delete_draft', $passed_id);
960 if (isset($delete_draft)) {
961 echo addHidden('delete_draft', $delete_draft);
963 if (isset($session)) {
964 echo addHidden('session', $session);
967 if (isset($passed_id)) {
968 echo addHidden('passed_id', $passed_id);
971 if ($saved_draft == 'yes') {
972 echo '<br /><center><b>'. _("Draft Saved").'</center></b>';
974 if ($mail_sent == 'yes') {
975 echo '<br /><center><b>'. _("Your Message has been sent.").'</center></b>';
977 echo '<table align="center" cellspacing="0" border="0">' . "\n";
978 if ($compose_new_win == '1') {
979 echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
980 ' <tr><td></td>'.html_tag( 'td', '', 'right' ).
981 '<input type="button" name="Close" onclick="return self.close()" value="'.
982 _("Close").'" /></td></tr>'."\n";
984 if ($location_of_buttons == 'top') {
985 showComposeButtonRow();
988 /* display select list for identities */
989 if (count($idents) > 1) {
990 $ident_list = array();
991 foreach($idents as $id => $data) {
993 $data['full_name'].' <'.$data['email_address'].'>';
995 echo ' <tr>' . "\n" .
996 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
997 _("From:") . '</td>' . "\n" .
998 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1000 addSelect('identity', $ident_list, $identity, TRUE);
1002 echo ' </td>' . "\n" .
1006 echo ' <tr>' . "\n" .
1007 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1008 _("To") . ':</td>' . "\n" .
1009 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1010 addInput('send_to', $send_to, 60). '<br />' . "\n" .
1014 html_tag( 'td', '', 'right', $color[4] ) .
1015 _("Cc") . ':</td>' . "\n" .
1016 html_tag( 'td', '', 'left', $color[4] ) .
1017 addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
1021 html_tag( 'td', '', 'right', $color[4] ) .
1022 _("Bcc") . ':</td>' . "\n" .
1023 html_tag( 'td', '', 'left', $color[4] ) .
1024 addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
1028 html_tag( 'td', '', 'right', $color[4] ) .
1029 _("Subject") . ':</td>' . "\n" .
1030 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1031 echo ' '.addInput('subject', $subject, 60).
1035 if ($location_of_buttons == 'between') {
1036 showComposeButtonRow();
1039 /* why this distinction? */
1040 if ($compose_new_win == '1') {
1041 echo ' <tr>' . "\n" .
1042 ' <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
1043 ' <textarea name="body" id="body" rows="' . (int)$editor_height .
1044 '" cols="' . (int)$editor_size . '" wrap="virtual">';
1047 echo ' <tr>' . "\n" .
1048 ' <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
1049 ' <textarea name="body" id="body" rows="' . (int)$editor_height .
1050 '" cols="' . (int)$editor_size . '" wrap="virtual">';
1053 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1054 $signature = $idents[$identity]['signature'];
1056 if ($sig_first == '1') {
1057 if ($default_charset == 'iso-2022-jp') {
1058 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1060 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1062 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1065 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1066 if ($default_charset == 'iso-2022-jp') {
1067 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1069 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1073 echo htmlspecialchars(decodeHeader($body,false,false));
1075 echo '</textarea><br />' . "\n" .
1080 if ($location_of_buttons == 'bottom') {
1081 showComposeButtonRow();
1083 echo ' <tr>' . "\n" .
1084 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1085 ' ' . addSubmit(_("Send"), 'send').
1086 ' <br /><br />' . "\n" .
1091 /* This code is for attachments */
1092 if ((bool) ini_get('file_uploads')) {
1094 /* Calculate the max size for an uploaded file.
1095 * This is advisory for the user because we can't actually prevent
1096 * people to upload too large files. */
1098 /* php.ini vars which influence the max for uploads */
1099 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1100 foreach($configvars as $var) {
1101 /* skip 0 or empty values */
1102 if( $size = getByteSize(ini_get($var)) ) {
1107 if(count($sizes) > 0) {
1108 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1112 echo addHidden('MAX_FILE_SIZE', min( $sizes )).
1114 ' <td colspan="2">' . "\n" .
1115 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1116 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1119 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1120 ' border="0">' . "\n" .
1122 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1123 _("Attach:") . '</td>' . "\n" .
1124 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1125 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1126 ' <input type="submit" name="attach"' .
1127 ' value="' . _("Add") .'" />' . "\n" .
1133 if ($composeMessage->entities
) {
1134 foreach ($composeMessage->entities
as $key => $attachment) {
1135 $attached_file = $attachment->att_local_name
;
1136 if ($attachment->att_local_name ||
$attachment->body_part
) {
1137 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1138 $type = $attachment->mime_header
->type0
.'/'.
1139 $attachment->mime_header
->type1
;
1141 $s_a[] = '<table bgcolor="'.$color[0].
1142 '" border="0"><tr><td>'.
1143 addCheckBox('delete[]', FALSE, $key).
1144 "</td><td>\n" . $attached_filename .
1145 '</td><td>-</td><td> ' . $type . '</td><td>('.
1146 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1151 foreach ($s_a as $s) {
1152 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1154 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1155 _("Delete selected attachments") . "\" />\n" .
1158 echo ' </table>' . "\n" .
1161 ' </table>' . "\n" .
1164 } // End of file_uploads if-block
1165 /* End of attachment code */
1166 if ($compose_new_win == '1') {
1167 echo '</table>'."\n";
1170 echo '</table>' . "\n" .
1171 addHidden('username', $username).
1172 addHidden('smaction', $action).
1173 addHidden('mailbox', $mailbox);
1175 store the complete ComposeMessages array in a hidden input value
1176 so we can restore them in case of a session timeout.
1178 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1179 echo addHidden('restoremessages', serialize($compose_messages)).
1180 addHidden('composesession', $composesession).
1181 addHidden('querystring', $queryString).
1183 if (!(bool) ini_get('file_uploads')) {
1184 /* File uploads are off, so we didn't show that part of the form.
1185 To avoid bogus bug reports, tell the user why. */
1186 echo 'Because PHP file uploads are turned off, you can not attach files ';
1187 echo "to this message. Please see your system administrator for details.\r\n";
1190 do_hook('compose_bottom');
1191 echo '</body></html>' . "\n";
1195 function showComposeButtonRow() {
1196 global $use_javascript_addr_book, $save_as_draft,
1197 $default_use_priority, $mailprio, $default_use_mdn,
1198 $request_mdn, $request_dr,
1199 $data_dir, $username;
1201 echo ' <tr>' . "\n" .
1202 ' <td></td>' . "\n" .
1204 if ($default_use_priority) {
1205 if(!isset($mailprio)) {
1208 echo ' ' . _("Priority") .
1209 addSelect('mailprio', array(
1212 '5' => _("Low") ), $mailprio, TRUE);
1214 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1215 if ($default_use_mdn) {
1216 if ($mdn_user_support) {
1217 echo ' ' . _("Receipt") .': '.
1218 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1219 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1223 echo ' </td>' . "\n" .
1226 ' <td></td>' . "\n" .
1228 ' <input type="submit" name="sigappend" value="' . _("Signature") . '" />' . "\n";
1229 if ($use_javascript_addr_book) {
1230 echo " <script language=\"JavaScript\"><!--\n document.write(\"".
1231 " <input type=button value=\\\""._("Addresses").
1232 "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
1233 " // --></script><noscript>\n".
1234 ' <input type="submit" name="html_addr_search" value="'.
1235 _("Addresses").'" />'.
1238 echo ' <input type="submit" name="html_addr_search" value="'.
1239 _("Addresses").'" />' . "\n";
1242 if ($save_as_draft) {
1243 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\" />\n";
1246 echo ' <input type="submit" name="send" value="'. _("Send") . '" />' . "\n";
1247 do_hook('compose_button_row');
1249 echo ' </td>' . "\n" .
1253 function checkInput ($show) {
1255 * I implemented the $show variable because the error messages
1256 * were getting sent before the page header. So, I check once
1257 * using $show=false, and then when i'm ready to display the error
1258 * message, show=true
1260 global $body, $send_to, $send_to_bcc, $subject, $color;
1262 if ($send_to == '' && $send_to_bcc == '') {
1264 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1269 } /* function checkInput() */
1272 /* True if FAILURE */
1273 function saveAttachedFiles($session) {
1274 global $_FILES, $attachment_dir, $attachments, $username,
1275 $data_dir, $compose_messages;
1277 /* get out of here if no file was attached at all */
1278 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1282 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1283 $localfilename = GenerateRandomString(32, '', 7);
1284 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1285 while (file_exists($full_localfilename)) {
1286 $localfilename = GenerateRandomString(32, '', 7);
1287 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1290 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1291 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1292 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1293 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1297 $message = $compose_messages[$session];
1298 $type = strtolower($_FILES['attachfile']['type']);
1299 $name = $_FILES['attachfile']['name'];
1300 $message->initAttachment($type, $name, $full_localfilename);
1301 $compose_messages[$session] = $message;
1302 sqsession_register($compose_messages , 'compose_messages');
1305 function ClearAttachments($composeMessage) {
1306 if ($composeMessage->att_local_name
) {
1307 $attached_file = $composeMessage->att_local_name
;
1308 if (file_exists($attached_file)) {
1309 unlink($attached_file);
1312 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1313 ClearAttachments($composeMessage->entities
[$i]);
1317 /* parse values like 8M and 2k into bytes */
1318 function getByteSize($ini_size) {
1324 $ini_size = trim($ini_size);
1326 // if there's some kind of letter at the end of the string we need to multiply.
1327 if(!is_numeric(substr($ini_size, -1))) {
1329 switch(strtoupper(substr($ini_size, -1))) {
1331 $bytesize = 1073741824;
1334 $bytesize = 1048576;
1341 return ($bytesize * (int)substr($ini_size, 0, -1));
1348 /* temporary function to make use of the deliver class.
1349 In the future the responsable backend should be automaticly loaded
1350 and conf.pl should show a list of available backends.
1351 The message also should be constructed by the message class.
1354 function deliverMessage($composeMessage, $draft=false) {
1355 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1356 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1357 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1358 $domain, $action, $default_move_to_sent, $move_to_sent;
1359 global $imapServerAddress, $imapPort, $sent_folder, $key;
1361 $rfc822_header = $composeMessage->rfc822_header
;
1363 $abook = addressbook_init(false, true);
1364 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1365 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1366 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1367 $rfc822_header->priority
= $mailprio;
1368 $rfc822_header->subject
= $subject;
1370 $special_encoding='';
1371 if (strtolower($default_charset) == 'iso-2022-jp') {
1372 if (mb_detect_encoding($body) == 'ASCII') {
1373 $special_encoding = '8bit';
1375 $body = mb_convert_encoding($body, 'JIS');
1376 $special_encoding = '7bit';
1379 $composeMessage->setBody($body);
1381 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1382 $popuser = $usernamedata[1];
1383 $domain = $usernamedata[2];
1384 unset($usernamedata);
1386 $popuser = $username;
1389 $from_mail = $idents[$identity]['email_address'];
1390 $full_name = $idents[$identity]['full_name'];
1391 $reply_to = $idents[$identity]['reply_to'];
1393 $from_mail = "$popuser@$domain";
1395 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1397 $from = $rfc822_header->from
[0];
1398 if (!$from->host
) $from->host
= $domain;
1399 $full_name_encoded = encodeHeader($full_name);
1400 if ($full_name_encoded != $full_name) {
1401 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1403 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1405 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1408 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1410 /* Receipt: On Read */
1411 if (isset($request_mdn) && $request_mdn) {
1412 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1414 /* Receipt: On Delivery */
1415 if (isset($request_dr) && $request_dr) {
1416 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1418 /* multipart messages */
1419 if (count($composeMessage->entities
)) {
1420 $message_body = new Message();
1421 $message_body->body_part
= $composeMessage->body_part
;
1422 $composeMessage->body_part
= '';
1423 $mime_header = new MessageHeader
;
1424 $mime_header->type0
= 'text';
1425 $mime_header->type1
= 'plain';
1426 if ($special_encoding) {
1427 $mime_header->encoding
= $special_encoding;
1429 $mime_header->encoding
= '8bit';
1431 if ($default_charset) {
1432 $mime_header->parameters
['charset'] = $default_charset;
1434 $message_body->mime_header
= $mime_header;
1435 array_unshift($composeMessage->entities
, $message_body);
1436 $content_type = new ContentType('multipart/mixed');
1438 $content_type = new ContentType('text/plain');
1439 if ($special_encoding) {
1440 $rfc822_header->encoding
= $special_encoding;
1442 $rfc822_header->encoding
= '8bit';
1444 if ($default_charset) {
1445 $content_type->properties
['charset']=$default_charset;
1449 $rfc822_header->content_type
= $content_type;
1450 $composeMessage->rfc822_header
= $rfc822_header;
1452 /* Here you can modify the message structure just before we hand
1453 it over to deliver */
1454 $hookReturn = do_hook('compose_send', $composeMessage);
1455 /* Get any changes made by plugins to $composeMessage. */
1456 if ( is_object($hookReturn[1]) ) {
1457 $composeMessage = $hookReturn[1];
1460 if (!$useSendmail && !$draft) {
1461 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1462 $deliver = new Deliver_SMTP();
1463 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
1465 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1466 get_smtp_user($user, $pass);
1467 $stream = $deliver->initStream($composeMessage,$domain,0,
1468 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1469 } elseif (!$draft) {
1470 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1471 global $sendmail_path;
1472 $deliver = new Deliver_SendMail();
1473 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1475 global $draft_folder;
1476 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1477 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1479 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1480 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1481 $imap_deliver = new Deliver_IMAP();
1482 $length = $imap_deliver->mail($composeMessage);
1483 sqimap_append ($imap_stream, $draft_folder, $length);
1484 $imap_deliver->mail($composeMessage, $imap_stream);
1485 sqimap_append_done ($imap_stream, $draft_folder);
1486 sqimap_logout($imap_stream);
1487 unset ($imap_deliver);
1490 $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
1491 plain_error_message($msg, $color);
1497 $length = $deliver->mail($composeMessage, $stream);
1498 $succes = $deliver->finalizeStream($stream);
1501 $msg = $deliver->dlv_msg
. '<br />' .
1502 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1503 $deliver->dlv_server_msg
;
1504 plain_error_message($msg, $color);
1507 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1508 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1510 /* Move to sent code */
1511 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1512 $svr_allow_sent = true;
1514 $svr_allow_sent = false;
1517 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1518 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1524 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1525 $lcl_allow_sent = true;
1527 $lcl_allow_sent = false;
1530 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1531 global $passed_id, $mailbox, $action;
1532 if ($action == 'reply' ||
$action == 'reply_all') {
1533 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1534 if ($save_reply_with_orig) {
1535 $sent_folder = $mailbox;
1538 sqimap_append ($imap_stream, $sent_folder, $length);
1539 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1540 $imap_deliver = new Deliver_IMAP();
1541 $imap_deliver->mail($composeMessage, $imap_stream);
1542 sqimap_append_done ($imap_stream, $sent_folder);
1543 unset ($imap_deliver);
1545 global $passed_id, $mailbox, $action;
1546 ClearAttachments($composeMessage);
1547 if ($action == 'reply' ||
$action == 'reply_all') {
1548 sqimap_mailbox_select ($imap_stream, $mailbox);
1549 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1551 sqimap_logout($imap_stream);