6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
18 * @package squirrelmail
22 * Path for SquirrelMail required files.
25 define('SM_PATH','../');
27 /* SquirrelMail required files. */
28 require_once(SM_PATH
. 'include/validate.php');
29 require_once(SM_PATH
. 'functions/global.php');
30 require_once(SM_PATH
. 'functions/imap.php');
31 require_once(SM_PATH
. 'functions/date.php');
32 require_once(SM_PATH
. 'functions/mime.php');
33 require_once(SM_PATH
. 'functions/plugin.php');
34 require_once(SM_PATH
. 'functions/display_messages.php');
35 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
36 require_once(SM_PATH
. 'functions/addressbook.php');
37 require_once(SM_PATH
. 'functions/forms.php');
38 require_once(SM_PATH
. 'functions/identity.php');
40 /* --------------------- Get globals ------------------------------------- */
42 sqgetGlobalVar('key', $key, SQ_COOKIE
);
45 sqgetGlobalVar('username', $username, SQ_SESSION
);
46 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
47 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
50 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
51 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
53 /** SESSION/POST/GET VARS */
54 sqgetGlobalVar('session',$session);
55 sqgetGlobalVar('mailbox',$mailbox);
56 if(!sqgetGlobalVar('identity',$identity)) {
59 sqgetGlobalVar('send_to',$send_to);
60 sqgetGlobalVar('send_to_cc',$send_to_cc);
61 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
62 sqgetGlobalVar('subject',$subject);
63 sqgetGlobalVar('body',$body);
64 sqgetGlobalVar('mailprio',$mailprio);
65 sqgetGlobalVar('request_mdn',$request_mdn);
66 sqgetGlobalVar('request_dr',$request_dr);
67 sqgetGlobalVar('html_addr_search',$html_addr_search);
68 sqgetGlobalVar('mail_sent',$mail_sent);
69 sqgetGlobalVar('passed_id',$passed_id);
70 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
71 sqgetGlobalVar('send',$send);
73 sqgetGlobalVar('attach',$attach);
75 sqgetGlobalVar('draft',$draft);
76 sqgetGlobalVar('draft_id',$draft_id);
77 sqgetGlobalVar('ent_num',$ent_num);
78 sqgetGlobalVar('saved_draft',$saved_draft);
79 sqgetGlobalVar('delete_draft',$delete_draft);
80 if ( sqgetGlobalVar('startMessage',$startMessage) ) {
81 $startMessage = (int)$startMessage;
87 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
88 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
89 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
90 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
91 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
92 sqgetGlobalVar('delete', $delete, SQ_POST
);
93 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
94 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
95 $html_addr_search_done = 'Use Addresses';
99 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
102 if ( !sqgetGlobalVar('smaction',$action) )
104 if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply';
105 if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all';
106 if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward';
107 if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment';
108 if ( sqgetGlobalVar('smaction_draft',$tmp) ) $action = 'draft';
109 if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action = 'edit_as_new';
112 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
113 $location = get_location();
114 /* Identities (fetch only once) */
115 $idents = get_identities();
117 /* --------------------- Specific Functions ------------------------------ */
119 function replyAllString($header) {
120 global $include_self_reply_all, $idents;
123 * 1) Remove the addresses we'll be sending the message 'to'
125 if (isset($header->replyto
)) {
126 $excl_ar = $header->getAddr_a('replyto');
129 * 2) Remove our identities from the CC list (they still can be in the
130 * TO list) only if $include_self_reply_all is turned off
132 if (!$include_self_reply_all) {
133 foreach($idents as $id) {
134 $excl_ar[strtolower(trim($id['email_address']))] = '';
139 * 3) get the addresses.
141 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
144 * 4) generate the string.
146 $url_replytoallcc = '';
147 foreach( $url_replytoall_ar as $email => $personal) {
149 // if personal name contains address separator then surround
150 // the personal name with double quotes.
151 if (strpos($personal,',') !== false) {
152 $personal = '"'.$personal.'"';
154 $url_replytoallcc .= ", $personal <$email>";
156 $url_replytoallcc .= ', '. $email;
159 $url_replytoallcc = substr($url_replytoallcc,2);
161 return $url_replytoallcc;
165 * creates top line in reply citations
167 * Line style depends on user preferences.
168 * $orig_date argument is available only from 1.4.3 and 1.5.1 version.
169 * @param object $orig_from From: header object.
170 * @param integer $orig_date email's timestamp
171 * @return string reply citation
173 function getReplyCitation($orig_from, $orig_date) {
174 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
176 if (!is_object($orig_from)) {
179 $sOrig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
182 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
184 /* First, return an empty string when no citation style selected. */
185 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
189 /* Make sure our final value isn't an empty string. */
190 if ($sOrig_from == '') {
194 /* Otherwise, try to select the desired citation style. */
195 switch ($reply_citation_style) {
198 * To translators: %s is for author's name
200 $full_reply_citation = sprintf(_("%s wrote:"),$sOrig_from);
203 // FIXME: do we have to translate xml formating?
204 $start = '<' . _("quote") . ' ' . _("who") . '="';
206 $full_reply_citation = $start . $sOrig_from . $end;
208 case 'date_time_author':
211 * first %s is for date string, second %s is for author's name. Date uses
212 * formating from "D, F j, Y g:i a" and "D, F j, Y H:i" translations.
214 * "On Sat, December 24, 2004 23:59, Santa wrote:"
215 * If you have to put author's name in front of date string, check comments about
216 * argument swapping at http://www.php.net/sprintf
218 $full_reply_citation = sprintf(_("On %s, %s wrote:"), getLongDateString($orig_date), $sOrig_from);
221 $start = $reply_citation_start .
222 ($reply_citation_start == '' ?
'' : ' ');
223 $end = $reply_citation_end;
224 $full_reply_citation = $start . $sOrig_from . $end;
230 /* Add line feed and return the citation string. */
231 return ($full_reply_citation . "\n");
235 * Creates header fields in forwarded email body
237 * $default_charset global must be set correctly before you call this function.
238 * @param object $orig_header
241 function getforwardHeader($orig_header) {
242 global $editor_size, $default_charset;
244 // using own strlen function in order to detect correct string length
245 $display = array( _("Subject") => sq_strlen(_("Subject"),$default_charset),
246 _("From") => sq_strlen(_("From"),$default_charset),
247 _("Date") => sq_strlen(_("Date"),$default_charset),
248 _("To") => sq_strlen(_("To"),$default_charset),
249 _("Cc") => sq_strlen(_("Cc"),$default_charset) );
250 $maxsize = max($display);
251 $indent = str_pad('',$maxsize+
2);
252 foreach($display as $key => $val) {
253 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
255 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
256 $from = str_replace(' ',' ',$from);
257 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
258 $to = str_replace(' ',' ',$to);
259 $subject = decodeHeader($orig_header->subject
,false,false,true);
260 $subject = str_replace(' ',' ',$subject);
262 // using own str_pad function in order to create correct string pad
263 $bodyTop = sq_str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
,$default_charset) .
264 "\n". $display[_("Subject")] . $subject . "\n" .
265 $display[_("From")] . $from . "\n" .
266 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
267 $display[_("To")] . $to . "\n";
268 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
269 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
270 $cc = str_replace(' ',' ',$cc);
271 $bodyTop .= $display[_("Cc")] .$cc . "\n";
273 $bodyTop .= str_pad('', $editor_size -2 , '-') .
277 /* ----------------------------------------------------------------------- */
280 * If the session is expired during a post this restores the compose session
283 if (sqsession_is_registered('session_expired_post')) {
284 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
286 * extra check for username so we don't display previous post data from
287 * another user during this session.
289 if ($session_expired_post['username'] != $username) {
290 unset($session_expired_post);
291 sqsession_unregister('session_expired_post');
292 session_write_close();
294 foreach ($session_expired_post as $postvar => $val) {
301 $compose_messages = unserialize(urldecode($restoremessages));
302 sqsession_register($compose_messages,'compose_messages');
303 sqsession_register($composesession,'composesession');
307 $session_expired = true;
309 unset($session_expired_post);
310 sqsession_unregister('session_expired_post');
311 session_write_close();
312 if (!isset($mailbox)) {
315 if ($compose_new_win == '1') {
316 compose_Header($color, $mailbox);
318 $sHeaderJs = (isset($sHeaderJs)) ?
$sHeaderJs : '';
319 if (strpos($action, 'reply') !== false && $reply_focus) {
320 $sBodyTagJs = 'onload="checkForm(\''.$replyfocus.'\');"';
322 $sBodyTagJs = 'onload="checkForm();"';
324 displayPageHeader($color, $mailbox,$sHeaderJs,$sBodyTagJs);
326 showInputForm($session, false);
329 if (!isset($composesession)) {
331 sqsession_register(0,'composesession');
334 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
335 sqsession_unregister('composesession');
336 $session = "$composesession" +
1;
337 $composesession = $session;
338 sqsession_register($composesession,'composesession');
340 if (!isset($compose_messages)) {
341 $compose_messages = array();
344 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
345 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
346 $composeMessage = new Message();
347 $rfc822_header = new Rfc822Header();
348 $composeMessage->rfc822_header
= $rfc822_header;
349 $composeMessage->reply_rfc822_header
= '';
350 $compose_messages[$session] = $composeMessage;
352 sqsession_register($compose_messages,'compose_messages');
354 $composeMessage=$compose_messages[$session];
357 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
363 * Set $default_charset to correspond with the user's selection
364 * of language interface.
367 $composeMessage=$compose_messages[$session];
368 if (! deliverMessage($composeMessage, true)) {
369 showInputForm($session);
372 unset($compose_messages[$session]);
373 $draft_message = _("Draft Email Saved");
374 /* If this is a resumed draft, then delete the original */
375 if(isset($delete_draft)) {
376 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, false);
377 sqimap_mailbox_select($imap_stream, $draft_folder);
378 // force bypass_trash=true because message should be saved when deliverMessage() returns true.
379 // in current implementation of sqimap_msgs_list_flag() single message id can
380 // be submitted as string. docs state that it should be array.
381 sqimap_msgs_list_delete($imap_stream, $draft_folder, $delete_draft, true);
383 sqimap_mailbox_expunge($imap_stream, $draft_folder, true);
385 sqimap_logout($imap_stream);
387 if ($compose_new_win == '1') {
388 if ( !isset($pageheader_sent) ||
!$pageheader_sent ) {
389 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
391 echo ' <br><br><center><a href="' . $location
392 . '/compose.php?saved_sent=yes&session=' . $composesession . '">'
393 . _("Return") . '</a></center>';
397 if ( !isset($pageheader_sent) ||
!$pageheader_sent ) {
398 Header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
399 "&startMessage=1¬e=".urlencode($draft_message));
401 echo ' <br><br><center><a href="' . $location
402 . '/right_main.php?mailbox=' . urlencode($draft_folder)
403 . '&startMessage=1&note=' . urlencode($draft_message) .'">'
404 . _("Return") . '</a></center>';
412 if (isset($_FILES['attachfile']) &&
413 $_FILES['attachfile']['tmp_name'] &&
414 $_FILES['attachfile']['tmp_name'] != 'none') {
415 $AttachFailure = saveAttachedFiles($session);
417 if (checkInput(false) && !isset($AttachFailure)) {
418 if ($mailbox == "All Folders") {
419 /* We entered compose via the search results page */
420 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
422 $urlMailbox = urlencode (trim($mailbox));
423 if (! isset($passed_id)) {
427 * Set $default_charset to correspond with the user's selection
428 * of language interface.
432 * This is to change all newlines to \n
433 * We'll change them to \r\n later (in the sendMessage function)
435 $body = str_replace("\r\n", "\n", $body);
436 $body = str_replace("\r", "\n", $body);
439 * Rewrap $body so that no line is bigger than $editor_size
441 $body = explode("\n", $body);
443 foreach ($body as $line) {
444 if( $line <> '-- ' ) {
445 $line = rtrim($line);
447 if (sq_strlen($line,$default_charset) <= $editor_size +
1) {
448 $newBody .= $line . "\n";
450 sqWordWrap($line, $editor_size,$default_charset);
451 $newBody .= $line . "\n";
458 $composeMessage=$compose_messages[$session];
460 $Result = deliverMessage($composeMessage);
462 showInputForm($session);
465 unset($compose_messages[$session]);
466 /* if it is resumed draft, delete draft message */
467 if ( isset($delete_draft)) {
468 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, false);
469 sqimap_mailbox_select($imap_stream, $draft_folder);
470 // bypass_trash=true because message should be saved when deliverMessage() returns true.
471 // in current implementation of sqimap_msgs_list_flag() single message id can
472 // be submitted as string. docs state that it should be array.
473 sqimap_msgs_list_delete($imap_stream, $draft_folder, $delete_draft, true);
475 sqimap_mailbox_expunge($imap_stream, $draft_folder, true);
477 sqimap_logout($imap_stream);
479 if ($compose_new_win == '1') {
480 if ( !isset($pageheader_sent) ||
!$pageheader_sent ) {
481 Header("Location: $location/compose.php?mail_sent=yes");
483 echo ' <br><br><center><a href="' . $location
484 . '/compose.php?mail_sent=yes">'
485 . _("Return") . '</a></center>';
489 if ( !isset($pageheader_sent) ||
!$pageheader_sent ) {
490 Header("Location: $location/right_main.php?mailbox=$urlMailbox".
491 "&startMessage=$startMessage&mail_sent=yes");
493 echo ' <br><br><center><a href="' . $location
494 . "/right_main.php?mailbox=$urlMailbox"
495 . "&startMessage=$startMessage&mail_sent=yes\">"
496 . _("Return") . '</a></center>';
501 if ($compose_new_win == '1') {
502 compose_Header($color, $mailbox);
505 displayPageHeader($color, $mailbox);
507 if (isset($AttachFailure)) {
508 plain_error_message(_("Could not move/copy file. File not attached"),
512 showInputForm($session);
513 /* sqimap_logout($imapConnection); */
515 } elseif (isset($html_addr_search_done)) {
516 if ($compose_new_win == '1') {
517 compose_Header($color, $mailbox);
520 displayPageHeader($color, $mailbox);
523 if (isset($send_to_search) && is_array($send_to_search)) {
524 foreach ($send_to_search as $k => $v) {
525 if (substr($k, 0, 1) == 'T') {
531 elseif (substr($k, 0, 1) == 'C') {
537 elseif (substr($k, 0, 1) == 'B') {
539 $send_to_bcc .= ', ';
545 showInputForm($session);
546 } elseif (isset($html_addr_search)) {
547 if (isset($_FILES['attachfile']) &&
548 $_FILES['attachfile']['tmp_name'] &&
549 $_FILES['attachfile']['tmp_name'] != 'none') {
550 if(saveAttachedFiles($session)) {
551 plain_error_message(_("Could not move/copy file. File not attached"), $color);
555 * I am using an include so as to elminiate an extra unnecessary
556 * click. If you can think of a better way, please implement it.
558 include_once('./addrbook_search_html.php');
559 } elseif (isset($attach)) {
560 if (saveAttachedFiles($session)) {
561 plain_error_message(_("Could not move/copy file. File not attached"), $color);
563 if ($compose_new_win == '1') {
564 compose_Header($color, $mailbox);
566 displayPageHeader($color, $mailbox);
568 showInputForm($session);
570 elseif (isset($sigappend)) {
571 $signature = $idents[$identity]['signature'];
573 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
574 if ($compose_new_win == '1') {
575 compose_Header($color, $mailbox);
577 displayPageHeader($color, $mailbox);
579 showInputForm($session);
580 } elseif (isset($do_delete)) {
581 if ($compose_new_win == '1') {
582 compose_Header($color, $mailbox);
584 displayPageHeader($color, $mailbox);
587 if (isset($delete) && is_array($delete)) {
588 $composeMessage = $compose_messages[$session];
589 foreach($delete as $index) {
590 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
591 unlink ($attached_file);
592 unset ($composeMessage->entities
[$index]);
594 $new_entities = array();
595 foreach ($composeMessage->entities
as $entity) {
596 $new_entities[] = $entity;
598 $composeMessage->entities
= $new_entities;
599 $compose_messages[$session] = $composeMessage;
600 sqsession_register($compose_messages, 'compose_messages');
602 showInputForm($session);
605 * This handles the default case as well as the error case
606 * (they had the same code) --> if (isset($smtpErrors))
609 if ($compose_new_win == '1') {
610 compose_Header($color, $mailbox);
612 displayPageHeader($color, $mailbox);
617 if (!isset($passed_ent_id)) {
620 if (!isset($passed_id)) {
623 if (!isset($mailbox)) {
626 if (!isset($action)) {
630 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
632 /* in case the origin is not read_body.php */
633 if (isset($send_to)) {
634 $values['send_to'] = $send_to;
636 if (isset($send_to_cc)) {
637 $values['send_to_cc'] = $send_to_cc;
639 if (isset($send_to_bcc)) {
640 $values['send_to_bcc'] = $send_to_bcc;
642 if (isset($subject)) {
643 $values['subject'] = $subject;
645 showInputForm($session, $values);
650 /**************** Only function definitions go below *************/
652 function getforwardSubject($subject)
654 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
655 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
656 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
657 $subject = '[Fwd: ' . $subject . ']';
662 /* This function is used when not sending or adding attachments */
663 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
664 global $editor_size, $default_use_priority, $body, $idents,
665 $use_signature, $data_dir, $username,
666 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
667 $composeMessage, $body_quote;
668 global $languages, $squirrelmail_language, $default_charset;
671 * Set $default_charset to correspond with the user's selection
672 * of language interface. $default_charset global is not correct,
673 * if message is composed in new window.
677 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
681 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
684 sqimap_mailbox_select($imapConnection, $mailbox);
685 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
688 if ($passed_ent_id) {
689 /* redefine the messsage in case of message/rfc822 */
690 $message = $message->getEntity($passed_ent_id);
691 /* message is an entity which contains the envelope and type0=message
692 * and type1=rfc822. The actual entities are childs from
693 * $message->entities[0]. That's where the encoding and is located
696 $entities = $message->entities
[0]->findDisplayEntity
697 (array(), $alt_order = array('text/plain'));
698 if (!count($entities)) {
699 $entities = $message->entities
[0]->findDisplayEntity
700 (array(), $alt_order = array('text/plain','html/plain'));
702 $orig_header = $message->rfc822_header
; /* here is the envelope located */
703 /* redefine the message for picking up the attachments */
704 $message = $message->entities
[0];
707 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
708 if (!count($entities)) {
709 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
711 $orig_header = $message->rfc822_header
;
714 $type0 = $message->type0
;
715 $type1 = $message->type1
;
716 foreach ($entities as $ent) {
717 $msg = $message->getEntity($ent);
718 $type0 = $msg->type0
;
719 $type1 = $msg->type1
;
720 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
721 $body_part_entity = $message->getEntity($ent);
722 $bodypart = decodeBody($unencoded_bodypart,
723 $body_part_entity->header
->encoding
);
724 if ($type1 == 'html') {
725 $bodypart = str_replace("\n", ' ', $bodypart);
726 $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
727 $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart);
728 $bodypart = strip_tags($bodypart);
730 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
731 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) {
732 if (mb_detect_encoding($bodypart) != 'ASCII') {
733 $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart);
737 if (isset($body_part_entity->header
->parameters
['charset'])) {
738 $actual = $body_part_entity->header
->parameters
['charset'];
740 $actual = 'us-ascii';
743 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
744 $bodypart = charset_convert($actual,$bodypart,$default_charset,false);
749 if ($default_use_priority) {
750 $mailprio = substr($orig_header->priority
,0,1);
757 //ClearAttachments($session);
760 $from_o = $orig_header->from
;
761 if (is_array($from_o)) {
762 if (isset($from_o[0])) {
763 $from_o = $from_o[0];
766 if (is_object($from_o)) {
767 $orig_from = $from_o->getAddress();
772 $identities = array();
773 if (count($idents) > 1) {
774 foreach($idents as $nr=>$data) {
775 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
776 if($enc_from_name == $orig_from) {
780 $identities[] = $enc_from_name;
783 $identity_match = $orig_header->findAddress($identities);
784 if ($identity_match) {
785 $identity = $identity_match;
791 $use_signature = FALSE;
792 $composeMessage->rfc822_header
= $orig_header;
793 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
794 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
795 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
796 $send_from = $orig_header->getAddr_s('from');
797 $send_from_parts = new AddressStructure();
798 $send_from_parts = $orig_header->parseAddress($send_from);
799 $send_from_add = $send_from_parts->mailbox
. '@' . $send_from_parts->host
;
800 $identities = get_identities();
801 if (count($identities) > 0) {
802 foreach($identities as $iddata) {
803 if ($send_from_add == $iddata['email_address']) {
804 $identity = $iddata['index'];
809 $subject = decodeHeader($orig_header->subject
,false,false,true);
810 /* remember the references and in-reply-to headers in case of an reply */
811 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
812 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
813 // rewrap the body to clean up quotations and line lengths
814 sqBodyWrap($body, $editor_size);
815 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
817 case ('edit_as_new'):
818 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
819 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
820 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
821 $subject = decodeHeader($orig_header->subject
,false,false,true);
822 $mailprio = $orig_header->priority
;
824 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
825 // rewrap the body to clean up quotations and line lengths
826 sqBodyWrap($body, $editor_size);
830 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
831 $body = getforwardHeader($orig_header) . $body;
832 // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines
833 // forwarded message text should be as undisturbed as possible, so commenting out this call
834 // sqUnWordWrap($body);
835 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
837 //add a blank line after the forward headers
838 $body = "\n" . $body;
840 case ('forward_as_attachment'):
841 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,false,true));
842 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
846 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
847 $send_to = $orig_header->getAddr_s('mail_followup_to');
849 $send_to_cc = replyAllString($orig_header);
850 $send_to_cc = decodeHeader($send_to_cc,false,false,true);
853 // skip this if send_to was already set right above here
855 $send_to = $orig_header->reply_to
;
856 if (is_array($send_to) && count($send_to)) {
857 $send_to = $orig_header->getAddr_s('reply_to');
858 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
859 $send_to = $orig_header->getAddr_s('reply_to');
861 $send_to = $orig_header->getAddr_s('from');
864 $send_to = decodeHeader($send_to,false,false,true);
865 $subject = decodeHeader($orig_header->subject
,false,false,true);
866 $subject = str_replace('"', "'", $subject);
867 $subject = trim($subject);
868 if (substr(strtolower($subject), 0, 3) != 're:') {
869 $subject = 'Re: ' . $subject;
871 /* this corrects some wrapping/quoting problems on replies */
872 $rewrap_body = explode("\n", $body);
873 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
875 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
876 foreach ($rewrap_body as $line) {
877 if ($strip_sigs && substr($line,0,3) == '-- ') {
880 if (preg_match("/^(>+)/", $line, $matches)) {
882 $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n";
884 $body .= $body_quote . (!empty($body_quote) ?
' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ?
' ' : ''), rtrim($line)) . "\n";
888 //rewrap the body to clean up quotations and line lengths
889 $body = sqBodyWrap ($body, $editor_size);
891 $body = getReplyCitation($from , $orig_header->date
) . $body;
892 $composeMessage->reply_rfc822_header
= $orig_header;
898 $compose_messages[$session] = $composeMessage;
899 sqsession_register($compose_messages, 'compose_messages');
900 session_write_close();
901 sqimap_logout($imapConnection);
903 $ret = array( 'send_to' => $send_to,
904 'send_to_cc' => $send_to_cc,
905 'send_to_bcc' => $send_to_bcc,
906 'subject' => $subject,
907 'mailprio' => $mailprio,
909 'identity' => $identity );
912 } /* function newMail() */
915 * downloads attachments from original message, stores them in attachment directory and adds
916 * them to composed message.
917 * @param object $message
918 * @param object $composeMessage
919 * @param integer $passed_id
920 * @param mixed $entities
921 * @param mixed $imapConnection
924 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
925 global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages;
926 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
927 if (!count($message->entities
) ||
928 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
929 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
930 switch ($message->type0
) {
932 if ($message->type1
== 'rfc822') {
933 $filename = $message->rfc822_header
->subject
;
934 if ($filename == "") {
935 $filename = "untitled-".$message->entity_id
;
939 $filename = $message->getFilename();
943 if (!$message->mime_header
) { /* temporary hack */
944 $message->mime_header
= $message->header
;
946 $filename = $message->getFilename();
949 $filename = str_replace(' ', ' ', decodeHeader($filename));
950 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
951 function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) {
952 $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename);
954 $localfilename = GenerateRandomString(32, '', 7);
955 $full_localfilename = "$hashed_attachment_dir/$localfilename";
956 while (file_exists($full_localfilename)) {
957 $localfilename = GenerateRandomString(32, '', 7);
958 $full_localfilename = "$hashed_attachment_dir/$localfilename";
960 $message->att_local_name
= $full_localfilename;
962 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
963 $full_localfilename);
965 /* Write Attachment to file */
966 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
967 mime_print_body_lines ($imapConnection, $passed_id, $message->entity_id
, $message->header
->encoding
, $fp);
971 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
972 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
975 return $composeMessage;
978 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
979 $passed_ent_id='', $imapConnection) {
980 global $attachment_dir, $username, $data_dir;
981 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
982 if (!$passed_ent_id) {
983 $body_a = sqimap_run_command($imapConnection,
984 'FETCH '.$passed_id.' RFC822',
985 TRUE, $response, $readmessage,
988 $body_a = sqimap_run_command($imapConnection,
989 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
990 TRUE, $response, $readmessage, TRUE);
991 $message = $message->parent
;
993 if ($response == 'OK') {
994 $subject = encodeHeader($message->rfc822_header
->subject
);
995 array_shift($body_a);
997 $body = implode('', $body_a) . "\r\n";
999 $localfilename = GenerateRandomString(32, 'FILE', 7);
1000 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1002 $fp = fopen($full_localfilename, 'w');
1003 fwrite ($fp, $body);
1005 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
1006 $full_localfilename);
1008 return $composeMessage;
1011 function showInputForm ($session, $values=false) {
1012 global $send_to, $send_to_cc, $body, $startMessage, $action,
1013 $color, $use_signature, $signature, $prefix_sig,
1014 $editor_size, $editor_height, $subject, $newmail,
1015 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
1016 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
1017 $username, $data_dir, $identity, $idents, $delete_draft,
1018 $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first,
1019 $username, $compose_messages, $composesession, $default_charset;
1022 $composeMessage = $compose_messages[$session];
1024 $send_to = $values['send_to'];
1025 $send_to_cc = $values['send_to_cc'];
1026 $send_to_bcc = $values['send_to_bcc'];
1027 $subject = $values['subject'];
1028 $mailprio = $values['mailprio'];
1029 $body = $values['body'];
1030 $identity = (int) $values['identity'];
1032 $send_to = decodeHeader($send_to, true, false);
1033 $send_to_cc = decodeHeader($send_to_cc, true, false);
1034 $send_to_bcc = decodeHeader($send_to_bcc, true, false);
1037 if ($use_javascript_addr_book) {
1038 echo "\n". '<script language="JavaScript">'."\n<!--\n" .
1039 'function open_abook() { ' . "\n" .
1040 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
1041 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
1042 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
1043 ' nwin.opener = document.windows;' . "\n" .
1045 "// -->\n</script>\n\n";
1048 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
1049 'enctype="multipart/form-data"';
1050 do_hook('compose_form');
1054 echo addHidden('startMessage', $startMessage);
1056 if ($action == 'draft') {
1057 echo addHidden('delete_draft', $passed_id);
1059 if (isset($delete_draft)) {
1060 echo addHidden('delete_draft', $delete_draft);
1062 if (isset($session)) {
1063 echo addHidden('session', $session);
1066 if (isset($passed_id)) {
1067 echo addHidden('passed_id', $passed_id);
1070 if ($saved_draft == 'yes') {
1071 echo '<br /><center><b>'. _("Draft Saved").'</center></b>';
1073 if ($mail_sent == 'yes') {
1074 echo '<br /><center><b>'. _("Your Message has been sent.").'</center></b>';
1076 echo '<table align="center" cellspacing="0" border="0">' . "\n";
1077 if ($compose_new_win == '1') {
1078 echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
1079 ' <tr><td></td>'.html_tag( 'td', '', 'right' ).
1080 '<input type="button" name="Close" onclick="return self.close()" value="'.
1081 _("Close").'" /></td></tr>'."\n";
1083 if ($location_of_buttons == 'top') {
1084 showComposeButtonRow();
1087 /* display select list for identities */
1088 if (count($idents) > 1) {
1089 $ident_list = array();
1090 foreach($idents as $id => $data) {
1092 $data['full_name'].' <'.$data['email_address'].'>';
1094 echo ' <tr>' . "\n" .
1095 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1096 _("From:") . '</td>' . "\n" .
1097 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1099 addSelect('identity', $ident_list, $identity, TRUE);
1101 echo ' </td>' . "\n" .
1105 echo ' <tr>' . "\n" .
1106 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
1107 _("To") . ':</td>' . "\n" .
1108 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1109 addInput('send_to', $send_to, 60). '<br />' . "\n" .
1113 html_tag( 'td', '', 'right', $color[4] ) .
1114 _("Cc") . ':</td>' . "\n" .
1115 html_tag( 'td', '', 'left', $color[4] ) .
1116 addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
1120 html_tag( 'td', '', 'right', $color[4] ) .
1121 _("Bcc") . ':</td>' . "\n" .
1122 html_tag( 'td', '', 'left', $color[4] ) .
1123 addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
1127 html_tag( 'td', '', 'right', $color[4] ) .
1128 _("Subject") . ':</td>' . "\n" .
1129 html_tag( 'td', '', 'left', $color[4] ) . "\n";
1130 echo ' '.addInput('subject', $subject, 60).
1134 if ($location_of_buttons == 'between') {
1135 showComposeButtonRow();
1138 /* why this distinction? */
1139 if ($compose_new_win == '1') {
1140 echo ' <tr>' . "\n" .
1141 ' <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
1142 ' <textarea name="body" id="body" rows="' . (int)$editor_height .
1143 '" cols="' . (int)$editor_size . '" wrap="virtual">';
1146 echo ' <tr>' . "\n" .
1147 ' <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
1148 ' <textarea name="body" id="body" rows="' . (int)$editor_height .
1149 '" cols="' . (int)$editor_size . '" wrap="virtual">';
1152 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1153 $signature = $idents[$identity]['signature'];
1155 if ($sig_first == '1') {
1157 * FIXME: test is specific to ja_JP translation implementation.
1158 * This test might apply incorrect conversion to other translations, but
1159 * use of 7bit iso-2022-jp charset in other translations might have other
1162 if ($default_charset == 'iso-2022-jp') {
1163 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1165 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1167 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1170 echo "\n\n".htmlspecialchars(decodeHeader($body,false,false));
1171 // FIXME: test is specific to ja_JP translation implementation. See above comments.
1172 if ($default_charset == 'iso-2022-jp') {
1173 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1175 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1179 echo htmlspecialchars(decodeHeader($body,false,false));
1181 echo '</textarea><br />' . "\n" .
1186 if ($location_of_buttons == 'bottom') {
1187 showComposeButtonRow();
1189 echo ' <tr>' . "\n" .
1190 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1191 ' ' . addSubmit(_("Send"), 'send').
1192 ' <br /><br />' . "\n" .
1197 /* This code is for attachments */
1198 if ((bool) ini_get('file_uploads')) {
1200 /* Calculate the max size for an uploaded file.
1201 * This is advisory for the user because we can't actually prevent
1202 * people to upload too large files. */
1204 /* php.ini vars which influence the max for uploads */
1205 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1206 foreach($configvars as $var) {
1207 /* skip 0 or empty values, and -1 which means 'unlimited' */
1208 if( $size = getByteSize(ini_get($var)) ) {
1209 if ( $size != '-1' ) {
1215 if(count($sizes) > 0) {
1216 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1217 echo addHidden('MAX_FILE_SIZE', min( $sizes ));
1221 echo ' <tr>' . "\n" .
1222 ' <td colspan="2">' . "\n" .
1223 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1224 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1227 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1228 ' border="0">' . "\n" .
1230 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1231 _("Attach:") . '</td>' . "\n" .
1232 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1233 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1234 ' <input type="submit" name="attach"' .
1235 ' value="' . _("Add") .'" />' . "\n" .
1241 if ($composeMessage->entities
) {
1242 foreach ($composeMessage->entities
as $key => $attachment) {
1243 $attached_file = $attachment->att_local_name
;
1244 if ($attachment->att_local_name ||
$attachment->body_part
) {
1245 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1246 $type = $attachment->mime_header
->type0
.'/'.
1247 $attachment->mime_header
->type1
;
1249 $s_a[] = '<table bgcolor="'.$color[0].
1250 '" border="0"><tr><td>'.
1251 addCheckBox('delete[]', FALSE, $key).
1252 "</td><td>\n" . $attached_filename .
1253 '</td><td>-</td><td> ' . $type . '</td><td>('.
1254 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1259 foreach ($s_a as $s) {
1260 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1262 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1263 _("Delete selected attachments") . "\" />\n" .
1266 echo ' </table>' . "\n" .
1269 ' </table>' . "\n" .
1272 } // End of file_uploads if-block
1273 /* End of attachment code */
1274 if ($compose_new_win == '1') {
1275 echo '</table>'."\n";
1278 echo '</table>' . "\n" .
1279 addHidden('username', $username).
1280 addHidden('smaction', $action).
1281 addHidden('mailbox', $mailbox);
1283 store the complete ComposeMessages array in a hidden input value
1284 so we can restore them in case of a session timeout.
1286 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1287 echo addHidden('restoremessages', serialize($compose_messages)).
1288 addHidden('composesession', $composesession).
1289 addHidden('querystring', $queryString).
1291 if (!(bool) ini_get('file_uploads')) {
1292 /* File uploads are off, so we didn't show that part of the form.
1293 To avoid bogus bug reports, tell the user why. */
1294 echo '<p style="text-align:center">'
1295 . _("Because PHP file uploads are turned off, you can not attach files to this message. Please see your system administrator for details.")
1299 do_hook('compose_bottom');
1300 echo '</body></html>' . "\n";
1304 function showComposeButtonRow() {
1305 global $use_javascript_addr_book, $save_as_draft,
1306 $default_use_priority, $mailprio, $default_use_mdn,
1307 $request_mdn, $request_dr,
1308 $data_dir, $username;
1310 echo ' <tr>' . "\n" .
1311 ' <td></td>' . "\n" .
1313 if ($default_use_priority) {
1314 if(!isset($mailprio)) {
1317 echo ' ' . _("Priority") .
1318 addSelect('mailprio', array(
1321 '5' => _("Low") ), $mailprio, TRUE);
1323 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1324 if ($default_use_mdn) {
1325 if ($mdn_user_support) {
1326 echo ' ' . _("Receipt") .': '.
1327 addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
1328 addCheckBox('request_dr', $request_dr == '1', '1'). _("On Delivery");
1332 echo ' </td>' . "\n" .
1335 ' <td></td>' . "\n" .
1337 ' <input type="submit" name="sigappend" value="' . _("Signature") . '" />' . "\n";
1338 if ($use_javascript_addr_book) {
1339 echo " <script language=\"JavaScript\"><!--\n document.write(\"".
1340 " <input type=button value=\\\""._("Addresses").
1341 "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
1342 " // --></script><noscript>\n".
1343 ' <input type="submit" name="html_addr_search" value="'.
1344 _("Addresses").'" />'.
1347 echo ' <input type="submit" name="html_addr_search" value="'.
1348 _("Addresses").'" />' . "\n";
1351 if ($save_as_draft) {
1352 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\" />\n";
1355 echo ' <input type="submit" name="send" value="'. _("Send") . '" />' . "\n";
1356 do_hook('compose_button_row');
1358 echo ' </td>' . "\n" .
1362 function checkInput ($show) {
1364 * I implemented the $show variable because the error messages
1365 * were getting sent before the page header. So, I check once
1366 * using $show=false, and then when i'm ready to display the error
1367 * message, show=true
1369 global $body, $send_to, $send_to_bcc, $subject, $color;
1371 if ($send_to == '' && $send_to_bcc == '') {
1373 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1378 } /* function checkInput() */
1381 /* True if FAILURE */
1382 function saveAttachedFiles($session) {
1383 global $_FILES, $attachment_dir, $attachments, $username,
1384 $data_dir, $compose_messages;
1385 /* get out of here if no file was attached at all */
1386 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1390 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1391 $localfilename = GenerateRandomString(32, '', 7);
1392 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1393 while (file_exists($full_localfilename)) {
1394 $localfilename = GenerateRandomString(32, '', 7);
1395 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1398 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1399 // m_u_f works better with restricted PHP installs (safe_mode, open_basedir)
1400 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1401 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1405 $message = $compose_messages[$session];
1406 $type = strtolower($_FILES['attachfile']['type']);
1407 $name = $_FILES['attachfile']['name'];
1408 $message->initAttachment($type, $name, $full_localfilename);
1409 $compose_messages[$session] = $message;
1410 sqsession_register($compose_messages , 'compose_messages');
1413 function ClearAttachments($composeMessage) {
1414 if ($composeMessage->att_local_name
) {
1415 $attached_file = $composeMessage->att_local_name
;
1416 if (file_exists($attached_file)) {
1417 unlink($attached_file);
1420 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1421 ClearAttachments($composeMessage->entities
[$i]);
1425 /* parse values like 8M and 2k into bytes */
1426 function getByteSize($ini_size) {
1432 $ini_size = trim($ini_size);
1434 // if there's some kind of letter at the end of the string we need to multiply.
1435 if(!is_numeric(substr($ini_size, -1))) {
1437 switch(strtoupper(substr($ini_size, -1))) {
1439 $bytesize = 1073741824;
1442 $bytesize = 1048576;
1449 return ($bytesize * (int)substr($ini_size, 0, -1));
1457 * temporary function to make use of the deliver class.
1458 * In the future the responsable backend should be automaticly loaded
1459 * and conf.pl should show a list of available backends.
1460 * The message also should be constructed by the message class.
1462 function deliverMessage($composeMessage, $draft=false) {
1463 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1464 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1465 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1466 $domain, $action, $default_move_to_sent, $move_to_sent;
1467 global $imapServerAddress, $imapPort, $sent_folder, $key;
1469 $rfc822_header = $composeMessage->rfc822_header
;
1471 $abook = addressbook_init(false, true);
1472 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1473 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1474 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1475 $rfc822_header->priority
= $mailprio;
1476 $rfc822_header->subject
= $subject;
1478 $special_encoding='';
1479 if (strtolower($default_charset) == 'iso-2022-jp') {
1480 if (mb_detect_encoding($body) == 'ASCII') {
1481 $special_encoding = '8bit';
1483 $body = mb_convert_encoding($body, 'JIS');
1484 $special_encoding = '7bit';
1487 $composeMessage->setBody($body);
1489 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1490 $popuser = $usernamedata[1];
1491 $domain = $usernamedata[2];
1492 unset($usernamedata);
1494 $popuser = $username;
1497 $from_mail = $idents[$identity]['email_address'];
1498 $full_name = $idents[$identity]['full_name'];
1499 $reply_to = $idents[$identity]['reply_to'];
1501 $from_mail = "$popuser@$domain";
1503 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1505 $from = $rfc822_header->from
[0];
1506 if (!$from->host
) $from->host
= $domain;
1507 $full_name_encoded = encodeHeader($full_name);
1508 if ($full_name_encoded != $full_name) {
1509 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1511 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1513 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1516 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1518 /* Receipt: On Read */
1519 if (isset($request_mdn) && $request_mdn) {
1520 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1522 /* Receipt: On Delivery */
1523 if (isset($request_dr) && $request_dr) {
1524 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1526 /* multipart messages */
1527 if (count($composeMessage->entities
)) {
1528 $message_body = new Message();
1529 $message_body->body_part
= $composeMessage->body_part
;
1530 $composeMessage->body_part
= '';
1531 $mime_header = new MessageHeader
;
1532 $mime_header->type0
= 'text';
1533 $mime_header->type1
= 'plain';
1534 if ($special_encoding) {
1535 $mime_header->encoding
= $special_encoding;
1537 $mime_header->encoding
= '8bit';
1539 if ($default_charset) {
1540 $mime_header->parameters
['charset'] = $default_charset;
1542 $message_body->mime_header
= $mime_header;
1543 array_unshift($composeMessage->entities
, $message_body);
1544 $content_type = new ContentType('multipart/mixed');
1546 $content_type = new ContentType('text/plain');
1547 if ($special_encoding) {
1548 $rfc822_header->encoding
= $special_encoding;
1550 $rfc822_header->encoding
= '8bit';
1552 if ($default_charset) {
1553 $content_type->properties
['charset']=$default_charset;
1557 $rfc822_header->content_type
= $content_type;
1558 $composeMessage->rfc822_header
= $rfc822_header;
1560 /* Here you can modify the message structure just before we hand
1561 it over to deliver */
1562 $hookReturn = do_hook('compose_send', $composeMessage);
1563 /* Get any changes made by plugins to $composeMessage. */
1564 if ( is_object($hookReturn[1]) ) {
1565 $composeMessage = $hookReturn[1];
1568 if (!$useSendmail && !$draft) {
1569 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1570 $deliver = new Deliver_SMTP();
1571 global $smtpServerAddress, $smtpPort, $pop_before_smtp;
1573 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1574 get_smtp_user($user, $pass);
1575 $stream = $deliver->initStream($composeMessage,$domain,0,
1576 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1577 } elseif (!$draft) {
1578 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1579 global $sendmail_path;
1580 $deliver = new Deliver_SendMail();
1581 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1583 global $draft_folder;
1584 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1585 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1587 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1588 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1589 $imap_deliver = new Deliver_IMAP();
1590 $length = $imap_deliver->mail($composeMessage);
1591 sqimap_append ($imap_stream, $draft_folder, $length);
1592 $imap_deliver->mail($composeMessage, $imap_stream);
1593 sqimap_append_done ($imap_stream, $draft_folder);
1594 sqimap_logout($imap_stream);
1595 unset ($imap_deliver);
1598 $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
1599 plain_error_message($msg, $color);
1605 $length = $deliver->mail($composeMessage, $stream);
1606 $succes = $deliver->finalizeStream($stream);
1609 $msg = $deliver->dlv_msg
. '<br />' .
1610 _("Server replied:") . ' ' . $deliver->dlv_ret_nr
. ' ' .
1611 $deliver->dlv_server_msg
;
1612 plain_error_message($msg, $color);
1615 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1616 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1618 /* Move to sent code */
1619 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1620 $svr_allow_sent = true;
1622 $svr_allow_sent = false;
1625 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1626 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1632 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1633 $lcl_allow_sent = true;
1635 $lcl_allow_sent = false;
1638 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1639 global $passed_id, $mailbox, $action;
1640 if ($action == 'reply' ||
$action == 'reply_all') {
1641 $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1642 if ($save_reply_with_orig) {
1643 $sent_folder = $mailbox;
1646 sqimap_append ($imap_stream, $sent_folder, $length);
1647 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1648 $imap_deliver = new Deliver_IMAP();
1649 $imap_deliver->mail($composeMessage, $imap_stream);
1650 sqimap_append_done ($imap_stream, $sent_folder);
1651 unset ($imap_deliver);
1653 global $passed_id, $mailbox, $action;
1654 ClearAttachments($composeMessage);
1655 if ($action == 'reply' ||
$action == 'reply_all') {
1656 sqimap_mailbox_select ($imap_stream, $mailbox);
1657 sqimap_toggle_flag($imap_stream, array($passed_id), '\\Answered', true, false);
1659 sqimap_logout($imap_stream);