6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
18 * @package squirrelmail
21 /** Path for SquirrelMail required files. */
22 define('SM_PATH','../');
24 /* SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 require_once(SM_PATH
. 'functions/global.php');
27 require_once(SM_PATH
. 'functions/imap.php');
28 require_once(SM_PATH
. 'functions/date.php');
29 require_once(SM_PATH
. 'functions/mime.php');
30 require_once(SM_PATH
. 'functions/plugin.php');
31 require_once(SM_PATH
. 'functions/display_messages.php');
32 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
33 require_once(SM_PATH
. 'functions/addressbook.php');
34 require_once(SM_PATH
. 'functions/identity.php');
36 /* --------------------- Get globals ------------------------------------- */
38 sqgetGlobalVar('key', $key, SQ_COOKIE
);
41 sqgetGlobalVar('username', $username, SQ_SESSION
);
42 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
43 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
44 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
46 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
47 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
49 /** SESSION/POST/GET VARS */
50 sqgetGlobalVar('smaction',$action);
51 sqgetGlobalVar('session',$session);
52 sqgetGlobalVar('mailbox',$mailbox);
53 if(!sqgetGlobalVar('identity',$identity)) {
56 sqgetGlobalVar('send_to',$send_to);
57 sqgetGlobalVar('send_to_cc',$send_to_cc);
58 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
59 sqgetGlobalVar('subject',$subject);
60 sqgetGlobalVar('body',$body);
61 sqgetGlobalVar('mailprio',$mailprio);
62 sqgetGlobalVar('request_mdn',$request_mdn);
63 sqgetGlobalVar('request_dr',$request_dr);
64 sqgetGlobalVar('html_addr_search',$html_addr_search);
65 sqgetGlobalVar('mail_sent',$mail_sent);
66 sqgetGlobalVar('passed_id',$passed_id);
67 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
68 sqgetGlobalVar('send',$send);
70 sqgetGlobalVar('attach',$attach);
72 sqgetGlobalVar('draft',$draft);
73 sqgetGlobalVar('draft_id',$draft_id);
74 sqgetGlobalVar('ent_num',$ent_num);
75 sqgetGlobalVar('saved_draft',$saved_draft);
76 sqgetGlobalVar('delete_draft',$delete_draft);
77 sqgetGlobalVar('startMessage',$startMessage);
80 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
81 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
82 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
83 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
84 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
85 sqgetGlobalVar('delete', $delete, SQ_POST
);
86 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
87 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
88 $html_addr_search_done = 'Use Addresses';
92 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
94 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
95 $location = get_location();
96 /* Identities (fetch only once) */
97 $idents = get_identities();
99 /* --------------------- Specific Functions ------------------------------ */
101 function replyAllString($header) {
102 global $include_self_reply_all, $idents;
105 * 1) Remove the addresses we'll be sending the message 'to'
107 $url_replytoall_avoid_addrs = '';
108 if (isset($header->replyto
)) {
109 $excl_ar = $header->getAddr_a('replyto');
112 * 2) Remove our identities from the CC list (they still can be in the
113 * TO list) only if $include_self_reply_all is turned off
115 if (!$include_self_reply_all) {
116 foreach($idents as $id) {
117 $excl_ar[strtolower(trim($id['email_address']))] = '';
122 * 3) get the addresses.
124 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
127 * 4) generate the string.
129 $url_replytoallcc = '';
130 foreach( $url_replytoall_ar as $email => $personal) {
132 // if personal name contains address separator then surround
133 // the personal name with double quotes.
134 if (strpos($personal,',') !== false) {
135 $personal = '"'.$personal.'"';
137 $url_replytoallcc .= ", $personal <$email>";
139 $url_replytoallcc .= ', '. $email;
142 $url_replytoallcc = substr($url_replytoallcc,2);
144 return $url_replytoallcc;
147 function getReplyCitation($orig_from) {
148 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
149 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
150 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
151 /* First, return an empty string when no citation style selected. */
152 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
156 /* Make sure our final value isn't an empty string. */
157 if ($orig_from == '') {
161 /* Otherwise, try to select the desired citation style. */
162 switch ($reply_citation_style) {
165 $end = ' ' . _("said") . ':';
168 $start = '<' . _("quote") . ' ' . _("who") . '="';
172 $start = $reply_citation_start .
173 ($reply_citation_start == '' ?
'' : ' ');
174 $end = $reply_citation_end;
180 /* Build and return the citation string. */
181 return ($start . $orig_from . $end . "\n");
184 function getforwardHeader($orig_header) {
187 $display = array( _("Subject") => strlen(_("Subject")),
188 _("From") => strlen(_("From")),
189 _("Date") => strlen(_("Date")),
190 _("To") => strlen(_("To")),
191 _("Cc") => strlen(_("Cc")) );
192 $maxsize = max($display);
193 $indent = str_pad('',$maxsize+
2);
194 foreach($display as $key => $val) {
195 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
197 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
198 $from = str_replace(' ',' ',$from);
199 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
200 $to = str_replace(' ',' ',$to);
201 $subject = decodeHeader($orig_header->subject
,false,false);
202 $subject = str_replace(' ',' ',$subject);
203 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
204 "\n". $display[_("Subject")] . $subject . "\n" .
205 $display[_("From")] . $from . "\n" .
206 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
207 $display[_("To")] . $to . "\n";
208 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
209 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
210 $cc = str_replace(' ',' ',$cc);
211 $bodyTop .= $display[_("Cc")] .$cc . "\n";
213 $bodyTop .= str_pad('', $editor_size -2 , '-') .
217 /* ----------------------------------------------------------------------- */
220 * If the session is expired during a post this restores the compose session
223 if (sqsession_is_registered('session_expired_post')) {
224 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
226 * extra check for username so we don't display previous post data from
227 * another user during this session.
229 if ($session_expired_post['username'] != $username) {
230 unset($session_expired_post);
231 sqsession_unregister('session_expired_post');
232 session_write_close();
234 foreach ($session_expired_post as $postvar => $val) {
241 $compose_messages = unserialize(urldecode($restoremessages));
242 sqsession_register($compose_messages,'compose_messages');
243 sqsession_register($composesession,'composesession');
247 $session_expired = true;
249 unset($session_expired_post);
250 sqsession_unregister('session_expired_post');
251 session_write_close();
252 if (!isset($mailbox)) {
255 if ($compose_new_win == '1') {
256 compose_Header($color, $mailbox);
258 displayPageHeader($color, $mailbox);
260 showInputForm($session, false);
263 if (!isset($composesession)) {
265 sqsession_register(0,'composesession');
268 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
269 sqsession_unregister('composesession');
270 $session = "$composesession" +
1;
271 $composesession = $session;
272 sqsession_register($composesession,'composesession');
274 if (!isset($compose_messages)) {
275 $compose_messages = array();
277 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
278 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
279 $composeMessage = new Message();
280 $rfc822_header = new Rfc822Header();
281 $composeMessage->rfc822_header
= $rfc822_header;
282 $composeMessage->reply_rfc822_header
= '';
283 $compose_messages[$session] = $composeMessage;
284 sqsession_register($compose_messages,'compose_messages');
286 $composeMessage=$compose_messages[$session];
289 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
295 * Set $default_charset to correspond with the user's selection
296 * of language interface.
299 $composeMessage=$compose_messages[$session];
300 if (! deliverMessage($composeMessage, true)) {
301 showInputForm($session);
304 unset($compose_messages[$session]);
305 $draft_message = _("Draft Email Saved");
306 /* If this is a resumed draft, then delete the original */
307 if(isset($delete_draft)) {
308 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
309 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
313 if ($compose_new_win == '1') {
314 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
318 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
319 "&startMessage=1¬e=".urlencode($draft_message));
327 if (isset($_FILES['attachfile']) &&
328 $_FILES['attachfile']['tmp_name'] &&
329 $_FILES['attachfile']['tmp_name'] != 'none') {
330 $AttachFailure = saveAttachedFiles($session);
332 if (checkInput(false) && !isset($AttachFailure)) {
333 if ($mailbox == "All Folders") {
334 /* We entered compose via the search results page */
335 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
337 $urlMailbox = urlencode (trim($mailbox));
338 if (! isset($passed_id)) {
342 * Set $default_charset to correspond with the user's selection
343 * of language interface.
347 * This is to change all newlines to \n
348 * We'll change them to \r\n later (in the sendMessage function)
350 $body = str_replace("\r\n", "\n", $body);
351 $body = str_replace("\r", "\n", $body);
354 * Rewrap $body so that no line is bigger than $editor_size
355 * This should only really kick in the sqWordWrap function
356 * if the browser doesn't support "VIRTUAL" as the wrap type.
358 $body = explode("\n", $body);
360 foreach ($body as $line) {
361 if( $line <> '-- ' ) {
362 $line = rtrim($line);
364 if (strlen($line) <= $editor_size +
1) {
365 $newBody .= $line . "\n";
367 sqWordWrap($line, $editor_size);
368 $newBody .= $line . "\n";
375 $composeMessage=$compose_messages[$session];
377 $Result = deliverMessage($composeMessage);
379 showInputForm($session);
382 unset($compose_messages[$session]);
383 if ( isset($delete_draft)) {
384 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
385 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
388 if ($compose_new_win == '1') {
390 Header("Location: $location/compose.php?mail_sent=yes");
393 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
394 "&startMessage=$startMessage&mail_sent=yes");
397 if ($compose_new_win == '1') {
398 compose_Header($color, $mailbox);
401 displayPageHeader($color, $mailbox);
403 if (isset($AttachFailure)) {
404 plain_error_message(_("Could not move/copy file. File not attached"),
408 showInputForm($session);
409 /* sqimap_logout($imapConnection); */
411 } elseif (isset($html_addr_search_done)) {
412 if ($compose_new_win == '1') {
413 compose_Header($color, $mailbox);
416 displayPageHeader($color, $mailbox);
419 if (isset($send_to_search) && is_array($send_to_search)) {
420 foreach ($send_to_search as $k => $v) {
421 if (substr($k, 0, 1) == 'T') {
427 elseif (substr($k, 0, 1) == 'C') {
433 elseif (substr($k, 0, 1) == 'B') {
435 $send_to_bcc .= ', ';
441 showInputForm($session);
442 } elseif (isset($html_addr_search)) {
443 if (isset($_FILES['attachfile']) &&
444 $_FILES['attachfile']['tmp_name'] &&
445 $_FILES['attachfile']['tmp_name'] != 'none') {
446 if(saveAttachedFiles($session)) {
447 plain_error_message(_("Could not move/copy file. File not attached"), $color);
451 * I am using an include so as to elminiate an extra unnecessary
452 * click. If you can think of a better way, please implement it.
454 include_once('./addrbook_search_html.php');
455 } elseif (isset($attach)) {
456 if (saveAttachedFiles($session)) {
457 plain_error_message(_("Could not move/copy file. File not attached"), $color);
459 if ($compose_new_win == '1') {
460 compose_Header($color, $mailbox);
463 displayPageHeader($color, $mailbox);
465 showInputForm($session);
467 elseif (isset($sigappend)) {
468 $signature = $idents[$identity]['signature'];
470 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
471 if ($compose_new_win == '1') {
472 compose_Header($color, $mailbox);
474 displayPageHeader($color, $mailbox);
476 showInputForm($session);
477 } elseif (isset($do_delete)) {
478 if ($compose_new_win == '1') {
479 compose_Header($color, $mailbox);
482 displayPageHeader($color, $mailbox);
485 if (isset($delete) && is_array($delete)) {
486 $composeMessage = $compose_messages[$session];
487 foreach($delete as $index) {
488 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
489 unlink ($attached_file);
490 unset ($composeMessage->entities
[$index]);
492 $new_entities = array();
493 foreach ($composeMessage->entities
as $entity) {
494 $new_entities[] = $entity;
496 $composeMessage->entities
= $new_entities;
497 $compose_messages[$session] = $composeMessage;
498 sqsession_register($compose_messages, 'compose_messages');
500 showInputForm($session);
503 * This handles the default case as well as the error case
504 * (they had the same code) --> if (isset($smtpErrors))
507 if ($compose_new_win == '1') {
508 compose_Header($color, $mailbox);
510 displayPageHeader($color, $mailbox);
515 if (!isset($passed_ent_id)) {
518 if (!isset($passed_id)) {
521 if (!isset($mailbox)) {
524 if (!isset($action)) {
528 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
530 /* in case the origin is not read_body.php */
531 if (isset($send_to)) {
532 $values['send_to'] = $send_to;
534 if (isset($send_to_cc)) {
535 $values['send_to_cc'] = $send_to_cc;
537 if (isset($send_to_bcc)) {
538 $values['send_to_bcc'] = $send_to_bcc;
540 if (isset($subject)) {
541 $values['subject'] = $subject;
543 showInputForm($session, $values);
548 /**************** Only function definitions go below *************/
550 function getforwardSubject($subject)
552 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
553 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
554 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
555 $subject = '[Fwd: ' . $subject . ']';
560 /* This function is used when not sending or adding attachments */
561 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
562 global $editor_size, $default_use_priority, $body, $idents,
563 $use_signature, $composesession, $data_dir, $username,
564 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
566 global $languages, $squirrelmail_language, $default_charset;
568 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
572 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
575 sqimap_mailbox_select($imapConnection, $mailbox);
576 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
579 if ($passed_ent_id) {
580 /* redefine the messsage in case of message/rfc822 */
581 $message = $message->getEntity($passed_ent_id);
582 /* message is an entity which contains the envelope and type0=message
583 * and type1=rfc822. The actual entities are childs from
584 * $message->entities[0]. That's where the encoding and is located
587 $entities = $message->entities
[0]->findDisplayEntity
588 (array(), $alt_order = array('text/plain'));
589 if (!count($entities)) {
590 $entities = $message->entities
[0]->findDisplayEntity
591 (array(), $alt_order = array('text/plain','html/plain'));
593 $orig_header = $message->rfc822_header
; /* here is the envelope located */
594 /* redefine the message for picking up the attachments */
595 $message = $message->entities
[0];
598 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
599 if (!count($entities)) {
600 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
602 $orig_header = $message->rfc822_header
;
605 $encoding = $message->header
->encoding
;
606 $type0 = $message->type0
;
607 $type1 = $message->type1
;
608 foreach ($entities as $ent) {
609 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
610 $body_part_entity = $message->getEntity($ent);
611 $bodypart = decodeBody($unencoded_bodypart,
612 $body_part_entity->header
->encoding
);
613 if ($type1 == 'html') {
614 $bodypart = str_replace("\n", ' ', $bodypart);
615 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
616 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
617 $bodypart = strip_tags($bodypart);
620 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
621 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
622 if (mb_detect_encoding($bodypart) != 'ASCII') {
623 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
627 if (isset($body_part_entity->header
->parameters
['charset'])) {
628 $actual = $body_part_entity->header
->parameters
['charset'];
630 $actual = 'us-ascii';
633 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
634 $bodypart = charset_decode($actual,$bodypart);
639 if ($default_use_priority) {
640 $mailprio = substr($orig_header->priority
,0,1);
647 //ClearAttachments($session);
650 $from_o = $orig_header->from
;
651 if (is_object($from_o)) {
652 $orig_from = $from_o->getAddress();
657 $identities = array();
658 if (count($idents) > 1) {
659 foreach($idents as $nr=>$data) {
660 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
661 if($enc_from_name == $orig_from) {
665 $identities[] = $enc_from_name;
668 $identity_match = $orig_header->findAddress($identities);
669 if ($identity_match) {
670 $identity = $identity_match;
672 // we need identiy here fore draft case #845290
673 // echo $identity."leer";
678 $use_signature = FALSE;
679 $composeMessage->rfc822_header
= $orig_header;
680 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
681 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
682 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
683 $subject = decodeHeader($orig_header->subject
,false,true);
684 // /* remember the references and in-reply-to headers in case of an reply */
685 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
686 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
687 $body_ary = explode("\n", $body);
688 /* echo "debug: $identity"; #845290
690 echo "header".decodeHeader($orig_header->getAddr_s('from'),false,true)."<BR>";
691 print_r($identities);
692 $cnt = count($body_ary) ;
694 for ($i=0; $i < $cnt; $i++
) {
695 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
696 sqWordWrap($body_ary[$i], $editor_size );
697 $body .= $body_ary[$i] . "\n";
699 unset($body_ary[$i]);
702 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
704 case ('edit_as_new'):
705 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
706 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
707 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
708 $subject = decodeHeader($orig_header->subject
,false,true);
709 $mailprio = $orig_header->priority
;
711 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
716 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
717 $body = getforwardHeader($orig_header) . $body;
719 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
720 $body = "\n" . $body;
722 case ('forward_as_attachment'):
723 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
724 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
728 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
729 $send_to = $orig_header->getAddr_s('mail_followup_to');
731 $send_to_cc = replyAllString($orig_header);
732 $send_to_cc = decodeHeader($send_to_cc,false,true);
735 // skip this if send_to was already set right above here
737 $send_to = $orig_header->reply_to
;
738 if (is_array($send_to) && count($send_to)) {
739 $send_to = $orig_header->getAddr_s('reply_to');
740 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
741 $send_to = $orig_header->getAddr_s('reply_to');
743 $send_to = $orig_header->getAddr_s('from');
746 $send_to = decodeHeader($send_to,false,true);
747 $subject = decodeHeader($orig_header->subject
,false,true);
748 $subject = str_replace('"', "'", $subject);
749 $subject = trim($subject);
750 if (substr(strtolower($subject), 0, 3) != 're:') {
751 $subject = 'Re: ' . $subject;
753 /* this corrects some wrapping/quoting problems on replies */
754 $rewrap_body = explode("\n", $body);
755 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
756 sqUnWordWrap($body); // unwrap and then reset it?!
758 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
759 foreach ($rewrap_body as $line) {
760 if ($strip_sigs && substr($line,0,3) == '-- ') {
763 sqWordWrap($line, ($editor_size));
764 if (preg_match("/^(>+)/", $line, $matches)) {
766 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
768 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
771 $body = getReplyCitation($from) . $body;
772 $composeMessage->reply_rfc822_header
= $orig_header;
778 $compose_messages[$session] = $composeMessage;
779 sqsession_register($compose_messages, 'compose_messages');
780 session_write_close();
781 sqimap_logout($imapConnection);
783 $ret = array( 'send_to' => $send_to,
784 'send_to_cc' => $send_to_cc,
785 'send_to_bcc' => $send_to_bcc,
786 'subject' => $subject,
787 'mailprio' => $mailprio,
789 'identity' => $identity );
792 } /* function newMail() */
794 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
795 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
796 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
797 if (!count($message->entities
) ||
798 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
799 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
800 switch ($message->type0
) {
802 if ($message->type1
== 'rfc822') {
803 $filename = $message->rfc822_header
->subject
;
804 if ($filename == "") {
805 $filename = "untitled-".$message->entity_id
;
809 $filename = $message->getFilename();
813 if (!$message->mime_header
) { /* temporary hack */
814 $message->mime_header
= $message->header
;
816 $filename = $message->getFilename();
819 $filename = str_replace(' ', ' ', decodeHeader($filename));
820 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
821 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
822 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
824 $localfilename = GenerateRandomString(32, '', 7);
825 $full_localfilename = "$hashed_attachment_dir/$localfilename";
826 while (file_exists($full_localfilename)) {
827 $localfilename = GenerateRandomString(32, '', 7);
828 $full_localfilename = "$hashed_attachment_dir/$localfilename";
830 $message->att_local_name
= $full_localfilename;
832 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
833 $full_localfilename);
835 /* Write Attachment to file */
836 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
837 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
838 $passed_id, $message->entity_id
),
839 $message->header
->encoding
));
843 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
844 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
847 return $composeMessage;
850 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
851 $passed_ent_id='', $imapConnection) {
852 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
853 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
854 if (!$passed_ent_id) {
855 $body_a = sqimap_run_command($imapConnection,
856 'FETCH '.$passed_id.' RFC822',
857 TRUE, $response, $readmessage,
860 $body_a = sqimap_run_command($imapConnection,
861 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
862 TRUE, $response, $readmessage, $uid_support);
863 $message = $message->parent
;
865 if ($response == 'OK') {
866 $subject = encodeHeader($message->rfc822_header
->subject
);
867 array_shift($body_a);
869 $body = implode('', $body_a) . "\r\n";
871 $localfilename = GenerateRandomString(32, 'FILE', 7);
872 $full_localfilename = "$hashed_attachment_dir/$localfilename";
874 $fp = fopen($full_localfilename, 'w');
877 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
878 $full_localfilename);
880 return $composeMessage;
883 function showInputForm ($session, $values=false) {
884 global $send_to, $send_to_cc, $body, $startMessage,
885 $passed_body, $color, $use_signature, $signature, $prefix_sig,
886 $editor_size, $attachments, $subject, $newmail,
887 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
888 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
889 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
890 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
891 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
892 $username, $compose_messages, $composesession, $default_charset;
894 $composeMessage = $compose_messages[$session];
897 $send_to = $values['send_to'];
898 $send_to_cc = $values['send_to_cc'];
899 $send_to_bcc = $values['send_to_bcc'];
900 $subject = $values['subject'];
901 $mailprio = $values['mailprio'];
902 $body = $values['body'];
903 $identity = (int) $values['identity'];
905 $send_to = decodeHeader($send_to);
906 $send_to_cc = decodeHeader($send_to_cc);
907 $send_to_bcc = decodeHeader($send_to_bcc);
910 if ($use_javascript_addr_book) {
911 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
912 'function open_abook() { ' . "\n" .
913 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
914 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
915 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
916 ' nwin.opener = document.windows;' . "\n" .
918 "// -->\n</SCRIPT>\n\n";
921 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
922 'enctype="multipart/form-data"';
923 do_hook('compose_form');
927 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
929 if ($action == 'draft') {
930 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
932 if (isset($delete_draft)) {
933 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
935 if (isset($session)) {
936 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
939 if (isset($passed_id)) {
940 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
943 if ($saved_draft == 'yes') {
944 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
946 if ($mail_sent == 'yes') {
947 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
949 echo '<table align="center" cellspacing="0" border="0">' . "\n";
950 if ($compose_new_win == '1') {
951 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
952 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
954 if ($location_of_buttons == 'top') {
955 showComposeButtonRow();
958 /* display select list for identities */
959 if (count($idents) > 1) {
960 echo ' <tr>' . "\n" .
961 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
962 _("From:") . '</td>' . "\n" .
963 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
964 ' <select name="identity">' . "\n" ;
965 foreach($idents as $id=>$data) {
966 echo '<option value="'.$id.'"';
967 if($id == $identity) {
970 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
974 echo '</select>' . "\n" .
978 echo ' <tr>' . "\n" .
979 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
980 _("To:") . '</TD>' . "\n" .
981 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
982 ' <input type="text" name="send_to" value="' .
983 $send_to . '" size="60" /><br />' . "\n" .
987 html_tag( 'td', '', 'right', $color[4] ) .
988 _("CC:") . '</td>' . "\n" .
989 html_tag( 'td', '', 'left', $color[4] ) .
990 ' <input type="text" name="send_to_cc" size="60" value="' .
991 $send_to_cc . '" /><br />' . "\n" .
995 html_tag( 'td', '', 'right', $color[4] ) .
996 _("BCC:") . '</td>' . "\n" .
997 html_tag( 'td', '', 'left', $color[4] ) .
998 ' <input type="text" name="send_to_bcc" value="' .
999 $send_to_bcc . '" size="60" /><br />' . "\n" .
1003 html_tag( 'td', '', 'right', $color[4] ) .
1004 _("Subject:") . '</td>' . "\n" .
1005 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1006 echo ' <input type="text" name="subject" size="60" value="' .
1007 $subject . '" />' . "\n" .
1011 if ($location_of_buttons == 'between') {
1012 showComposeButtonRow();
1015 /* why this distinction? */
1016 if ($compose_new_win == '1') {
1017 echo ' <TR>' . "\n" .
1018 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1019 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1020 $editor_size . '" WRAP="VIRTUAL">';
1023 echo ' <TR>' . "\n" .
1024 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1025 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1026 $editor_size . '" WRAP="VIRTUAL">';
1029 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1030 $signature = $idents[$identity]['signature'];
1032 if ($sig_first == '1') {
1033 if ($default_charset == 'iso-2022-jp') {
1034 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1036 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1038 echo "\n\n".decodeHeader($body,false,false);
1041 echo "\n\n".decodeHeader($body,false,false);
1042 if ($default_charset == 'iso-2022-jp') {
1043 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1045 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1050 echo decodeHeader($body,false,false);
1052 echo '</textarea><br />' . "\n" .
1057 if ($location_of_buttons == 'bottom') {
1058 showComposeButtonRow();
1060 echo ' <tr>' . "\n" .
1061 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1062 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1063 ' <br /><br />' . "\n" .
1068 /* This code is for attachments */
1069 if ((bool) ini_get('file_uploads')) {
1071 /* Calculate the max size for an uploaded file.
1072 * This is advisory for the user because we can't actually prevent
1073 * people to upload too large files. */
1075 /* php.ini vars which influence the max for uploads */
1076 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1077 foreach($configvars as $var) {
1078 /* skip 0 or empty values */
1079 if( $size = getByteSize(ini_get($var)) ) {
1084 if(count($sizes) > 0) {
1085 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1089 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1090 echo ' <tr>' . "\n" .
1091 ' <td colspan="2">' . "\n" .
1092 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1093 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1096 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1097 ' border="0">' . "\n" .
1099 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1100 _("Attach:") . '</td>' . "\n" .
1101 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1102 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1103 ' <input type="submit" name="attach"' .
1104 ' value="' . _("Add") .'">' . "\n" .
1111 if ($composeMessage->entities
) {
1112 foreach ($composeMessage->entities
as $key => $attachment) {
1113 $attached_file = $attachment->att_local_name
;
1114 if ($attachment->att_local_name ||
$attachment->body_part
) {
1115 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1116 $type = $attachment->mime_header
->type0
.'/'.
1117 $attachment->mime_header
->type1
;
1119 $s_a[] = '<table bgcolor="'.$color[0].
1120 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1121 $key . "\"></td><td>\n" . $attached_filename .
1122 '</td><td>-</td><td> ' . $type . '</td><td>('.
1123 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1128 foreach ($s_a as $s) {
1129 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1131 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1132 _("Delete selected attachments") . "\">\n" .
1135 echo ' </table>' . "\n" .
1138 ' </TABLE>' . "\n" .
1141 } // End of file_uploads if-block
1142 /* End of attachment code */
1143 if ($compose_new_win == '1') {
1144 echo '</TABLE>'."\n";
1147 echo '</TABLE>' . "\n" .
1148 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1149 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1150 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1153 store the complete ComposeMessages array in a hidden input value
1154 so we can restore them in case of a session timeout.
1156 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1157 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1158 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1159 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1161 if (!(bool) ini_get('file_uploads')) {
1162 /* File uploads are off, so we didn't show that part of the form.
1163 To avoid bogus bug reports, tell the user why. */
1164 echo 'Because PHP file uploads are turned off, you can not attach files ';
1165 echo "to this message. Please see your system administrator for details.\r\n";
1168 do_hook('compose_bottom');
1169 echo '</BODY></HTML>' . "\n";
1173 function showComposeButtonRow() {
1174 global $use_javascript_addr_book, $save_as_draft,
1175 $default_use_priority, $mailprio, $default_use_mdn,
1176 $request_mdn, $request_dr,
1177 $data_dir, $username;
1179 echo ' <TR>' . "\n" .
1180 ' <TD></TD>' . "\n" .
1182 if ($default_use_priority) {
1183 if(!isset($mailprio)) {
1186 echo ' ' . _("Priority") .': <select name="mailprio">'.
1187 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1188 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1189 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1192 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1193 if ($default_use_mdn) {
1194 if ($mdn_user_support) {
1195 echo ' ' . _("Receipt") .': '.
1196 '<input type="checkbox" name="request_mdn" value=1'.
1197 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1198 ' <input type="checkbox" name="request_dr" value=1'.
1199 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1203 echo ' </TD>' . "\n" .
1206 ' <TD></TD>' . "\n" .
1208 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1209 if ($use_javascript_addr_book) {
1210 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1211 " <input type=button value=\\\""._("Addresses").
1212 "\\\" onclick='javascript:open_abook();'>\");".
1213 " // --></SCRIPT><NOSCRIPT>\n".
1214 " <input type=submit name=\"html_addr_search\" value=\"".
1215 _("Addresses")."\">".
1218 echo ' <input type=submit name="html_addr_search" value="'.
1219 _("Addresses").'">' . "\n";
1222 if ($save_as_draft) {
1223 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1226 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1227 do_hook('compose_button_row');
1229 echo ' </TD>' . "\n" .
1233 function checkInput ($show) {
1235 * I implemented the $show variable because the error messages
1236 * were getting sent before the page header. So, I check once
1237 * using $show=false, and then when i'm ready to display the error
1238 * message, show=true
1240 global $body, $send_to, $send_to_bcc, $subject, $color;
1242 if ($send_to == '' && $send_to_bcc == '') {
1244 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1249 } /* function checkInput() */
1252 /* True if FAILURE */
1253 function saveAttachedFiles($session) {
1254 global $_FILES, $attachment_dir, $attachments, $username,
1255 $data_dir, $compose_messages;
1257 /* get out of here if no file was attached at all */
1258 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1262 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1263 $localfilename = GenerateRandomString(32, '', 7);
1264 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1265 while (file_exists($full_localfilename)) {
1266 $localfilename = GenerateRandomString(32, '', 7);
1267 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1270 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1271 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1272 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1273 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1277 $message = $compose_messages[$session];
1278 $type = strtolower($_FILES['attachfile']['type']);
1279 $name = $_FILES['attachfile']['name'];
1280 $message->initAttachment($type, $name, $full_localfilename);
1281 $compose_messages[$session] = $message;
1282 sqsession_register($compose_messages , 'compose_messages');
1285 function ClearAttachments($composeMessage) {
1286 if ($composeMessage->att_local_name
) {
1287 $attached_file = $composeMessage->att_local_name
;
1288 if (file_exists($attached_file)) {
1289 unlink($attached_file);
1292 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1293 ClearAttachments($composeMessage->entities
[$i]);
1297 /* parse values like 8M and 2k into bytes */
1298 function getByteSize($ini_size) {
1304 $ini_size = trim($ini_size);
1306 // if there's some kind of letter at the end of the string we need to multiply.
1307 if(!is_numeric(substr($ini_size, -1))) {
1309 switch(strtoupper(substr($ini_size, -1))) {
1311 $bytesize = 1073741824;
1314 $bytesize = 1048576;
1321 return ($bytesize * (int)substr($ini_size, 0, -1));
1328 /* temporary function to make use of the deliver class.
1329 In the future the responsable backend should be automaticly loaded
1330 and conf.pl should show a list of available backends.
1331 The message also should be constructed by the message class.
1334 function deliverMessage($composeMessage, $draft=false) {
1335 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1336 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1337 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1338 $domain, $action, $default_move_to_sent, $move_to_sent;
1339 global $imapServerAddress, $imapPort, $sent_folder, $key;
1341 /* some browsers replace <space> by nonbreaking spaces
1342 by replacing them back to spaces addressparsing works */
1343 /* FIXME: How to handle in case of other charsets where "\240"
1344 is not a non breaking space ??? */
1346 $send_to = str_replace("\240",' ',$send_to);
1347 $send_to_cc = str_replace("\240",' ',$send_to_cc);
1348 $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1350 $rfc822_header = $composeMessage->rfc822_header
;
1352 $abook = addressbook_init(false, true);
1353 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1354 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1355 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1356 $rfc822_header->priority
= $mailprio;
1357 $rfc822_header->subject
= $subject;
1358 $special_encoding='';
1359 if (strtolower($default_charset) == 'iso-2022-jp') {
1360 if (mb_detect_encoding($body) == 'ASCII') {
1361 $special_encoding = '8bit';
1363 $body = mb_convert_encoding($body, 'JIS');
1364 $special_encoding = '7bit';
1367 $composeMessage->setBody($body);
1369 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1370 $popuser = $usernamedata[1];
1371 $domain = $usernamedata[2];
1372 unset($usernamedata);
1374 $popuser = $username;
1377 $from_mail = $idents[$identity]['email_address'];
1378 $full_name = $idents[$identity]['full_name'];
1379 $reply_to = $idents[$identity]['reply_to'];
1381 $from_mail = "$popuser@$domain";
1383 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1385 $from = $rfc822_header->from
[0];
1386 if (!$from->host
) $from->host
= $domain;
1387 $full_name_encoded = encodeHeader($full_name);
1388 if ($full_name_encoded != $full_name) {
1389 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1391 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1393 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1396 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1398 /* Receipt: On Read */
1399 if (isset($request_mdn) && $request_mdn) {
1400 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1402 /* Receipt: On Delivery */
1403 if (isset($request_dr) && $request_dr) {
1404 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1406 /* multipart messages */
1407 if (count($composeMessage->entities
)) {
1408 $message_body = new Message();
1409 $message_body->body_part
= $composeMessage->body_part
;
1410 $composeMessage->body_part
= '';
1411 $mime_header = new MessageHeader
;
1412 $mime_header->type0
= 'text';
1413 $mime_header->type1
= 'plain';
1414 if ($special_encoding) {
1415 $mime_header->encoding
= $special_encoding;
1417 $mime_header->encoding
= '8bit';
1419 if ($default_charset) {
1420 $mime_header->parameters
['charset'] = $default_charset;
1422 $message_body->mime_header
= $mime_header;
1423 array_unshift($composeMessage->entities
, $message_body);
1424 $content_type = new ContentType('multipart/mixed');
1426 $content_type = new ContentType('text/plain');
1427 if ($special_encoding) {
1428 $rfc822_header->encoding
= $special_encoding;
1430 $rfc822_header->encoding
= '8bit';
1432 if ($default_charset) {
1433 $content_type->properties
['charset']=$default_charset;
1437 $rfc822_header->content_type
= $content_type;
1438 $composeMessage->rfc822_header
= $rfc822_header;
1440 /* Here you can modify the message structure just before we hand
1441 it over to deliver */
1442 $hookReturn = do_hook('compose_send', $composeMessage);
1443 /* Get any changes made by plugins to $composeMessage. */
1444 if ( is_object($hookReturn[1]) ) {
1445 $composeMessage = $hookReturn[1];
1448 if (!$useSendmail && !$draft) {
1449 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1450 $deliver = new Deliver_SMTP();
1451 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1453 if ($smtp_auth_mech == 'none') {
1457 global $key, $onetimepad;
1459 $pass = OneTimePadDecrypt($key, $onetimepad);
1462 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1463 $stream = $deliver->initStream($composeMessage,$domain,0,
1464 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1465 } elseif (!$draft) {
1466 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1467 global $sendmail_path;
1468 $deliver = new Deliver_SendMail();
1469 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1471 global $draft_folder;
1472 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1473 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1475 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1476 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1477 $imap_deliver = new Deliver_IMAP();
1478 $length = $imap_deliver->mail($composeMessage);
1479 sqimap_append ($imap_stream, $draft_folder, $length);
1480 $imap_deliver->mail($composeMessage, $imap_stream);
1481 sqimap_append_done ($imap_stream, $draft_folder);
1482 sqimap_logout($imap_stream);
1483 unset ($imap_deliver);
1486 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1487 plain_error_message($msg, $color);
1493 $length = $deliver->mail($composeMessage, $stream);
1494 $succes = $deliver->finalizeStream($stream);
1497 $msg = $deliver->dlv_msg
. '<br>' .
1498 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1499 $deliver->dlv_server_msg
;
1500 plain_error_message($msg, $color);
1503 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1504 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1506 /* Move to sent code */
1507 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1508 $svr_allow_sent = true;
1510 $svr_allow_sent = false;
1513 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1514 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1520 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1521 $lcl_allow_sent = true;
1523 $lcl_allow_sent = false;
1526 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1527 sqimap_append ($imap_stream, $sent_folder, $length);
1528 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1529 $imap_deliver = new Deliver_IMAP();
1530 $imap_deliver->mail($composeMessage, $imap_stream);
1531 sqimap_append_done ($imap_stream, $sent_folder);
1532 unset ($imap_deliver);
1534 global $passed_id, $mailbox, $action;
1535 ClearAttachments($composeMessage);
1536 if ($action == 'reply' ||
$action == 'reply_all') {
1537 sqimap_mailbox_select ($imap_stream, $mailbox);
1538 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1540 sqimap_logout($imap_stream);