d9308aac31076d993000b7dcef7ef19a6f795448
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');
34 /* --------------------- Get globals ------------------------------------- */
36 sqgetGlobalVar('key', $key, SQ_COOKIE
);
39 sqgetGlobalVar('username', $username, SQ_SESSION
);
40 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
41 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
42 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
44 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
45 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
47 /** SESSION/POST/GET VARS */
48 sqgetGlobalVar('action',$action);
49 sqgetGlobalVar('session',$session);
50 sqgetGlobalVar('mailbox',$mailbox);
51 sqgetGlobalVar('identity',$identity);
52 sqgetGlobalVar('send_to',$send_to);
53 sqgetGlobalVar('send_to_cc',$send_to_cc);
54 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
55 sqgetGlobalVar('subject',$subject);
56 sqgetGlobalVar('body',$body);
57 sqgetGlobalVar('mailprio',$mailprio);
58 sqgetGlobalVar('request_mdn',$request_mdn);
59 sqgetGlobalVar('request_dr',$request_dr);
60 sqgetGlobalVar('html_addr_search',$html_addr_search);
61 sqgetGlobalVar('mail_sent',$mail_sent);
62 sqgetGlobalVar('passed_id',$passed_id);
63 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
64 sqgetGlobalVar('send',$send);
66 sqgetGlobalVar('attach',$attach);
68 sqgetGlobalVar('draft',$draft);
69 sqgetGlobalVar('draft_id',$draft_id);
70 sqgetGlobalVar('ent_num',$ent_num);
71 sqgetGlobalVar('saved_draft',$saved_draft);
72 sqgetGlobalVar('delete_draft',$delete_draft);
76 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
77 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
78 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
79 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
80 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
81 sqgetGlobalVar('delete', $delete, SQ_POST
);
82 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
83 $html_addr_search_done = 'Use Addresses';
87 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
89 /* --------------------- Specific Functions ------------------------------ */
91 function replyAllString($header) {
92 global $include_self_reply_all, $username, $data_dir;
95 * 1) Remove the addresses we'll be sending the message 'to'
97 $url_replytoall_avoid_addrs = '';
98 if (isset($header->replyto
)) {
99 $excl_ar = $header->getAddr_a('replyto');
102 * 2) Remove our identities from the CC list (they still can be in the
103 * TO list) only if $include_self_reply_all is turned off
105 if (!$include_self_reply_all) {
106 $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address')));
107 $excl_ar[$email_address] = '';
108 $idents = getPref($data_dir, $username, 'identities');
109 if ($idents != '' && $idents > 1) {
111 for ($i = 1; $i < $idents; $i ++
) {
112 $cur_email_address = getPref($data_dir, $username,
113 'email_address' . $i);
114 $cur_email_address = strtolower(trim($cur_email_address));
115 $excl_ar[$cur_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 $url_replytoallcc .= ", \"$personal\" <$email>";
133 $url_replytoallcc .= ', '. $email;
136 $url_replytoallcc = substr($url_replytoallcc,2);
137 return $url_replytoallcc;
140 function getReplyCitation($orig_from) {
141 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
142 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
143 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
144 /* First, return an empty string when no citation style selected. */
145 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
149 /* Make sure our final value isn't an empty string. */
150 if ($orig_from == '') {
154 /* Otherwise, try to select the desired citation style. */
155 switch ($reply_citation_style) {
158 $end = ' ' . _("said") . ':';
161 $start = '<' . _("quote") . ' ' . _("who") . '="';
165 $start = $reply_citation_start .
166 ($reply_citation_start == '' ?
'' : ' ');
167 $end = $reply_citation_end;
173 /* Build and return the citation string. */
174 return ($start . $orig_from . $end . "\n");
177 function getforwardHeader($orig_header) {
180 $display = array( _("Subject") => strlen(_("Subject")),
181 _("From") => strlen(_("From")),
182 _("Date") => strlen(_("Date")),
183 _("To") => strlen(_("To")),
184 _("Cc") => strlen(_("Cc")) );
185 $maxsize = max($display);
186 $indent = str_pad('',$maxsize+
2);
187 foreach($display as $key => $val) {
188 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
190 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
191 $from = str_replace(' ',' ',$from);
192 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
193 $to = str_replace(' ',' ',$to);
194 $subject = decodeHeader($orig_header->subject
,false,false);
195 $subject = str_replace(' ',' ',$subject);
196 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
197 "\n\n". $display[_("Subject")] . $subject . "\n" .
198 $display[_("From")] . $from . "\n" .
199 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
200 $display[_("To")] . $to . "\n";
201 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
202 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
203 $cc = str_replace(' ',' ',$cc);
204 $bodyTop .= $display[_("Cc")] .$cc . "\n";
206 $bodyTop .= str_pad('', $editor_size -2 , '-') .
210 /* ----------------------------------------------------------------------- */
213 * If the session is expired during a post this restores the compose session
216 if (sqsession_is_registered('session_expired_post')) {
217 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
219 * extra check for username so we don't display previous post data from
220 * another user during this session.
222 if ($session_expired_post['username'] != $username) {
223 unset($session_expired_post);
224 sqsession_unregister('session_expired_post');
225 session_write_close();
227 foreach ($session_expired_post as $postvar => $val) {
234 $compose_messages = unserialize(urldecode($restoremessages));
235 sqsession_register($compose_messages,'compose_messages');
236 sqsession_register($composesession,'composesession');
240 $session_expired = true;
242 unset($session_expired_post);
243 sqsession_unregister('session_expired_post');
244 session_write_close();
245 if (!isset($mailbox)) {
248 if ($compose_new_win == '1') {
249 compose_Header($color, $mailbox);
251 displayPageHeader($color, $mailbox);
253 showInputForm($session, false);
256 if (!isset($composesession)) {
258 sqsession_register(0,'composesession');
261 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
262 sqsession_unregister('composesession');
263 $session = "$composesession" +
1;
264 $composesession = $session;
265 sqsession_register($composesession,'composesession');
267 if (!isset($compose_messages)) {
268 $compose_messages = array();
270 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
271 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
272 $composeMessage = new Message();
273 $rfc822_header = new Rfc822Header();
274 $composeMessage->rfc822_header
= $rfc822_header;
275 $composeMessage->reply_rfc822_header
= '';
276 $compose_messages[$session] = $composeMessage;
277 sqsession_register($compose_messages,'compose_messages');
279 $composeMessage=$compose_messages[$session];
282 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
288 * Set $default_charset to correspond with the user's selection
289 * of language interface.
292 $composeMessage=$compose_messages[$session];
293 if (! deliverMessage($composeMessage, true)) {
294 showInputForm($session);
297 unset($compose_messages[$session]);
298 $draft_message = _("Draft Email Saved");
299 /* If this is a resumed draft, then delete the original */
300 if(isset($delete_draft)) {
301 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
302 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
306 if ($compose_new_win == '1') {
307 Header("Location: compose.php?saved_draft=yes&session=$composesession");
311 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
312 "&startMessage=1¬e=".urlencode($draft_message));
320 if (isset($_FILES['attachfile']) &&
321 $_FILES['attachfile']['tmp_name'] &&
322 $_FILES['attachfile']['tmp_name'] != 'none') {
323 $AttachFailure = saveAttachedFiles($session);
325 if (checkInput(false) && !isset($AttachFailure)) {
326 if ($mailbox == "All Folders") {
327 /* We entered compose via the search results page */
328 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
330 $urlMailbox = urlencode (trim($mailbox));
331 if (! isset($passed_id)) {
335 * Set $default_charset to correspond with the user's selection
336 * of language interface.
340 * This is to change all newlines to \n
341 * We'll change them to \r\n later (in the sendMessage function)
343 $body = str_replace("\r\n", "\n", $body);
344 $body = str_replace("\r", "\n", $body);
347 * Rewrap $body so that no line is bigger than $editor_size
348 * This should only really kick in the sqWordWrap function
349 * if the browser doesn't support "VIRTUAL" as the wrap type.
351 $body = explode("\n", $body);
353 foreach ($body as $line) {
354 if( $line <> '-- ' ) {
355 $line = rtrim($line);
357 if (strlen($line) <= $editor_size +
1) {
358 $newBody .= $line . "\n";
360 sqWordWrap($line, $editor_size);
361 $newBody .= $line . "\n";
365 do_hook('compose_send');
366 $composeMessage=$compose_messages[$session];
368 $Result = deliverMessage($composeMessage);
370 showInputForm($session);
373 unset($compose_messages[$session]);
374 if ( isset($delete_draft)) {
375 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
376 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
379 if ($compose_new_win == '1') {
381 Header("Location: compose.php?mail_sent=yes");
384 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
388 if ($compose_new_win == '1') {
389 compose_Header($color, $mailbox);
392 displayPageHeader($color, $mailbox);
394 if (isset($AttachFailure)) {
395 plain_error_message(_("Could not move/copy file. File not attached"),
399 showInputForm($session);
400 /* sqimap_logout($imapConnection); */
402 } elseif (isset($html_addr_search_done)) {
403 if ($compose_new_win == '1') {
404 compose_Header($color, $mailbox);
407 displayPageHeader($color, $mailbox);
410 if (isset($send_to_search) && is_array($send_to_search)) {
411 foreach ($send_to_search as $k => $v) {
412 if (substr($k, 0, 1) == 'T') {
418 elseif (substr($k, 0, 1) == 'C') {
424 elseif (substr($k, 0, 1) == 'B') {
426 $send_to_bcc .= ', ';
432 showInputForm($session);
433 } elseif (isset($html_addr_search)) {
434 if (isset($_FILES['attachfile']) &&
435 $_FILES['attachfile']['tmp_name'] &&
436 $_FILES['attachfile']['tmp_name'] != 'none') {
437 if(saveAttachedFiles($session)) {
438 plain_error_message(_("Could not move/copy file. File not attached"), $color);
442 * I am using an include so as to elminiate an extra unnecessary
443 * click. If you can think of a better way, please implement it.
445 include_once('./addrbook_search_html.php');
446 } elseif (isset($attach)) {
447 if (saveAttachedFiles($session)) {
448 plain_error_message(_("Could not move/copy file. File not attached"), $color);
450 if ($compose_new_win == '1') {
451 compose_Header($color, $mailbox);
454 displayPageHeader($color, $mailbox);
456 showInputForm($session);
458 elseif (isset($sigappend)) {
459 $idents = getPref($data_dir, $username, 'identities', 0);
461 if ($identity == 'default') {
466 $signature = getSig($data_dir, $username, $no);
468 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
469 if ($compose_new_win == '1') {
470 compose_Header($color, $mailbox);
472 displayPageHeader($color, $mailbox);
474 showInputForm($session);
475 } elseif (isset($do_delete)) {
476 if ($compose_new_win == '1') {
477 compose_Header($color, $mailbox);
480 displayPageHeader($color, $mailbox);
483 if (isset($delete) && is_array($delete)) {
484 $composeMessage = $compose_messages[$session];
485 foreach($delete as $index) {
486 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
487 unlink ($attached_file);
488 unset ($composeMessage->entities
[$index]);
490 $new_entities = array();
491 foreach ($composeMessage->entities
as $entity) {
492 $new_entities[] = $entity;
494 $composeMessage->entities
= $new_entities;
495 $compose_messages[$session] = $composeMessage;
496 sqsession_register($compose_messages, 'compose_messages');
498 showInputForm($session);
501 * This handles the default case as well as the error case
502 * (they had the same code) --> if (isset($smtpErrors))
505 if ($compose_new_win == '1') {
506 compose_Header($color, $mailbox);
508 displayPageHeader($color, $mailbox);
513 if (!isset($passed_ent_id)) {
516 if (!isset($passed_id)) {
519 if (!isset($mailbox)) {
522 if (!isset($action)) {
526 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
528 /* in case the origin is not read_body.php */
529 if (isset($send_to)) {
530 $values['send_to'] = $send_to;
532 if (isset($send_to_cc)) {
533 $values['send_to_cc'] = $send_to_cc;
535 if (isset($send_to_bcc)) {
536 $values['send_to_bcc'] = $send_to_bcc;
538 showInputForm($session, $values);
543 /**************** Only function definitions go below *************/
546 /* This function is used when not sending or adding attachments */
547 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
548 global $editor_size, $default_use_priority, $body,
549 $use_signature, $composesession, $data_dir, $username,
550 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
553 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
557 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
560 sqimap_mailbox_select($imapConnection, $mailbox);
561 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
564 if ($passed_ent_id) {
565 /* redefine the messsage in case of message/rfc822 */
566 $message = $message->getEntity($passed_ent_id);
567 /* message is an entity which contains the envelope and type0=message
568 * and type1=rfc822. The actual entities are childs from
569 * $message->entities[0]. That's where the encoding and is located
572 $entities = $message->entities
[0]->findDisplayEntity
573 (array(), $alt_order = array('text/plain'));
574 if (!count($entities)) {
575 $entities = $message->entities
[0]->findDisplayEntity
576 (array(), $alt_order = array('text/plain','html/plain'));
578 $orig_header = $message->rfc822_header
; /* here is the envelope located */
579 /* redefine the message for picking up the attachments */
580 $message = $message->entities
[0];
583 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
584 if (!count($entities)) {
585 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
587 $orig_header = $message->rfc822_header
;
590 $encoding = $message->header
->encoding
;
591 $type0 = $message->type0
;
592 $type1 = $message->type1
;
593 foreach ($entities as $ent) {
594 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
595 $body_part_entity = $message->getEntity($ent);
596 $bodypart = decodeBody($unencoded_bodypart,
597 $body_part_entity->header
->encoding
);
598 if ($type1 == 'html') {
599 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
600 $bodypart = strip_tags($bodypart);
604 if ($default_use_priority) {
605 $mailprio = substr($orig_header->priority
,0,1);
612 //ClearAttachments($session);
615 $idents = getPref($data_dir, $username, 'identities');
616 $from_o = $orig_header->from
;
617 if (is_object($from_o)) {
618 $orig_from = $from_o->getAddress();
622 $identities = array();
623 if (!empty($idents) && $idents > 1) {
624 $identities[] = '"'. getPref($data_dir, $username, 'full_name')
625 . '" <' . getPref($data_dir, $username, 'email_address') . '>';
626 for ($i = 1; $i < $idents; $i++
) {
627 $enc_from_name = '"'.
628 getPref($data_dir, $username, 'full_name' . $i) .
630 getPref($data_dir, $username, 'email_address' . $i) . '>';
631 if ($enc_from_name == $orig_from && $i) {
635 $identities[] = $enc_from_name;
637 $identity_match = $orig_header->findAddress($identities);
638 if ($identity_match) {
639 $identity = $identity_match;
645 $use_signature = FALSE;
646 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
647 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
648 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
649 $subject = decodeHeader($orig_header->subject
,false,true);
650 $body_ary = explode("\n", $body);
651 $cnt = count($body_ary) ;
653 for ($i=0; $i < $cnt; $i++
) {
654 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
655 sqWordWrap($body_ary[$i], $editor_size );
656 $body .= $body_ary[$i] . "\n";
658 unset($body_ary[$i]);
661 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
663 case ('edit_as_new'):
664 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
665 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
666 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
667 $subject = decodeHeader($orig_header->subject
,false,true);
668 $mailprio = $orig_header->priority
;
670 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
675 $subject = decodeHeader($orig_header->subject
,false,true);
676 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
677 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
678 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
679 $subject = '[Fwd: ' . $subject . ']';
681 $body = getforwardHeader($orig_header) . $body;
683 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
684 $body = "\n" . $body;
686 case ('forward_as_attachment'):
687 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
691 $send_to_cc = replyAllString($orig_header);
692 $send_to_cc = decodeHeader($send_to_cc,false,true);
694 $send_to = $orig_header->reply_to
;
695 if (is_array($send_to) && count($send_to)) {
696 $send_to = $orig_header->getAddr_s('reply_to');
697 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
698 $send_to = $orig_header->getAddr_s('reply_to');
700 $send_to = $orig_header->getAddr_s('from');
702 $send_to = decodeHeader($send_to,false,true);
703 $subject = decodeHeader($orig_header->subject
,false,true);
704 $subject = str_replace('"', "'", $subject);
705 $subject = trim($subject);
706 if (substr(strtolower($subject), 0, 3) != 're:') {
707 $subject = 'Re: ' . $subject;
709 /* this corrects some wrapping/quoting problems on replies */
710 $rewrap_body = explode("\n", $body);
711 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
714 $cnt = count($rewrap_body);
715 for ($i=0;$i<$cnt;$i++
) {
716 sqWordWrap($rewrap_body[$i], ($editor_size));
717 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
719 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
721 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
723 unset($rewrap_body[$i]);
725 $body = getReplyCitation($from) . $body;
726 $composeMessage->reply_rfc822_header
= $orig_header;
732 $compose_messages[$session] = $composeMessage;
733 sqsession_register($compose_messages, 'compose_messages');
734 session_write_close();
735 sqimap_logout($imapConnection);
737 $ret = array( 'send_to' => $send_to,
738 'send_to_cc' => $send_to_cc,
739 'send_to_bcc' => $send_to_bcc,
740 'subject' => $subject,
741 'mailprio' => $mailprio,
743 'identity' => $identity );
746 } /* function newMail() */
748 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
749 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
750 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
751 if (!count($message->entities
) ||
752 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
753 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
754 switch ($message->type0
) {
756 if ($message->type1
== 'rfc822') {
757 $filename = $message->rfc822_header
->subject
.'.eml';
758 if ($filename == "") {
759 $filename = "untitled-".$message->entity_id
.'.eml';
762 $filename = $message->getFilename();
766 $filename = $message->getFilename();
769 $filename = decodeHeader($filename);
770 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
771 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
772 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
774 $localfilename = GenerateRandomString(32, '', 7);
775 $full_localfilename = "$hashed_attachment_dir/$localfilename";
776 while (file_exists($full_localfilename)) {
777 $localfilename = GenerateRandomString(32, '', 7);
778 $full_localfilename = "$hashed_attachment_dir/$localfilename";
780 $message->att_local_name
= $full_localfilename;
781 if (!$message->mime_header
) { /* temporary hack */
782 $message->mime_header
= $message->header
;
785 $composeMessage->addEntity($message);
787 /* Write Attachment to file */
788 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
789 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
790 $passed_id, $message->entity_id
),
791 $message->header
->encoding
));
795 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
796 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
799 return $composeMessage;
802 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
803 $passed_ent_id='', $imapConnection) {
804 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
805 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
806 if (!$passed_ent_id) {
807 $body_a = sqimap_run_command($imapConnection,
808 'FETCH '.$passed_id.' RFC822',
809 TRUE, $response, $readmessage,
812 $body_a = sqimap_run_command($imapConnection,
813 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
814 TRUE, $response, $readmessage, $uid_support);
815 $message = $message->parent
;
817 if ($response = 'OK') {
818 $subject = encodeHeader($message->rfc822_header
->subject
);
819 array_shift($body_a);
820 $body = implode('', $body_a) . "\r\n";
822 $localfilename = GenerateRandomString(32, 'FILE', 7);
823 $full_localfilename = "$hashed_attachment_dir/$localfilename";
825 $fp = fopen( $full_localfilename, 'w');
828 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
829 $full_localfilename);
831 return $composeMessage;
834 function showInputForm ($session, $values=false) {
835 global $send_to, $send_to_cc, $body,
836 $passed_body, $color, $use_signature, $signature, $prefix_sig,
837 $editor_size, $attachments, $subject, $newmail,
838 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
839 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
840 $username, $data_dir, $identity, $draft_id, $delete_draft,
841 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
842 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
843 $username, $compose_messages, $composesession, $default_charset;
845 $composeMessage = $compose_messages[$session];
848 $send_to = $values['send_to'];
849 $send_to_cc = $values['send_to_cc'];
850 $send_to_bcc = $values['send_to_bcc'];
851 $subject = $values['subject'];
852 $mailprio = $values['mailprio'];
853 $body = $values['body'];
854 $identity = (int) $values['identity'];
857 if ($use_javascript_addr_book) {
858 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
859 'function open_abook() { ' . "\n" .
860 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
861 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
862 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
863 ' nwin.opener = document.windows;' . "\n" .
865 '// --></SCRIPT>' . "\n\n";
868 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
869 'ENCTYPE="multipart/form-data"';
870 do_hook("compose_form");
874 if ($action == 'draft') {
875 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
877 if (isset($delete_draft)) {
878 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
880 if (isset($session)) {
881 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
884 if (isset($passed_id)) {
885 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
888 if ($saved_draft == 'yes') {
889 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
891 if ($mail_sent == 'yes') {
892 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
894 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
895 if ($compose_new_win == '1') {
896 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
897 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
899 if ($location_of_buttons == 'top') {
900 showComposeButtonRow();
903 $idents = getPref($data_dir, $username, 'identities', 0);
905 echo ' <TR>' . "\n" .
906 html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
907 _("From:") . '</TD>' . "\n" .
908 html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
909 ' <select name=identity>' . "\n" .
910 ' <option value=default>' .
911 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
912 $em = getPref($data_dir, $username, 'email_address');
914 echo htmlspecialchars(' <' . $em . '>') . "\n";
916 for ($i = 1; $i < $idents; $i ++
) {
917 echo '<option value="' . $i . '"';
918 if (isset($identity) && $identity == $i) {
921 echo '>' . htmlspecialchars(getPref($data_dir, $username,
923 $em = getPref($data_dir, $username, 'email_address' . $i);
925 echo htmlspecialchars(' <' . $em . '>') . "\n";
929 echo '</select>' . "\n" .
933 echo ' <TR>' . "\n" .
934 html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
935 _("To:") . '</TD>' . "\n" .
936 html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
937 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
938 $send_to . '" SIZE=60><BR>' . "\n" .
942 html_tag( 'td', '', 'right', $color[4] ) .
943 _("CC:") . '</TD>' . "\n" .
944 html_tag( 'td', '', 'left', $color[4] ) .
945 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
946 $send_to_cc . '"><BR>' . "\n" .
950 html_tag( 'td', '', 'right', $color[4] ) .
951 _("BCC:") . '</TD>' . "\n" .
952 html_tag( 'td', '', 'left', $color[4] ) .
953 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
954 $send_to_bcc . '" SIZE=60><BR>' . "\n" .
958 html_tag( 'td', '', 'right', $color[4] ) .
959 _("Subject:") . '</TD>' . "\n" .
960 html_tag( 'td', '', 'left', $color[4] ) . "\n";
961 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
962 $subject . '">' . "\n" .
966 if ($location_of_buttons == 'between') {
967 showComposeButtonRow();
970 if ($compose_new_win == '1') {
971 echo ' <TR>' . "\n" .
972 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
973 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
974 $editor_size . '" WRAP="VIRTUAL">';
977 echo ' <TR>' . "\n" .
978 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
979 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
980 $editor_size . '" WRAP="VIRTUAL">';
982 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
984 if ($identity == 'default') {
989 $signature = getSig($data_dir, $username, $no);
992 if ($sig_first == '1') {
993 if ($default_charset == 'iso-2022-jp') {
994 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
996 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false);
998 echo "\n\n".decodeHeader($body,false,true);
1001 echo "\n\n".decodeHeader($body,false,true);
1002 if ($default_charset == 'iso-2022-jp') {
1003 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1005 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,true);
1010 echo decodeHeader($body,false,true);
1012 echo '</TEXTAREA><BR>' . "\n" .
1017 if ($location_of_buttons == 'bottom') {
1018 showComposeButtonRow();
1020 echo ' <TR>' . "\n" .
1021 html_tag( 'td', '', 'right', '', 'COLSPAN=2' ) . "\n" .
1022 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . "\n" .
1023 ' <BR><BR>' . "\n" .
1028 /* This code is for attachments */
1029 if ((bool) ini_get('file_uploads')) {
1030 echo ' <TR>' . "\n" .
1031 ' <TD COLSPAN=2>' . "\n" .
1032 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1033 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1036 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1037 ' border="0">' . "\n" .
1039 html_tag( 'td', '', 'right', '', 'VALIGN=MIDDLE' ) .
1040 _("Attach:") . '</TD>' . "\n" .
1041 html_tag( 'td', '', 'left', '', 'VALIGN=MIDDLE' ) .
1042 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
1043 ' <input type="submit" name="attach"' .
1044 ' value="' . _("Add") .'">' . "\n" .
1050 if ($composeMessage->entities
) {
1051 foreach ($composeMessage->entities
as $key => $attachment) {
1052 $attached_file = $attachment->att_local_name
;
1053 if ($attachment->att_local_name ||
$attachment->body_part
) {
1054 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1055 $type = $attachment->mime_header
->type0
.'/'.
1056 $attachment->mime_header
->type1
;
1058 $s_a[] = '<table bgcolor="'.$color[0].
1059 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1060 $key . "\"></td><td>\n" . $attached_filename .
1061 '</td><td>-</td><td> ' . $type . '</td><td>('.
1062 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1067 foreach ($s_a as $s) {
1068 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1070 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1071 _("Delete selected attachments") . "\">\n" .
1074 echo ' </table>' . "\n" .
1077 ' </TABLE>' . "\n" .
1080 } // End of file_uploads if-block
1081 /* End of attachment code */
1082 if ($compose_new_win == '1') {
1083 echo '</TABLE>'."\n";
1086 echo '</TABLE>' . "\n" .
1087 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1088 '<input type=hidden name=action value="' . $action . "\">\n" .
1089 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1092 store the complete ComposeMessages array in a hidden input value
1093 so we can restore them in case of a session timeout.
1095 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1096 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1097 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1098 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1100 if (!(bool) ini_get('file_uploads')) {
1101 /* File uploads are off, so we didn't show that part of the form.
1102 To avoid bogus bug reports, tell the user why. */
1103 echo 'Because PHP file uploads are turned off, you can not attach files ';
1104 echo "to this message. Please see your system administrator for details.\r\n";
1107 do_hook('compose_bottom');
1108 echo '</BODY></HTML>' . "\n";
1112 function showComposeButtonRow() {
1113 global $use_javascript_addr_book, $save_as_draft,
1114 $default_use_priority, $mailprio, $default_use_mdn,
1115 $request_mdn, $request_dr,
1116 $data_dir, $username;
1118 echo ' <TR>' . "\n" .
1119 ' <TD></TD>' . "\n" .
1121 if ($default_use_priority) {
1122 if(!isset($mailprio)) {
1125 echo ' ' . _("Priority") .': <select name="mailprio">'.
1126 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1127 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1128 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1131 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1132 if ($default_use_mdn) {
1133 if ($mdn_user_support) {
1134 echo ' ' . _("Receipt") .': '.
1135 '<input type="checkbox" name="request_mdn" value=1'.
1136 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1137 ' <input type="checkbox" name="request_dr" value=1'.
1138 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1142 echo ' </TD>' . "\n" .
1145 ' <TD></TD>' . "\n" .
1147 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1148 if ($use_javascript_addr_book) {
1149 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1150 " <input type=button value=\\\""._("Addresses").
1151 "\\\" onclick='javascript:open_abook();'>\");".
1152 " // --></SCRIPT><NOSCRIPT>\n".
1153 " <input type=submit name=\"html_addr_search\" value=\"".
1154 _("Addresses")."\">".
1157 echo ' <input type=submit name="html_addr_search" value="'.
1158 _("Addresses").'">' . "\n";
1161 if ($save_as_draft) {
1162 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1165 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1166 do_hook('compose_button_row');
1168 echo ' </TD>' . "\n" .
1172 function checkInput ($show) {
1174 * I implemented the $show variable because the error messages
1175 * were getting sent before the page header. So, I check once
1176 * using $show=false, and then when i'm ready to display the error
1177 * message, show=true
1179 global $body, $send_to, $send_to_bcc, $subject, $color;
1181 if ($send_to == '' && $send_to_bcc == '') {
1183 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1188 } /* function checkInput() */
1191 /* True if FAILURE */
1192 function saveAttachedFiles($session) {
1193 global $_FILES, $attachment_dir, $attachments, $username,
1194 $data_dir, $compose_messages;
1196 /* get out of here if no file was attached at all */
1197 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1201 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1202 $localfilename = GenerateRandomString(32, '', 7);
1203 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1204 while (file_exists($full_localfilename)) {
1205 $localfilename = GenerateRandomString(32, '', 7);
1206 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1209 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1210 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1211 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1212 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1216 $message = $compose_messages[$session];
1217 $type = strtolower($_FILES['attachfile']['type']);
1218 $name = $_FILES['attachfile']['name'];
1219 $message->initAttachment($type, $name, $full_localfilename);
1220 $compose_messages[$session] = $message;
1223 function ClearAttachments($composeMessage) {
1224 if ($composeMessage->att_local_name
) {
1225 $attached_file = $composeMessage->att_local_name
;
1226 if (file_exists($attached_file)) {
1227 unlink($attached_file);
1230 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1231 ClearAttachments($composeMessage->entities
[$i]);
1238 /* temporary function to make use of the deliver class.
1239 In the future the responsable backend should be automaticly loaded
1240 and conf.pl should show a list of available backends.
1241 The message also should be constructed by the message class.
1244 function deliverMessage($composeMessage, $draft=false) {
1245 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1246 $username, $popuser, $usernamedata, $identity, $data_dir,
1247 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1249 global $imapServerAddress, $imapPort, $sent_folder, $key;
1251 $rfc822_header = $composeMessage->rfc822_header
;
1253 $abook = addressbook_init(false, true);
1254 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1255 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1256 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1257 $rfc822_header->priority
= $mailprio;
1258 $rfc822_header->subject
= $subject;
1259 $special_encoding='';
1260 if (strtolower($default_charset) == 'iso-2022-jp') {
1261 if (mb_detect_encoding($body) == 'ASCII') {
1262 $special_encoding = '8bit';
1264 $body = mb_convert_encoding($body, 'JIS');
1265 $special_encoding = '7bit';
1268 $composeMessage->setBody($body);
1270 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1271 $popuser = $usernamedata[1];
1272 $domain = $usernamedata[2];
1273 unset($usernamedata);
1275 $popuser = $username;
1278 if (isset($identity) && $identity != 'default') {
1279 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1280 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1281 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1283 $from_mail = getPref($data_dir, $username, 'email_address');
1284 $full_name = getPref($data_dir, $username, 'full_name');
1285 $reply_to = getPref($data_dir, $username,'reply_to');
1288 $from_mail = "$popuser@$domain";
1291 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1293 $from = $rfc822_header->from
[0];
1294 if (!$from->host
) $from->host
= $domain;
1295 $full_name_encoded = encodeHeader($full_name);
1296 if ($full_name_encoded != $full_name) {
1297 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1299 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1301 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1304 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1306 /* Receipt: On Read */
1307 if (isset($request_mdn) && $request_mdn) {
1308 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1310 /* Receipt: On Delivery */
1311 if (isset($request_dr) && $request_dr) {
1312 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1314 /* multipart messages */
1315 if (count($composeMessage->entities
)) {
1316 $message_body = new Message();
1317 $message_body->body_part
= $composeMessage->body_part
;
1318 $composeMessage->body_part
= '';
1319 $mime_header = new MessageHeader
;
1320 $mime_header->type0
= 'text';
1321 $mime_header->type1
= 'plain';
1322 if ($special_encoding) {
1323 $mime_header->encoding
= $special_encoding;
1325 $mime_header->encoding
= '8bit';
1327 if ($default_charset) {
1328 $mime_header->parameters
['charset'] = $default_charset;
1330 $message_body->mime_header
= $mime_header;
1331 array_unshift($composeMessage->entities
, $message_body);
1332 $content_type = new ContentType('multipart/mixed');
1334 $content_type = new ContentType('text/plain');
1336 if ($default_charset) {
1337 $content_type->properties
['charset']=$default_charset;
1340 $rfc822_header->content_type
= $content_type;
1341 $composeMessage->rfc822_header
= $rfc822_header;
1343 if (!$useSendmail && !$draft) {
1344 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1345 $deliver = new Deliver_SMTP();
1346 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1348 if ($smtp_auth_mech == 'none') {
1352 global $key, $onetimepad;
1354 $pass = OneTimePadDecrypt($key, $onetimepad);
1357 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1358 $stream = $deliver->initStream($composeMessage,$domain,0,
1359 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1360 } elseif (!$draft) {
1361 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1362 global $sendmail_path;
1363 $deliver = new Deliver_SendMail();
1364 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1366 global $draft_folder;
1367 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1368 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1370 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1371 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1372 $imap_deliver = new Deliver_IMAP();
1373 $length = $imap_deliver->mail($composeMessage);
1374 sqimap_append ($imap_stream, $draft_folder, $length);
1375 $imap_deliver->mail($composeMessage, $imap_stream);
1376 sqimap_append_done ($imap_stream, $draft_folder);
1377 sqimap_logout($imap_stream);
1378 unset ($imap_deliver);
1381 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1382 plain_error_message($msg, $color);
1388 $length = $deliver->mail($composeMessage, $stream);
1389 $succes = $deliver->finalizeStream($stream);
1392 $msg = $deliver->dlv_msg
. '<br>' .
1393 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1394 $deliver->dlv_server_msg
;
1395 plain_error_message($msg, $color);
1398 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1400 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1401 sqimap_append ($imap_stream, $sent_folder, $length);
1402 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1403 $imap_deliver = new Deliver_IMAP();
1404 $imap_deliver->mail($composeMessage, $imap_stream);
1405 sqimap_append_done ($imap_stream, $sent_folder);
1406 unset ($imap_deliver);
1408 global $passed_id, $mailbox, $action;
1409 ClearAttachments($composeMessage);
1410 if ($action == 'reply' ||
$action == 'reply_all') {
1411 sqimap_mailbox_select ($imap_stream, $mailbox);
1412 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1414 sqimap_logout($imap_stream);