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
21 /** Path for SquirrelMail required files. */
22 define('SM_PATH','../');
24 /* SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 require_once(SM_PATH
. 'functions/global.php');
27 require_once(SM_PATH
. 'functions/imap.php');
28 require_once(SM_PATH
. 'functions/date.php');
29 require_once(SM_PATH
. 'functions/mime.php');
30 require_once(SM_PATH
. 'functions/plugin.php');
31 require_once(SM_PATH
. 'functions/display_messages.php');
32 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
33 require_once(SM_PATH
. 'functions/addressbook.php');
34 require_once(SM_PATH
. 'functions/identity.php');
36 /* --------------------- Get globals ------------------------------------- */
38 sqgetGlobalVar('key', $key, SQ_COOKIE
);
41 sqgetGlobalVar('username', $username, SQ_SESSION
);
42 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
43 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
44 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
46 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
47 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
49 /** SESSION/POST/GET VARS */
50 sqgetGlobalVar('session',$session);
51 sqgetGlobalVar('mailbox',$mailbox);
52 if(!sqgetGlobalVar('identity',$identity)) {
55 sqgetGlobalVar('send_to',$send_to);
56 sqgetGlobalVar('send_to_cc',$send_to_cc);
57 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
58 sqgetGlobalVar('subject',$subject);
59 sqgetGlobalVar('body',$body);
60 sqgetGlobalVar('mailprio',$mailprio);
61 sqgetGlobalVar('request_mdn',$request_mdn);
62 sqgetGlobalVar('request_dr',$request_dr);
63 sqgetGlobalVar('html_addr_search',$html_addr_search);
64 sqgetGlobalVar('mail_sent',$mail_sent);
65 sqgetGlobalVar('passed_id',$passed_id);
66 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
67 sqgetGlobalVar('send',$send);
69 sqgetGlobalVar('attach',$attach);
71 sqgetGlobalVar('draft',$draft);
72 sqgetGlobalVar('draft_id',$draft_id);
73 sqgetGlobalVar('ent_num',$ent_num);
74 sqgetGlobalVar('saved_draft',$saved_draft);
75 sqgetGlobalVar('delete_draft',$delete_draft);
76 sqgetGlobalVar('startMessage',$startMessage);
79 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
80 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
81 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
82 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
83 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
84 sqgetGlobalVar('delete', $delete, SQ_POST
);
85 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
86 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
87 $html_addr_search_done = 'Use Addresses';
91 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
94 if ( !sqgetGlobalVar('smaction',$action) )
96 if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply';
97 if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all';
98 if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward';
99 if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment';
102 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
103 $location = get_location();
104 /* Identities (fetch only once) */
105 $idents = get_identities();
107 /* --------------------- Specific Functions ------------------------------ */
109 function replyAllString($header) {
110 global $include_self_reply_all, $idents;
113 * 1) Remove the addresses we'll be sending the message 'to'
115 $url_replytoall_avoid_addrs = '';
116 if (isset($header->replyto
)) {
117 $excl_ar = $header->getAddr_a('replyto');
120 * 2) Remove our identities from the CC list (they still can be in the
121 * TO list) only if $include_self_reply_all is turned off
123 if (!$include_self_reply_all) {
124 foreach($idents as $id) {
125 $excl_ar[strtolower(trim($id['email_address']))] = '';
130 * 3) get the addresses.
132 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
135 * 4) generate the string.
137 $url_replytoallcc = '';
138 foreach( $url_replytoall_ar as $email => $personal) {
140 // if personal name contains address separator then surround
141 // the personal name with double quotes.
142 if (strpos($personal,',') !== false) {
143 $personal = '"'.$personal.'"';
145 $url_replytoallcc .= ", $personal <$email>";
147 $url_replytoallcc .= ', '. $email;
150 $url_replytoallcc = substr($url_replytoallcc,2);
152 return $url_replytoallcc;
155 function getReplyCitation($orig_from, $orig_date) {
156 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
157 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
158 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
159 /* First, return an empty string when no citation style selected. */
160 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
164 /* Make sure our final value isn't an empty string. */
165 if ($orig_from == '') {
169 /* Otherwise, try to select the desired citation style. */
170 switch ($reply_citation_style) {
173 $end = ' ' . _("said") . ':';
176 $start = '<' . _("quote") . ' ' . _("who") . '="';
179 case 'date_time_author':
180 $start = 'On ' . getLongDateString($orig_date) . ', ';
181 $end = ' ' . _("said") . ':';
184 $start = $reply_citation_start .
185 ($reply_citation_start == '' ?
'' : ' ');
186 $end = $reply_citation_end;
192 /* Build and return the citation string. */
193 return ($start . $orig_from . $end . "\n");
196 function getforwardHeader($orig_header) {
199 $display = array( _("Subject") => strlen(_("Subject")),
200 _("From") => strlen(_("From")),
201 _("Date") => strlen(_("Date")),
202 _("To") => strlen(_("To")),
203 _("Cc") => strlen(_("Cc")) );
204 $maxsize = max($display);
205 $indent = str_pad('',$maxsize+
2);
206 foreach($display as $key => $val) {
207 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
209 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
210 $from = str_replace(' ',' ',$from);
211 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
212 $to = str_replace(' ',' ',$to);
213 $subject = decodeHeader($orig_header->subject
,false,false,true);
214 $subject = str_replace(' ',' ',$subject);
215 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
216 "\n". $display[_("Subject")] . $subject . "\n" .
217 $display[_("From")] . $from . "\n" .
218 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
219 $display[_("To")] . $to . "\n";
220 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
221 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
222 $cc = str_replace(' ',' ',$cc);
223 $bodyTop .= $display[_("Cc")] .$cc . "\n";
225 $bodyTop .= str_pad('', $editor_size -2 , '-') .
229 /* ----------------------------------------------------------------------- */
232 * If the session is expired during a post this restores the compose session
235 if (sqsession_is_registered('session_expired_post')) {
236 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
238 * extra check for username so we don't display previous post data from
239 * another user during this session.
241 if ($session_expired_post['username'] != $username) {
242 unset($session_expired_post);
243 sqsession_unregister('session_expired_post');
244 session_write_close();
246 foreach ($session_expired_post as $postvar => $val) {
253 $compose_messages = unserialize(urldecode($restoremessages));
254 sqsession_register($compose_messages,'compose_messages');
255 sqsession_register($composesession,'composesession');
259 $session_expired = true;
261 unset($session_expired_post);
262 sqsession_unregister('session_expired_post');
263 session_write_close();
264 if (!isset($mailbox)) {
267 if ($compose_new_win == '1') {
268 compose_Header($color, $mailbox);
270 displayPageHeader($color, $mailbox);
272 showInputForm($session, false);
275 if (!isset($composesession)) {
277 sqsession_register(0,'composesession');
280 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
281 sqsession_unregister('composesession');
282 $session = "$composesession" +
1;
283 $composesession = $session;
284 sqsession_register($composesession,'composesession');
286 if (!isset($compose_messages)) {
287 $compose_messages = array();
289 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
290 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
291 $composeMessage = new Message();
292 $rfc822_header = new Rfc822Header();
293 $composeMessage->rfc822_header
= $rfc822_header;
294 $composeMessage->reply_rfc822_header
= '';
295 $compose_messages[$session] = $composeMessage;
296 sqsession_register($compose_messages,'compose_messages');
298 $composeMessage=$compose_messages[$session];
301 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
307 * Set $default_charset to correspond with the user's selection
308 * of language interface.
311 $composeMessage=$compose_messages[$session];
312 if (! deliverMessage($composeMessage, true)) {
313 showInputForm($session);
316 unset($compose_messages[$session]);
317 $draft_message = _("Draft Email Saved");
318 /* If this is a resumed draft, then delete the original */
319 if(isset($delete_draft)) {
320 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
321 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
325 if ($compose_new_win == '1') {
326 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
330 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
331 "&startMessage=1¬e=".urlencode($draft_message));
339 if (isset($_FILES['attachfile']) &&
340 $_FILES['attachfile']['tmp_name'] &&
341 $_FILES['attachfile']['tmp_name'] != 'none') {
342 $AttachFailure = saveAttachedFiles($session);
344 if (checkInput(false) && !isset($AttachFailure)) {
345 if ($mailbox == "All Folders") {
346 /* We entered compose via the search results page */
347 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
349 $urlMailbox = urlencode (trim($mailbox));
350 if (! isset($passed_id)) {
354 * Set $default_charset to correspond with the user's selection
355 * of language interface.
359 * This is to change all newlines to \n
360 * We'll change them to \r\n later (in the sendMessage function)
362 $body = str_replace("\r\n", "\n", $body);
363 $body = str_replace("\r", "\n", $body);
366 * Rewrap $body so that no line is bigger than $editor_size
367 * This should only really kick in the sqWordWrap function
368 * if the browser doesn't support "VIRTUAL" as the wrap type.
370 $body = explode("\n", $body);
372 foreach ($body as $line) {
373 if( $line <> '-- ' ) {
374 $line = rtrim($line);
376 if (strlen($line) <= $editor_size +
1) {
377 $newBody .= $line . "\n";
379 sqWordWrap($line, $editor_size);
380 $newBody .= $line . "\n";
387 $composeMessage=$compose_messages[$session];
389 $Result = deliverMessage($composeMessage);
391 showInputForm($session);
394 unset($compose_messages[$session]);
395 if ( isset($delete_draft)) {
396 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
397 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
400 if ($compose_new_win == '1') {
402 Header("Location: $location/compose.php?mail_sent=yes");
405 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
406 "&startMessage=$startMessage&mail_sent=yes");
409 if ($compose_new_win == '1') {
410 compose_Header($color, $mailbox);
413 displayPageHeader($color, $mailbox);
415 if (isset($AttachFailure)) {
416 plain_error_message(_("Could not move/copy file. File not attached"),
420 showInputForm($session);
421 /* sqimap_logout($imapConnection); */
423 } elseif (isset($html_addr_search_done)) {
424 if ($compose_new_win == '1') {
425 compose_Header($color, $mailbox);
428 displayPageHeader($color, $mailbox);
431 if (isset($send_to_search) && is_array($send_to_search)) {
432 foreach ($send_to_search as $k => $v) {
433 if (substr($k, 0, 1) == 'T') {
439 elseif (substr($k, 0, 1) == 'C') {
445 elseif (substr($k, 0, 1) == 'B') {
447 $send_to_bcc .= ', ';
453 showInputForm($session);
454 } elseif (isset($html_addr_search)) {
455 if (isset($_FILES['attachfile']) &&
456 $_FILES['attachfile']['tmp_name'] &&
457 $_FILES['attachfile']['tmp_name'] != 'none') {
458 if(saveAttachedFiles($session)) {
459 plain_error_message(_("Could not move/copy file. File not attached"), $color);
463 * I am using an include so as to elminiate an extra unnecessary
464 * click. If you can think of a better way, please implement it.
466 include_once('./addrbook_search_html.php');
467 } elseif (isset($attach)) {
468 if (saveAttachedFiles($session)) {
469 plain_error_message(_("Could not move/copy file. File not attached"), $color);
471 if ($compose_new_win == '1') {
472 compose_Header($color, $mailbox);
475 displayPageHeader($color, $mailbox);
477 showInputForm($session);
479 elseif (isset($sigappend)) {
480 $signature = $idents[$identity]['signature'];
482 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
483 if ($compose_new_win == '1') {
484 compose_Header($color, $mailbox);
486 displayPageHeader($color, $mailbox);
488 showInputForm($session);
489 } elseif (isset($do_delete)) {
490 if ($compose_new_win == '1') {
491 compose_Header($color, $mailbox);
494 displayPageHeader($color, $mailbox);
497 if (isset($delete) && is_array($delete)) {
498 $composeMessage = $compose_messages[$session];
499 foreach($delete as $index) {
500 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
501 unlink ($attached_file);
502 unset ($composeMessage->entities
[$index]);
504 $new_entities = array();
505 foreach ($composeMessage->entities
as $entity) {
506 $new_entities[] = $entity;
508 $composeMessage->entities
= $new_entities;
509 $compose_messages[$session] = $composeMessage;
510 sqsession_register($compose_messages, 'compose_messages');
512 showInputForm($session);
515 * This handles the default case as well as the error case
516 * (they had the same code) --> if (isset($smtpErrors))
519 if ($compose_new_win == '1') {
520 compose_Header($color, $mailbox);
522 displayPageHeader($color, $mailbox);
527 if (!isset($passed_ent_id)) {
530 if (!isset($passed_id)) {
533 if (!isset($mailbox)) {
536 if (!isset($action)) {
540 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
542 /* in case the origin is not read_body.php */
543 if (isset($send_to)) {
544 $values['send_to'] = $send_to;
546 if (isset($send_to_cc)) {
547 $values['send_to_cc'] = $send_to_cc;
549 if (isset($send_to_bcc)) {
550 $values['send_to_bcc'] = $send_to_bcc;
552 if (isset($subject)) {
553 $values['subject'] = $subject;
555 showInputForm($session, $values);
560 /**************** Only function definitions go below *************/
562 function getforwardSubject($subject)
564 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
565 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
566 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
567 $subject = '[Fwd: ' . $subject . ']';
572 /* This function is used when not sending or adding attachments */
573 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
574 global $editor_size, $default_use_priority, $body, $idents,
575 $use_signature, $composesession, $data_dir, $username,
576 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
578 global $languages, $squirrelmail_language, $default_charset;
580 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
584 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
587 sqimap_mailbox_select($imapConnection, $mailbox);
588 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
591 if ($passed_ent_id) {
592 /* redefine the messsage in case of message/rfc822 */
593 $message = $message->getEntity($passed_ent_id);
594 /* message is an entity which contains the envelope and type0=message
595 * and type1=rfc822. The actual entities are childs from
596 * $message->entities[0]. That's where the encoding and is located
599 $entities = $message->entities
[0]->findDisplayEntity
600 (array(), $alt_order = array('text/plain'));
601 if (!count($entities)) {
602 $entities = $message->entities
[0]->findDisplayEntity
603 (array(), $alt_order = array('text/plain','html/plain'));
605 $orig_header = $message->rfc822_header
; /* here is the envelope located */
606 /* redefine the message for picking up the attachments */
607 $message = $message->entities
[0];
610 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
611 if (!count($entities)) {
612 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
614 $orig_header = $message->rfc822_header
;
617 $encoding = $message->header
->encoding
;
618 $type0 = $message->type0
;
619 $type1 = $message->type1
;
620 foreach ($entities as $ent) {
621 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
622 $body_part_entity = $message->getEntity($ent);
623 $bodypart = decodeBody($unencoded_bodypart,
624 $body_part_entity->header
->encoding
);
625 if ($type1 == 'html') {
626 $bodypart = str_replace("\n", ' ', $bodypart);
627 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
628 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
629 $bodypart = strip_tags($bodypart);
632 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
633 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
634 if (mb_detect_encoding($bodypart) != 'ASCII') {
635 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
639 if (isset($body_part_entity->header
->parameters
['charset'])) {
640 $actual = $body_part_entity->header
->parameters
['charset'];
642 $actual = 'us-ascii';
645 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
646 $bodypart = charset_decode($actual,$bodypart);
651 if ($default_use_priority) {
652 $mailprio = substr($orig_header->priority
,0,1);
659 //ClearAttachments($session);
662 $from_o = $orig_header->from
;
663 if (is_object($from_o)) {
664 $orig_from = $from_o->getAddress();
669 $identities = array();
670 if (count($idents) > 1) {
671 foreach($idents as $nr=>$data) {
672 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
673 if($enc_from_name == $orig_from) {
677 $identities[] = $enc_from_name;
680 $identity_match = $orig_header->findAddress($identities);
681 if ($identity_match) {
682 $identity = $identity_match;
684 // we need identiy here fore draft case #845290
685 // echo $identity."leer";
690 $use_signature = FALSE;
691 $composeMessage->rfc822_header
= $orig_header;
692 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
693 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
694 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
695 $send_from = $orig_header->getAddr_s('from');
696 $send_from_parts = new AddressStructure();
697 $send_from_parts = $orig_header->parseAddress($send_from);
698 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
699 $identities = get_identities();
700 if (count($identities) > 0) {
701 foreach($identities as $iddata) {
702 if ($send_from_add == $iddata['email_address']) {
703 $identity = $iddata['index'];
708 $subject = decodeHeader($orig_header->subject
,false,true,true);
709 // /* remember the references and in-reply-to headers in case of an reply */
710 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
711 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
712 $body_ary = explode("\n", $body);
713 $cnt = count($body_ary) ;
715 for ($i=0; $i < $cnt; $i++
) {
716 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
717 sqWordWrap($body_ary[$i], $editor_size );
718 $body .= $body_ary[$i] . "\n";
720 unset($body_ary[$i]);
723 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
725 case ('edit_as_new'):
726 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
727 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
728 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
729 $subject = decodeHeader($orig_header->subject
,false,true,true);
730 $mailprio = $orig_header->priority
;
732 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
737 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
738 $body = getforwardHeader($orig_header) . $body;
740 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
741 $body = "\n" . $body;
743 case ('forward_as_attachment'):
744 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true,true));
745 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
749 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
750 $send_to = $orig_header->getAddr_s('mail_followup_to');
752 $send_to_cc = replyAllString($orig_header);
753 $send_to_cc = decodeHeader($send_to_cc,false,true,true);
756 // skip this if send_to was already set right above here
758 $send_to = $orig_header->reply_to
;
759 if (is_array($send_to) && count($send_to)) {
760 $send_to = $orig_header->getAddr_s('reply_to');
761 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
762 $send_to = $orig_header->getAddr_s('reply_to');
764 $send_to = $orig_header->getAddr_s('from');
767 $send_to = decodeHeader($send_to,false,true,true);
768 $subject = decodeHeader($orig_header->subject
,false,true,true);
769 $subject = str_replace('"', "'", $subject);
770 $subject = trim($subject);
771 if (substr(strtolower($subject), 0, 3) != 're:') {
772 $subject = 'Re: ' . $subject;
774 /* this corrects some wrapping/quoting problems on replies */
775 $rewrap_body = explode("\n", $body);
776 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
777 sqUnWordWrap($body); // unwrap and then reset it?!
779 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
780 foreach ($rewrap_body as $line) {
781 if ($strip_sigs && substr($line,0,3) == '-- ') {
784 sqWordWrap($line, ($editor_size));
785 if (preg_match("/^(>+)/", $line, $matches)) {
787 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
789 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
792 $body = getReplyCitation($from , $orig_header->date
) . $body;
793 $composeMessage->reply_rfc822_header
= $orig_header;
799 $compose_messages[$session] = $composeMessage;
800 sqsession_register($compose_messages, 'compose_messages');
801 session_write_close();
802 sqimap_logout($imapConnection);
804 $ret = array( 'send_to' => $send_to,
805 'send_to_cc' => $send_to_cc,
806 'send_to_bcc' => $send_to_bcc,
807 'subject' => $subject,
808 'mailprio' => $mailprio,
810 'identity' => $identity );
813 } /* function newMail() */
815 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
816 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
817 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
818 if (!count($message->entities
) ||
819 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
820 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
821 switch ($message->type0
) {
823 if ($message->type1
== 'rfc822') {
824 $filename = $message->rfc822_header
->subject
;
825 if ($filename == "") {
826 $filename = "untitled-".$message->entity_id
;
830 $filename = $message->getFilename();
834 if (!$message->mime_header
) { /* temporary hack */
835 $message->mime_header
= $message->header
;
837 $filename = $message->getFilename();
840 $filename = str_replace(' ', ' ', decodeHeader($filename));
841 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
842 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
843 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
845 $localfilename = GenerateRandomString(32, '', 7);
846 $full_localfilename = "$hashed_attachment_dir/$localfilename";
847 while (file_exists($full_localfilename)) {
848 $localfilename = GenerateRandomString(32, '', 7);
849 $full_localfilename = "$hashed_attachment_dir/$localfilename";
851 $message->att_local_name
= $full_localfilename;
853 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
854 $full_localfilename);
856 /* Write Attachment to file */
857 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
858 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
859 $passed_id, $message->entity_id
),
860 $message->header
->encoding
));
864 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
865 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
868 return $composeMessage;
871 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
872 $passed_ent_id='', $imapConnection) {
873 global $attachments, $attachment_dir, $username, $data_dir;
874 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
875 if (!$passed_ent_id) {
876 $body_a = sqimap_run_command($imapConnection,
877 'FETCH '.$passed_id.' RFC822',
878 TRUE, $response, $readmessage,
881 $body_a = sqimap_run_command($imapConnection,
882 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
883 TRUE, $response, $readmessage, TRUE);
884 $message = $message->parent
;
886 if ($response == 'OK') {
887 $subject = encodeHeader($message->rfc822_header
->subject
);
888 array_shift($body_a);
890 $body = implode('', $body_a) . "\r\n";
892 $localfilename = GenerateRandomString(32, 'FILE', 7);
893 $full_localfilename = "$hashed_attachment_dir/$localfilename";
895 $fp = fopen($full_localfilename, 'w');
898 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
899 $full_localfilename);
901 return $composeMessage;
904 function showInputForm ($session, $values=false) {
905 global $send_to, $send_to_cc, $body, $startMessage,
906 $passed_body, $color, $use_signature, $signature, $prefix_sig,
907 $editor_size, $editor_height, $attachments, $subject, $newmail,
908 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
909 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
910 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
911 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
912 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
913 $username, $compose_messages, $composesession, $default_charset;
915 $composeMessage = $compose_messages[$session];
918 $send_to = $values['send_to'];
919 $send_to_cc = $values['send_to_cc'];
920 $send_to_bcc = $values['send_to_bcc'];
921 $subject = $values['subject'];
922 $mailprio = $values['mailprio'];
923 $body = $values['body'];
924 $identity = (int) $values['identity'];
926 $send_to = decodeHeader($send_to);
927 $send_to_cc = decodeHeader($send_to_cc);
928 $send_to_bcc = decodeHeader($send_to_bcc);
931 if ($use_javascript_addr_book) {
932 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
933 'function open_abook() { ' . "\n" .
934 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
935 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
936 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
937 ' nwin.opener = document.windows;' . "\n" .
939 "// -->\n</SCRIPT>\n\n";
942 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
943 'enctype="multipart/form-data"';
944 do_hook('compose_form');
948 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
950 if ($action == 'draft') {
951 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
953 if (isset($delete_draft)) {
954 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
956 if (isset($session)) {
957 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
960 if (isset($passed_id)) {
961 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
964 if ($saved_draft == 'yes') {
965 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
967 if ($mail_sent == 'yes') {
968 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
970 echo '<table align="center" cellspacing="0" border="0">' . "\n";
971 if ($compose_new_win == '1') {
972 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
973 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
975 if ($location_of_buttons == 'top') {
976 showComposeButtonRow();
979 /* display select list for identities */
980 if (count($idents) > 1) {
981 echo ' <tr>' . "\n" .
982 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
983 _("From:") . '</td>' . "\n" .
984 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
985 ' <select name="identity">' . "\n" ;
986 foreach($idents as $id=>$data) {
987 echo '<option value="'.$id.'"';
988 if($id == $identity) {
991 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
995 echo '</select>' . "\n" .
999 echo ' <tr>' . "\n" .
1000 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1001 _("To:") . '</TD>' . "\n" .
1002 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1003 ' <input type="text" name="send_to" value="' .
1004 $send_to . '" size="60" /><br />' . "\n" .
1008 html_tag( 'td', '', 'right', $color[4] ) .
1009 _("CC:") . '</td>' . "\n" .
1010 html_tag( 'td', '', 'left', $color[4] ) .
1011 ' <input type="text" name="send_to_cc" size="60" value="' .
1012 $send_to_cc . '" /><br />' . "\n" .
1016 html_tag( 'td', '', 'right', $color[4] ) .
1017 _("BCC:") . '</td>' . "\n" .
1018 html_tag( 'td', '', 'left', $color[4] ) .
1019 ' <input type="text" name="send_to_bcc" value="' .
1020 $send_to_bcc . '" size="60" /><br />' . "\n" .
1024 html_tag( 'td', '', 'right', $color[4] ) .
1025 _("Subject:") . '</td>' . "\n" .
1026 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1027 echo ' <input type="text" name="subject" size="60" value="' .
1028 $subject . '" />' . "\n" .
1032 if ($location_of_buttons == 'between') {
1033 showComposeButtonRow();
1036 /* why this distinction? */
1037 if ($compose_new_win == '1') {
1038 echo ' <TR>' . "\n" .
1039 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1040 ' <TEXTAREA NAME="body" ID="body" ROWS="' . $editor_height .
1041 '" COLS="' . $editor_size . '" WRAP="VIRTUAL">';
1044 echo ' <TR>' . "\n" .
1045 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1046 ' <TEXTAREA NAME="body" ID="body" ROWS="' . $editor_height .
1047 '" COLS="' . $editor_size . '" WRAP="VIRTUAL">';
1050 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1051 $signature = $idents[$identity]['signature'];
1053 if ($sig_first == '1') {
1054 if ($default_charset == 'iso-2022-jp') {
1055 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1057 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1059 echo "\n\n".decodeHeader($body,false,false);
1062 echo "\n\n".decodeHeader($body,false,false);
1063 if ($default_charset == 'iso-2022-jp') {
1064 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1066 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1071 echo decodeHeader($body,false,false);
1073 echo '</textarea><br />' . "\n" .
1078 if ($location_of_buttons == 'bottom') {
1079 showComposeButtonRow();
1081 echo ' <tr>' . "\n" .
1082 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1083 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1084 ' <br /><br />' . "\n" .
1089 /* This code is for attachments */
1090 if ((bool) ini_get('file_uploads')) {
1092 /* Calculate the max size for an uploaded file.
1093 * This is advisory for the user because we can't actually prevent
1094 * people to upload too large files. */
1096 /* php.ini vars which influence the max for uploads */
1097 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1098 foreach($configvars as $var) {
1099 /* skip 0 or empty values */
1100 if( $size = getByteSize(ini_get($var)) ) {
1105 if(count($sizes) > 0) {
1106 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1110 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1111 echo ' <tr>' . "\n" .
1112 ' <td colspan="2">' . "\n" .
1113 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1114 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1117 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1118 ' border="0">' . "\n" .
1120 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1121 _("Attach:") . '</td>' . "\n" .
1122 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1123 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1124 ' <input type="submit" name="attach"' .
1125 ' value="' . _("Add") .'">' . "\n" .
1132 if ($composeMessage->entities
) {
1133 foreach ($composeMessage->entities
as $key => $attachment) {
1134 $attached_file = $attachment->att_local_name
;
1135 if ($attachment->att_local_name ||
$attachment->body_part
) {
1136 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1137 $type = $attachment->mime_header
->type0
.'/'.
1138 $attachment->mime_header
->type1
;
1140 $s_a[] = '<table bgcolor="'.$color[0].
1141 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1142 $key . "\"></td><td>\n" . $attached_filename .
1143 '</td><td>-</td><td> ' . $type . '</td><td>('.
1144 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1149 foreach ($s_a as $s) {
1150 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1152 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1153 _("Delete selected attachments") . "\">\n" .
1156 echo ' </table>' . "\n" .
1159 ' </TABLE>' . "\n" .
1162 } // End of file_uploads if-block
1163 /* End of attachment code */
1164 if ($compose_new_win == '1') {
1165 echo '</TABLE>'."\n";
1168 echo '</TABLE>' . "\n" .
1169 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1170 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1171 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1174 store the complete ComposeMessages array in a hidden input value
1175 so we can restore them in case of a session timeout.
1177 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1178 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1179 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1180 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1182 if (!(bool) ini_get('file_uploads')) {
1183 /* File uploads are off, so we didn't show that part of the form.
1184 To avoid bogus bug reports, tell the user why. */
1185 echo 'Because PHP file uploads are turned off, you can not attach files ';
1186 echo "to this message. Please see your system administrator for details.\r\n";
1189 do_hook('compose_bottom');
1190 echo '</BODY></HTML>' . "\n";
1194 function showComposeButtonRow() {
1195 global $use_javascript_addr_book, $save_as_draft,
1196 $default_use_priority, $mailprio, $default_use_mdn,
1197 $request_mdn, $request_dr,
1198 $data_dir, $username;
1200 echo ' <TR>' . "\n" .
1201 ' <TD></TD>' . "\n" .
1203 if ($default_use_priority) {
1204 if(!isset($mailprio)) {
1207 echo ' ' . _("Priority") .': <select name="mailprio">'.
1208 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1209 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1210 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1213 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1214 if ($default_use_mdn) {
1215 if ($mdn_user_support) {
1216 echo ' ' . _("Receipt") .': '.
1217 '<input type="checkbox" name="request_mdn" value=1'.
1218 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1219 ' <input type="checkbox" name="request_dr" value=1'.
1220 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1224 echo ' </TD>' . "\n" .
1227 ' <TD></TD>' . "\n" .
1229 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1230 if ($use_javascript_addr_book) {
1231 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1232 " <input type=button value=\\\""._("Addresses").
1233 "\\\" onclick='javascript:open_abook();'>\");".
1234 " // --></SCRIPT><NOSCRIPT>\n".
1235 " <input type=submit name=\"html_addr_search\" value=\"".
1236 _("Addresses")."\">".
1239 echo ' <input type=submit name="html_addr_search" value="'.
1240 _("Addresses").'">' . "\n";
1243 if ($save_as_draft) {
1244 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1247 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1248 do_hook('compose_button_row');
1250 echo ' </TD>' . "\n" .
1254 function checkInput ($show) {
1256 * I implemented the $show variable because the error messages
1257 * were getting sent before the page header. So, I check once
1258 * using $show=false, and then when i'm ready to display the error
1259 * message, show=true
1261 global $body, $send_to, $send_to_bcc, $subject, $color;
1263 if ($send_to == '' && $send_to_bcc == '') {
1265 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1270 } /* function checkInput() */
1273 /* True if FAILURE */
1274 function saveAttachedFiles($session) {
1275 global $_FILES, $attachment_dir, $attachments, $username,
1276 $data_dir, $compose_messages;
1278 /* get out of here if no file was attached at all */
1279 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1283 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1284 $localfilename = GenerateRandomString(32, '', 7);
1285 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1286 while (file_exists($full_localfilename)) {
1287 $localfilename = GenerateRandomString(32, '', 7);
1288 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1291 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1292 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1293 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1294 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1298 $message = $compose_messages[$session];
1299 $type = strtolower($_FILES['attachfile']['type']);
1300 $name = $_FILES['attachfile']['name'];
1301 $message->initAttachment($type, $name, $full_localfilename);
1302 $compose_messages[$session] = $message;
1303 sqsession_register($compose_messages , 'compose_messages');
1306 function ClearAttachments($composeMessage) {
1307 if ($composeMessage->att_local_name
) {
1308 $attached_file = $composeMessage->att_local_name
;
1309 if (file_exists($attached_file)) {
1310 unlink($attached_file);
1313 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1314 ClearAttachments($composeMessage->entities
[$i]);
1318 /* parse values like 8M and 2k into bytes */
1319 function getByteSize($ini_size) {
1325 $ini_size = trim($ini_size);
1327 // if there's some kind of letter at the end of the string we need to multiply.
1328 if(!is_numeric(substr($ini_size, -1))) {
1330 switch(strtoupper(substr($ini_size, -1))) {
1332 $bytesize = 1073741824;
1335 $bytesize = 1048576;
1342 return ($bytesize * (int)substr($ini_size, 0, -1));
1349 /* temporary function to make use of the deliver class.
1350 In the future the responsable backend should be automaticly loaded
1351 and conf.pl should show a list of available backends.
1352 The message also should be constructed by the message class.
1355 function deliverMessage($composeMessage, $draft=false) {
1356 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1357 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1358 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1359 $domain, $action, $default_move_to_sent, $move_to_sent;
1360 global $imapServerAddress, $imapPort, $sent_folder, $key;
1362 /* some browsers replace <space> by nonbreaking spaces
1363 by replacing them back to spaces addressparsing works */
1364 /* FIXME: How to handle in case of other charsets where "\240"
1365 is not a non breaking space ??? */
1366 /* THEFIX: browsers don't replace space with nbsp. SM replaces
1367 space with nbsp when decodes headers. If problem still happens,
1368 use cleanup_nbsp() */
1370 // $send_to = str_replace("\240",' ',$send_to);
1371 // $send_to_cc = str_replace("\240",' ',$send_to_cc);
1372 // $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1374 $rfc822_header = $composeMessage->rfc822_header
;
1376 $abook = addressbook_init(false, true);
1377 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1378 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1379 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1380 $rfc822_header->priority
= $mailprio;
1381 $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>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
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);