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:
20 /* Path for SquirrelMail required files. */
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 require_once(SM_PATH
. 'functions/global.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/date.php');
28 require_once(SM_PATH
. 'functions/mime.php');
29 require_once(SM_PATH
. 'functions/plugin.php');
30 require_once(SM_PATH
. 'functions/display_messages.php');
31 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
32 require_once(SM_PATH
. 'functions/addressbook.php');
33 require_once(SM_PATH
. 'functions/identity.php');
35 /* --------------------- Get globals ------------------------------------- */
37 sqgetGlobalVar('key', $key, SQ_COOKIE
);
40 sqgetGlobalVar('username', $username, SQ_SESSION
);
41 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
42 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
43 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
45 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
46 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
48 /** SESSION/POST/GET VARS */
49 sqgetGlobalVar('smaction',$action);
50 sqgetGlobalVar('session',$session);
51 sqgetGlobalVar('mailbox',$mailbox);
52 if(!sqgetGlobalVar('identity',$identity)) {
55 sqgetGlobalVar('send_to',$send_to);
56 sqgetGlobalVar('send_to_cc',$send_to_cc);
57 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
58 sqgetGlobalVar('subject',$subject);
59 sqgetGlobalVar('body',$body);
60 sqgetGlobalVar('mailprio',$mailprio);
61 sqgetGlobalVar('request_mdn',$request_mdn);
62 sqgetGlobalVar('request_dr',$request_dr);
63 sqgetGlobalVar('html_addr_search',$html_addr_search);
64 sqgetGlobalVar('mail_sent',$mail_sent);
65 sqgetGlobalVar('passed_id',$passed_id);
66 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
67 sqgetGlobalVar('send',$send);
69 sqgetGlobalVar('attach',$attach);
71 sqgetGlobalVar('draft',$draft);
72 sqgetGlobalVar('draft_id',$draft_id);
73 sqgetGlobalVar('ent_num',$ent_num);
74 sqgetGlobalVar('saved_draft',$saved_draft);
75 sqgetGlobalVar('delete_draft',$delete_draft);
76 sqgetGlobalVar('startmessage',$startMessage);
79 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
80 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
81 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
82 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
83 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
84 sqgetGlobalVar('delete', $delete, SQ_POST
);
85 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
86 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
87 $html_addr_search_done = 'Use Addresses';
91 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
93 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
94 $location = get_location();
95 /* Identities (fetch only once) */
96 $idents = get_identities();
98 /* --------------------- Specific Functions ------------------------------ */
100 function replyAllString($header) {
101 global $include_self_reply_all, $idents;
104 * 1) Remove the addresses we'll be sending the message 'to'
106 $url_replytoall_avoid_addrs = '';
107 if (isset($header->replyto
)) {
108 $excl_ar = $header->getAddr_a('replyto');
111 * 2) Remove our identities from the CC list (they still can be in the
112 * TO list) only if $include_self_reply_all is turned off
114 if (!$include_self_reply_all) {
115 foreach($idents as $id) {
116 $excl_ar[strtolower(trim($id['email_address']))] = '';
121 * 3) get the addresses.
123 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
126 * 4) generate the string.
128 $url_replytoallcc = '';
129 foreach( $url_replytoall_ar as $email => $personal) {
131 // if personal name contains address separator then surround
132 // the personal name with double quotes.
133 if (strpos($personal,',') !== false) {
134 $personal = '"'.$personal.'"';
136 $url_replytoallcc .= ", $personal <$email>";
138 $url_replytoallcc .= ', '. $email;
141 $url_replytoallcc = substr($url_replytoallcc,2);
143 return $url_replytoallcc;
146 function getReplyCitation($orig_from) {
147 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
148 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
149 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
150 /* First, return an empty string when no citation style selected. */
151 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
155 /* Make sure our final value isn't an empty string. */
156 if ($orig_from == '') {
160 /* Otherwise, try to select the desired citation style. */
161 switch ($reply_citation_style) {
164 $end = ' ' . _("said") . ':';
167 $start = '<' . _("quote") . ' ' . _("who") . '="';
171 $start = $reply_citation_start .
172 ($reply_citation_start == '' ?
'' : ' ');
173 $end = $reply_citation_end;
179 /* Build and return the citation string. */
180 return ($start . $orig_from . $end . "\n");
183 function getforwardHeader($orig_header) {
186 $display = array( _("Subject") => strlen(_("Subject")),
187 _("From") => strlen(_("From")),
188 _("Date") => strlen(_("Date")),
189 _("To") => strlen(_("To")),
190 _("Cc") => strlen(_("Cc")) );
191 $maxsize = max($display);
192 $indent = str_pad('',$maxsize+
2);
193 foreach($display as $key => $val) {
194 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
196 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
197 $from = str_replace(' ',' ',$from);
198 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
199 $to = str_replace(' ',' ',$to);
200 $subject = decodeHeader($orig_header->subject
,false,false);
201 $subject = str_replace(' ',' ',$subject);
202 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
203 "\n". $display[_("Subject")] . $subject . "\n" .
204 $display[_("From")] . $from . "\n" .
205 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
206 $display[_("To")] . $to . "\n";
207 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
208 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
209 $cc = str_replace(' ',' ',$cc);
210 $bodyTop .= $display[_("Cc")] .$cc . "\n";
212 $bodyTop .= str_pad('', $editor_size -2 , '-') .
216 /* ----------------------------------------------------------------------- */
219 * If the session is expired during a post this restores the compose session
222 if (sqsession_is_registered('session_expired_post')) {
223 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
225 * extra check for username so we don't display previous post data from
226 * another user during this session.
228 if ($session_expired_post['username'] != $username) {
229 unset($session_expired_post);
230 sqsession_unregister('session_expired_post');
231 session_write_close();
233 foreach ($session_expired_post as $postvar => $val) {
240 $compose_messages = unserialize(urldecode($restoremessages));
241 sqsession_register($compose_messages,'compose_messages');
242 sqsession_register($composesession,'composesession');
246 $session_expired = true;
248 unset($session_expired_post);
249 sqsession_unregister('session_expired_post');
250 session_write_close();
251 if (!isset($mailbox)) {
254 if ($compose_new_win == '1') {
255 compose_Header($color, $mailbox);
257 displayPageHeader($color, $mailbox);
259 showInputForm($session, false);
262 if (!isset($composesession)) {
264 sqsession_register(0,'composesession');
267 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
268 sqsession_unregister('composesession');
269 $session = "$composesession" +
1;
270 $composesession = $session;
271 sqsession_register($composesession,'composesession');
273 if (!isset($compose_messages)) {
274 $compose_messages = array();
276 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
277 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
278 $composeMessage = new Message();
279 $rfc822_header = new Rfc822Header();
280 $composeMessage->rfc822_header
= $rfc822_header;
281 $composeMessage->reply_rfc822_header
= '';
282 $compose_messages[$session] = $composeMessage;
283 sqsession_register($compose_messages,'compose_messages');
285 $composeMessage=$compose_messages[$session];
288 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
294 * Set $default_charset to correspond with the user's selection
295 * of language interface.
298 $composeMessage=$compose_messages[$session];
299 if (! deliverMessage($composeMessage, true)) {
300 showInputForm($session);
303 unset($compose_messages[$session]);
304 $draft_message = _("Draft Email Saved");
305 /* If this is a resumed draft, then delete the original */
306 if(isset($delete_draft)) {
307 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
308 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
312 if ($compose_new_win == '1') {
313 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
317 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
318 "&startMessage=1¬e=".urlencode($draft_message));
326 if (isset($_FILES['attachfile']) &&
327 $_FILES['attachfile']['tmp_name'] &&
328 $_FILES['attachfile']['tmp_name'] != 'none') {
329 $AttachFailure = saveAttachedFiles($session);
331 if (checkInput(false) && !isset($AttachFailure)) {
332 if ($mailbox == "All Folders") {
333 /* We entered compose via the search results page */
334 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
336 $urlMailbox = urlencode (trim($mailbox));
337 if (! isset($passed_id)) {
341 * Set $default_charset to correspond with the user's selection
342 * of language interface.
346 * This is to change all newlines to \n
347 * We'll change them to \r\n later (in the sendMessage function)
349 $body = str_replace("\r\n", "\n", $body);
350 $body = str_replace("\r", "\n", $body);
353 * Rewrap $body so that no line is bigger than $editor_size
354 * This should only really kick in the sqWordWrap function
355 * if the browser doesn't support "VIRTUAL" as the wrap type.
357 $body = explode("\n", $body);
359 foreach ($body as $line) {
360 if( $line <> '-- ' ) {
361 $line = rtrim($line);
363 if (strlen($line) <= $editor_size +
1) {
364 $newBody .= $line . "\n";
366 sqWordWrap($line, $editor_size);
367 $newBody .= $line . "\n";
374 $composeMessage=$compose_messages[$session];
376 $Result = deliverMessage($composeMessage);
378 showInputForm($session);
381 unset($compose_messages[$session]);
382 if ( isset($delete_draft)) {
383 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
384 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
387 if ($compose_new_win == '1') {
389 Header("Location: $location/compose.php?mail_sent=yes");
392 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
393 "&startMessage=$startMessage&mail_sent=yes");
396 if ($compose_new_win == '1') {
397 compose_Header($color, $mailbox);
400 displayPageHeader($color, $mailbox);
402 if (isset($AttachFailure)) {
403 plain_error_message(_("Could not move/copy file. File not attached"),
407 showInputForm($session);
408 /* sqimap_logout($imapConnection); */
410 } elseif (isset($html_addr_search_done)) {
411 if ($compose_new_win == '1') {
412 compose_Header($color, $mailbox);
415 displayPageHeader($color, $mailbox);
418 if (isset($send_to_search) && is_array($send_to_search)) {
419 foreach ($send_to_search as $k => $v) {
420 if (substr($k, 0, 1) == 'T') {
426 elseif (substr($k, 0, 1) == 'C') {
432 elseif (substr($k, 0, 1) == 'B') {
434 $send_to_bcc .= ', ';
440 showInputForm($session);
441 } elseif (isset($html_addr_search)) {
442 if (isset($_FILES['attachfile']) &&
443 $_FILES['attachfile']['tmp_name'] &&
444 $_FILES['attachfile']['tmp_name'] != 'none') {
445 if(saveAttachedFiles($session)) {
446 plain_error_message(_("Could not move/copy file. File not attached"), $color);
450 * I am using an include so as to elminiate an extra unnecessary
451 * click. If you can think of a better way, please implement it.
453 include_once('./addrbook_search_html.php');
454 } elseif (isset($attach)) {
455 if (saveAttachedFiles($session)) {
456 plain_error_message(_("Could not move/copy file. File not attached"), $color);
458 if ($compose_new_win == '1') {
459 compose_Header($color, $mailbox);
462 displayPageHeader($color, $mailbox);
464 showInputForm($session);
466 elseif (isset($sigappend)) {
467 $signature = $idents[$identity]['signature'];
469 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
470 if ($compose_new_win == '1') {
471 compose_Header($color, $mailbox);
473 displayPageHeader($color, $mailbox);
475 showInputForm($session);
476 } elseif (isset($do_delete)) {
477 if ($compose_new_win == '1') {
478 compose_Header($color, $mailbox);
481 displayPageHeader($color, $mailbox);
484 if (isset($delete) && is_array($delete)) {
485 $composeMessage = $compose_messages[$session];
486 foreach($delete as $index) {
487 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
488 unlink ($attached_file);
489 unset ($composeMessage->entities
[$index]);
491 $new_entities = array();
492 foreach ($composeMessage->entities
as $entity) {
493 $new_entities[] = $entity;
495 $composeMessage->entities
= $new_entities;
496 $compose_messages[$session] = $composeMessage;
497 sqsession_register($compose_messages, 'compose_messages');
499 showInputForm($session);
502 * This handles the default case as well as the error case
503 * (they had the same code) --> if (isset($smtpErrors))
506 if ($compose_new_win == '1') {
507 compose_Header($color, $mailbox);
509 displayPageHeader($color, $mailbox);
514 if (!isset($passed_ent_id)) {
517 if (!isset($passed_id)) {
520 if (!isset($mailbox)) {
523 if (!isset($action)) {
527 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
529 /* in case the origin is not read_body.php */
530 if (isset($send_to)) {
531 $values['send_to'] = $send_to;
533 if (isset($send_to_cc)) {
534 $values['send_to_cc'] = $send_to_cc;
536 if (isset($send_to_bcc)) {
537 $values['send_to_bcc'] = $send_to_bcc;
539 if (isset($subject)) {
540 $values['subject'] = $subject;
542 showInputForm($session, $values);
547 /**************** Only function definitions go below *************/
549 function getforwardSubject($subject)
551 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
552 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
553 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
554 $subject = '[Fwd: ' . $subject . ']';
559 /* This function is used when not sending or adding attachments */
560 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
561 global $editor_size, $default_use_priority, $body, $idents,
562 $use_signature, $composesession, $data_dir, $username,
563 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
565 global $languages, $squirrelmail_language;
567 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
571 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
574 sqimap_mailbox_select($imapConnection, $mailbox);
575 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
578 if ($passed_ent_id) {
579 /* redefine the messsage in case of message/rfc822 */
580 $message = $message->getEntity($passed_ent_id);
581 /* message is an entity which contains the envelope and type0=message
582 * and type1=rfc822. The actual entities are childs from
583 * $message->entities[0]. That's where the encoding and is located
586 $entities = $message->entities
[0]->findDisplayEntity
587 (array(), $alt_order = array('text/plain'));
588 if (!count($entities)) {
589 $entities = $message->entities
[0]->findDisplayEntity
590 (array(), $alt_order = array('text/plain','html/plain'));
592 $orig_header = $message->rfc822_header
; /* here is the envelope located */
593 /* redefine the message for picking up the attachments */
594 $message = $message->entities
[0];
597 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
598 if (!count($entities)) {
599 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
601 $orig_header = $message->rfc822_header
;
604 $encoding = $message->header
->encoding
;
605 $type0 = $message->type0
;
606 $type1 = $message->type1
;
607 foreach ($entities as $ent) {
608 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
609 $body_part_entity = $message->getEntity($ent);
610 $bodypart = decodeBody($unencoded_bodypart,
611 $body_part_entity->header
->encoding
);
612 if ($type1 == 'html') {
613 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
614 $bodypart = strip_tags($bodypart);
616 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
617 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
618 if (mb_detect_encoding($bodypart) != 'ASCII') {
619 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
624 if ($default_use_priority) {
625 $mailprio = substr($orig_header->priority
,0,1);
632 //ClearAttachments($session);
635 $from_o = $orig_header->from
;
636 if (is_object($from_o)) {
637 $orig_from = $from_o->getAddress();
642 $identities = array();
643 if (count($idents) > 1) {
644 foreach($idents as $nr=>$data) {
645 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
646 if($enc_from_name == $orig_from) {
650 $identities[] = $enc_from_name;
653 $identity_match = $orig_header->findAddress($identities);
654 if ($identity_match) {
655 $identity = $identity_match;
661 $use_signature = FALSE;
662 $composeMessage->rfc822_header
= $orig_header;
663 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
664 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
665 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
666 $subject = decodeHeader($orig_header->subject
,false,true);
667 // /* remember the references and in-reply-to headers in case of an reply */
668 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
669 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
670 $body_ary = explode("\n", $body);
671 $cnt = count($body_ary) ;
673 for ($i=0; $i < $cnt; $i++
) {
674 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
675 sqWordWrap($body_ary[$i], $editor_size );
676 $body .= $body_ary[$i] . "\n";
678 unset($body_ary[$i]);
681 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
683 case ('edit_as_new'):
684 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
685 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
686 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
687 $subject = decodeHeader($orig_header->subject
,false,true);
688 $mailprio = $orig_header->priority
;
690 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
695 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
696 $body = getforwardHeader($orig_header) . $body;
698 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
699 $body = "\n" . $body;
701 case ('forward_as_attachment'):
702 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
703 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
707 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
708 $send_to = $orig_header->getAddr_s('mail_followup_to');
710 $send_to_cc = replyAllString($orig_header);
711 $send_to_cc = decodeHeader($send_to_cc,false,true);
714 // skip this if send_to was already set right above here
716 $send_to = $orig_header->reply_to
;
717 if (is_array($send_to) && count($send_to)) {
718 $send_to = $orig_header->getAddr_s('reply_to');
719 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
720 $send_to = $orig_header->getAddr_s('reply_to');
722 $send_to = $orig_header->getAddr_s('from');
725 $send_to = decodeHeader($send_to,false,true);
726 $subject = decodeHeader($orig_header->subject
,false,true);
727 $subject = str_replace('"', "'", $subject);
728 $subject = trim($subject);
729 if (substr(strtolower($subject), 0, 3) != 're:') {
730 $subject = 'Re: ' . $subject;
732 /* this corrects some wrapping/quoting problems on replies */
733 $rewrap_body = explode("\n", $body);
734 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
735 sqUnWordWrap($body); // unwrap and then reset it?!
737 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
738 foreach ($rewrap_body as $line) {
739 if ($strip_sigs && substr($line,0,3) == '-- ') {
742 sqWordWrap($line, ($editor_size));
743 if (preg_match("/^(>+)/", $line, $matches)) {
745 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
747 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
750 $body = getReplyCitation($from) . $body;
751 $composeMessage->reply_rfc822_header
= $orig_header;
757 $compose_messages[$session] = $composeMessage;
758 sqsession_register($compose_messages, 'compose_messages');
759 session_write_close();
760 sqimap_logout($imapConnection);
762 $ret = array( 'send_to' => $send_to,
763 'send_to_cc' => $send_to_cc,
764 'send_to_bcc' => $send_to_bcc,
765 'subject' => $subject,
766 'mailprio' => $mailprio,
768 'identity' => $identity );
771 } /* function newMail() */
773 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
774 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
775 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
776 if (!count($message->entities
) ||
777 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
778 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
779 switch ($message->type0
) {
781 if ($message->type1
== 'rfc822') {
782 $filename = $message->rfc822_header
->subject
;
783 if ($filename == "") {
784 $filename = "untitled-".$message->entity_id
;
788 $filename = $message->getFilename();
792 if (!$message->mime_header
) { /* temporary hack */
793 $message->mime_header
= $message->header
;
795 $filename = $message->getFilename();
798 $filename = str_replace(' ', ' ', decodeHeader($filename));
799 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
800 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
801 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
803 $localfilename = GenerateRandomString(32, '', 7);
804 $full_localfilename = "$hashed_attachment_dir/$localfilename";
805 while (file_exists($full_localfilename)) {
806 $localfilename = GenerateRandomString(32, '', 7);
807 $full_localfilename = "$hashed_attachment_dir/$localfilename";
809 $message->att_local_name
= $full_localfilename;
811 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
812 $full_localfilename);
814 /* Write Attachment to file */
815 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
816 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
817 $passed_id, $message->entity_id
),
818 $message->header
->encoding
));
822 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
823 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
826 return $composeMessage;
829 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
830 $passed_ent_id='', $imapConnection) {
831 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
832 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
833 if (!$passed_ent_id) {
834 $body_a = sqimap_run_command($imapConnection,
835 'FETCH '.$passed_id.' RFC822',
836 TRUE, $response, $readmessage,
839 $body_a = sqimap_run_command($imapConnection,
840 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
841 TRUE, $response, $readmessage, $uid_support);
842 $message = $message->parent
;
844 if ($response == 'OK') {
845 $subject = encodeHeader($message->rfc822_header
->subject
);
846 array_shift($body_a);
848 $body = implode('', $body_a) . "\r\n";
850 $localfilename = GenerateRandomString(32, 'FILE', 7);
851 $full_localfilename = "$hashed_attachment_dir/$localfilename";
853 $fp = fopen($full_localfilename, 'w');
856 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
857 $full_localfilename);
859 return $composeMessage;
862 function showInputForm ($session, $values=false) {
863 global $send_to, $send_to_cc, $body, $startMessage,
864 $passed_body, $color, $use_signature, $signature, $prefix_sig,
865 $editor_size, $attachments, $subject, $newmail,
866 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
867 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
868 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
869 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
870 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
871 $username, $compose_messages, $composesession, $default_charset;
873 $composeMessage = $compose_messages[$session];
876 $send_to = $values['send_to'];
877 $send_to_cc = $values['send_to_cc'];
878 $send_to_bcc = $values['send_to_bcc'];
879 $subject = $values['subject'];
880 $mailprio = $values['mailprio'];
881 $body = $values['body'];
882 $identity = (int) $values['identity'];
884 $send_to = decodeHeader($send_to);
885 $send_to_cc = decodeHeader($send_to_cc);
886 $send_to_bcc = decodeHeader($send_to_bcc);
889 if ($use_javascript_addr_book) {
890 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
891 'function open_abook() { ' . "\n" .
892 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
893 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
894 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
895 ' nwin.opener = document.windows;' . "\n" .
897 "// -->\n</SCRIPT>\n\n";
900 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
901 'enctype="multipart/form-data"';
902 do_hook('compose_form');
906 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
908 if ($action == 'draft') {
909 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
911 if (isset($delete_draft)) {
912 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
914 if (isset($session)) {
915 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
918 if (isset($passed_id)) {
919 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
922 if ($saved_draft == 'yes') {
923 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
925 if ($mail_sent == 'yes') {
926 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
928 echo '<table align="center" cellspacing="0" border="0">' . "\n";
929 if ($compose_new_win == '1') {
930 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
931 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
933 if ($location_of_buttons == 'top') {
934 showComposeButtonRow();
937 /* display select list for identities */
938 if (count($idents) > 1) {
939 echo ' <tr>' . "\n" .
940 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
941 _("From:") . '</td>' . "\n" .
942 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
943 ' <select name="identity">' . "\n" ;
944 foreach($idents as $id=>$data) {
945 echo '<option value="'.$id.'"';
946 if($id == $identity) {
949 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
953 echo '</select>' . "\n" .
957 echo ' <tr>' . "\n" .
958 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
959 _("To:") . '</TD>' . "\n" .
960 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
961 ' <input type="text" name="send_to" value="' .
962 $send_to . '" size="60" /><br />' . "\n" .
966 html_tag( 'td', '', 'right', $color[4] ) .
967 _("CC:") . '</td>' . "\n" .
968 html_tag( 'td', '', 'left', $color[4] ) .
969 ' <input type="text" name="send_to_cc" size="60" value="' .
970 $send_to_cc . '" /><br />' . "\n" .
974 html_tag( 'td', '', 'right', $color[4] ) .
975 _("BCC:") . '</td>' . "\n" .
976 html_tag( 'td', '', 'left', $color[4] ) .
977 ' <input type="text" name="send_to_bcc" value="' .
978 $send_to_bcc . '" size="60" /><br />' . "\n" .
982 html_tag( 'td', '', 'right', $color[4] ) .
983 _("Subject:") . '</td>' . "\n" .
984 html_tag( 'td', '', 'left', $color[4] ) . "\n";
985 echo ' <input type="text" name="subject" size="60" value="' .
986 $subject . '" />' . "\n" .
990 if ($location_of_buttons == 'between') {
991 showComposeButtonRow();
994 /* why this distinction? */
995 if ($compose_new_win == '1') {
996 echo ' <TR>' . "\n" .
997 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
998 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
999 $editor_size . '" WRAP="VIRTUAL">';
1002 echo ' <TR>' . "\n" .
1003 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1004 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1005 $editor_size . '" WRAP="VIRTUAL">';
1008 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1009 $signature = $idents[$identity]['signature'];
1011 if ($sig_first == '1') {
1012 if ($default_charset == 'iso-2022-jp') {
1013 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1015 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1017 echo "\n\n".decodeHeader($body,false,false);
1020 echo "\n\n".decodeHeader($body,false,false);
1021 if ($default_charset == 'iso-2022-jp') {
1022 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1024 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1029 echo decodeHeader($body,false,false);
1031 echo '</textarea><br />' . "\n" .
1036 if ($location_of_buttons == 'bottom') {
1037 showComposeButtonRow();
1039 echo ' <tr>' . "\n" .
1040 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1041 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1042 ' <br /><br />' . "\n" .
1047 /* This code is for attachments */
1048 if ((bool) ini_get('file_uploads')) {
1050 /* Calculate the max size for an uploaded file.
1051 * This is advisory for the user because we can't actually prevent
1052 * people to upload too large files. */
1054 /* php.ini vars which influence the max for uploads */
1055 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1056 foreach($configvars as $var) {
1057 /* skip 0 or empty values */
1058 if( $size = getByteSize(ini_get($var)) ) {
1063 if(count($sizes) > 0) {
1064 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1068 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1069 echo ' <tr>' . "\n" .
1070 ' <td colspan="2">' . "\n" .
1071 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1072 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1075 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1076 ' border="0">' . "\n" .
1078 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1079 _("Attach:") . '</td>' . "\n" .
1080 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1081 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1082 ' <input type="submit" name="attach"' .
1083 ' value="' . _("Add") .'">' . "\n" .
1090 if ($composeMessage->entities
) {
1091 foreach ($composeMessage->entities
as $key => $attachment) {
1092 $attached_file = $attachment->att_local_name
;
1093 if ($attachment->att_local_name ||
$attachment->body_part
) {
1094 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1095 $type = $attachment->mime_header
->type0
.'/'.
1096 $attachment->mime_header
->type1
;
1098 $s_a[] = '<table bgcolor="'.$color[0].
1099 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1100 $key . "\"></td><td>\n" . $attached_filename .
1101 '</td><td>-</td><td> ' . $type . '</td><td>('.
1102 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1107 foreach ($s_a as $s) {
1108 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1110 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1111 _("Delete selected attachments") . "\">\n" .
1114 echo ' </table>' . "\n" .
1117 ' </TABLE>' . "\n" .
1120 } // End of file_uploads if-block
1121 /* End of attachment code */
1122 if ($compose_new_win == '1') {
1123 echo '</TABLE>'."\n";
1126 echo '</TABLE>' . "\n" .
1127 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1128 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1129 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1132 store the complete ComposeMessages array in a hidden input value
1133 so we can restore them in case of a session timeout.
1135 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1136 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1137 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1138 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1140 if (!(bool) ini_get('file_uploads')) {
1141 /* File uploads are off, so we didn't show that part of the form.
1142 To avoid bogus bug reports, tell the user why. */
1143 echo 'Because PHP file uploads are turned off, you can not attach files ';
1144 echo "to this message. Please see your system administrator for details.\r\n";
1147 do_hook('compose_bottom');
1148 echo '</BODY></HTML>' . "\n";
1152 function showComposeButtonRow() {
1153 global $use_javascript_addr_book, $save_as_draft,
1154 $default_use_priority, $mailprio, $default_use_mdn,
1155 $request_mdn, $request_dr,
1156 $data_dir, $username;
1158 echo ' <TR>' . "\n" .
1159 ' <TD></TD>' . "\n" .
1161 if ($default_use_priority) {
1162 if(!isset($mailprio)) {
1165 echo ' ' . _("Priority") .': <select name="mailprio">'.
1166 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1167 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1168 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1171 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1172 if ($default_use_mdn) {
1173 if ($mdn_user_support) {
1174 echo ' ' . _("Receipt") .': '.
1175 '<input type="checkbox" name="request_mdn" value=1'.
1176 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1177 ' <input type="checkbox" name="request_dr" value=1'.
1178 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1182 echo ' </TD>' . "\n" .
1185 ' <TD></TD>' . "\n" .
1187 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1188 if ($use_javascript_addr_book) {
1189 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1190 " <input type=button value=\\\""._("Addresses").
1191 "\\\" onclick='javascript:open_abook();'>\");".
1192 " // --></SCRIPT><NOSCRIPT>\n".
1193 " <input type=submit name=\"html_addr_search\" value=\"".
1194 _("Addresses")."\">".
1197 echo ' <input type=submit name="html_addr_search" value="'.
1198 _("Addresses").'">' . "\n";
1201 if ($save_as_draft) {
1202 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1205 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1206 do_hook('compose_button_row');
1208 echo ' </TD>' . "\n" .
1212 function checkInput ($show) {
1214 * I implemented the $show variable because the error messages
1215 * were getting sent before the page header. So, I check once
1216 * using $show=false, and then when i'm ready to display the error
1217 * message, show=true
1219 global $body, $send_to, $send_to_bcc, $subject, $color;
1221 if ($send_to == '' && $send_to_bcc == '') {
1223 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1228 } /* function checkInput() */
1231 /* True if FAILURE */
1232 function saveAttachedFiles($session) {
1233 global $_FILES, $attachment_dir, $attachments, $username,
1234 $data_dir, $compose_messages;
1236 /* get out of here if no file was attached at all */
1237 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1241 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1242 $localfilename = GenerateRandomString(32, '', 7);
1243 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1244 while (file_exists($full_localfilename)) {
1245 $localfilename = GenerateRandomString(32, '', 7);
1246 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1249 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1250 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1251 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1252 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1256 $message = $compose_messages[$session];
1257 $type = strtolower($_FILES['attachfile']['type']);
1258 $name = $_FILES['attachfile']['name'];
1259 $message->initAttachment($type, $name, $full_localfilename);
1260 $compose_messages[$session] = $message;
1261 sqsession_register($compose_messages , 'compose_messages');
1264 function ClearAttachments($composeMessage) {
1265 if ($composeMessage->att_local_name
) {
1266 $attached_file = $composeMessage->att_local_name
;
1267 if (file_exists($attached_file)) {
1268 unlink($attached_file);
1271 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1272 ClearAttachments($composeMessage->entities
[$i]);
1276 /* parse values like 8M and 2k into bytes */
1277 function getByteSize($ini_size) {
1283 $ini_size = trim($ini_size);
1285 // if there's some kind of letter at the end of the string we need to multiply.
1286 if(!is_numeric(substr($ini_size, -1))) {
1288 switch(strtoupper(substr($ini_size, -1))) {
1290 $bytesize = 1073741824;
1293 $bytesize = 1048576;
1300 return ($bytesize * (int)substr($ini_size, 0, -1));
1307 /* temporary function to make use of the deliver class.
1308 In the future the responsable backend should be automaticly loaded
1309 and conf.pl should show a list of available backends.
1310 The message also should be constructed by the message class.
1313 function deliverMessage($composeMessage, $draft=false) {
1314 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1315 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1316 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1317 $domain, $action, $default_move_to_sent, $move_to_sent;
1318 global $imapServerAddress, $imapPort, $sent_folder, $key;
1320 /* some browsers replace <space> by nonbreaking spaces
1321 by replacing them back to spaces addressparsing works */
1322 /* FIXME: How to handle in case of other charsets where "\240"
1323 is not a non breaking space ??? */
1325 $send_to = str_replace("\240",' ',$send_to);
1326 $send_to_cc = str_replace("\240",' ',$send_to_cc);
1327 $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1329 $rfc822_header = $composeMessage->rfc822_header
;
1331 $abook = addressbook_init(false, true);
1332 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1333 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1334 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1335 $rfc822_header->priority
= $mailprio;
1336 $rfc822_header->subject
= $subject;
1337 $special_encoding='';
1338 if (strtolower($default_charset) == 'iso-2022-jp') {
1339 if (mb_detect_encoding($body) == 'ASCII') {
1340 $special_encoding = '8bit';
1342 $body = mb_convert_encoding($body, 'JIS');
1343 $special_encoding = '7bit';
1346 $composeMessage->setBody($body);
1348 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1349 $popuser = $usernamedata[1];
1350 $domain = $usernamedata[2];
1351 unset($usernamedata);
1353 $popuser = $username;
1356 $from_mail = $idents[$identity]['email_address'];
1357 $full_name = $idents[$identity]['full_name'];
1358 $reply_to = $idents[$identity]['reply_to'];
1360 $from_mail = "$popuser@$domain";
1362 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1364 $from = $rfc822_header->from
[0];
1365 if (!$from->host
) $from->host
= $domain;
1366 $full_name_encoded = encodeHeader($full_name);
1367 if ($full_name_encoded != $full_name) {
1368 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1370 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1372 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1375 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1377 /* Receipt: On Read */
1378 if (isset($request_mdn) && $request_mdn) {
1379 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1381 /* Receipt: On Delivery */
1382 if (isset($request_dr) && $request_dr) {
1383 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1385 /* multipart messages */
1386 if (count($composeMessage->entities
)) {
1387 $message_body = new Message();
1388 $message_body->body_part
= $composeMessage->body_part
;
1389 $composeMessage->body_part
= '';
1390 $mime_header = new MessageHeader
;
1391 $mime_header->type0
= 'text';
1392 $mime_header->type1
= 'plain';
1393 if ($special_encoding) {
1394 $mime_header->encoding
= $special_encoding;
1396 $mime_header->encoding
= '8bit';
1398 if ($default_charset) {
1399 $mime_header->parameters
['charset'] = $default_charset;
1401 $message_body->mime_header
= $mime_header;
1402 array_unshift($composeMessage->entities
, $message_body);
1403 $content_type = new ContentType('multipart/mixed');
1405 $content_type = new ContentType('text/plain');
1406 if ($special_encoding) {
1407 $rfc822_header->encoding
= $special_encoding;
1409 $rfc822_header->encoding
= '8bit';
1411 if ($default_charset) {
1412 $content_type->properties
['charset']=$default_charset;
1416 $rfc822_header->content_type
= $content_type;
1417 $composeMessage->rfc822_header
= $rfc822_header;
1419 /* Here you can modify the message structure just before we hand
1420 it over to deliver */
1421 $hookReturn = do_hook('compose_send', $composeMessage);
1422 /* Get any changes made by plugins to $composeMessage. */
1423 if ( is_object($hookReturn[1]) ) {
1424 $composeMessage = $hookReturn[1];
1427 if (!$useSendmail && !$draft) {
1428 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1429 $deliver = new Deliver_SMTP();
1430 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1432 if ($smtp_auth_mech == 'none') {
1436 global $key, $onetimepad;
1438 $pass = OneTimePadDecrypt($key, $onetimepad);
1441 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1442 $stream = $deliver->initStream($composeMessage,$domain,0,
1443 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1444 } elseif (!$draft) {
1445 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1446 global $sendmail_path;
1447 $deliver = new Deliver_SendMail();
1448 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1450 global $draft_folder;
1451 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1452 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1454 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1455 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1456 $imap_deliver = new Deliver_IMAP();
1457 $length = $imap_deliver->mail($composeMessage);
1458 sqimap_append ($imap_stream, $draft_folder, $length);
1459 $imap_deliver->mail($composeMessage, $imap_stream);
1460 sqimap_append_done ($imap_stream, $draft_folder);
1461 sqimap_logout($imap_stream);
1462 unset ($imap_deliver);
1465 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1466 plain_error_message($msg, $color);
1472 $length = $deliver->mail($composeMessage, $stream);
1473 $succes = $deliver->finalizeStream($stream);
1476 $msg = $deliver->dlv_msg
. '<br>' .
1477 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1478 $deliver->dlv_server_msg
;
1479 plain_error_message($msg, $color);
1482 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1483 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1485 /* Move to sent code */
1486 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1487 $svr_allow_sent = true;
1489 $svr_allow_sent = false;
1492 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1493 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1499 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1500 $lcl_allow_sent = true;
1502 $lcl_allow_sent = false;
1505 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1506 sqimap_append ($imap_stream, $sent_folder, $length);
1507 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1508 $imap_deliver = new Deliver_IMAP();
1509 $imap_deliver->mail($composeMessage, $imap_stream);
1510 sqimap_append_done ($imap_stream, $sent_folder);
1511 unset ($imap_deliver);
1513 global $passed_id, $mailbox, $action;
1514 ClearAttachments($composeMessage);
1515 if ($action == 'reply' ||
$action == 'reply_all') {
1516 sqimap_mailbox_select ($imap_stream, $mailbox);
1517 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1519 sqimap_logout($imap_stream);