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 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
83 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
84 $html_addr_search_done = 'Use Addresses';
88 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
90 /* --------------------- Specific Functions ------------------------------ */
92 function replyAllString($header) {
93 global $include_self_reply_all, $username, $data_dir;
96 * 1) Remove the addresses we'll be sending the message 'to'
98 $url_replytoall_avoid_addrs = '';
99 if (isset($header->replyto
)) {
100 $excl_ar = $header->getAddr_a('replyto');
103 * 2) Remove our identities from the CC list (they still can be in the
104 * TO list) only if $include_self_reply_all is turned off
106 if (!$include_self_reply_all) {
107 $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address')));
108 $excl_ar[$email_address] = '';
109 $idents = getPref($data_dir, $username, 'identities');
110 if ($idents != '' && $idents > 1) {
112 for ($i = 1; $i < $idents; $i ++
) {
113 $cur_email_address = getPref($data_dir, $username,
114 'email_address' . $i);
115 $cur_email_address = strtolower(trim($cur_email_address));
116 $excl_ar[$cur_email_address] = '';
122 * 3) get the addresses.
124 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
127 * 4) generate the string.
129 $url_replytoallcc = '';
130 foreach( $url_replytoall_ar as $email => $personal) {
132 $url_replytoallcc .= ", \"$personal\" <$email>";
134 $url_replytoallcc .= ', '. $email;
137 $url_replytoallcc = substr($url_replytoallcc,2);
138 return $url_replytoallcc;
141 function getReplyCitation($orig_from) {
142 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
143 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
144 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
145 /* First, return an empty string when no citation style selected. */
146 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
150 /* Make sure our final value isn't an empty string. */
151 if ($orig_from == '') {
155 /* Otherwise, try to select the desired citation style. */
156 switch ($reply_citation_style) {
159 $end = ' ' . _("said") . ':';
162 $start = '<' . _("quote") . ' ' . _("who") . '="';
166 $start = $reply_citation_start .
167 ($reply_citation_start == '' ?
'' : ' ');
168 $end = $reply_citation_end;
174 /* Build and return the citation string. */
175 return ($start . $orig_from . $end . "\n");
178 function getforwardHeader($orig_header) {
181 $display = array( _("Subject") => strlen(_("Subject")),
182 _("From") => strlen(_("From")),
183 _("Date") => strlen(_("Date")),
184 _("To") => strlen(_("To")),
185 _("Cc") => strlen(_("Cc")) );
186 $maxsize = max($display);
187 $indent = str_pad('',$maxsize+
2);
188 foreach($display as $key => $val) {
189 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
191 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
192 $from = str_replace(' ',' ',$from);
193 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
194 $to = str_replace(' ',' ',$to);
195 $subject = decodeHeader($orig_header->subject
,false,false);
196 $subject = str_replace(' ',' ',$subject);
197 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
198 "\n\n". $display[_("Subject")] . $subject . "\n" .
199 $display[_("From")] . $from . "\n" .
200 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
201 $display[_("To")] . $to . "\n";
202 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
203 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
204 $cc = str_replace(' ',' ',$cc);
205 $bodyTop .= $display[_("Cc")] .$cc . "\n";
207 $bodyTop .= str_pad('', $editor_size -2 , '-') .
211 /* ----------------------------------------------------------------------- */
214 * If the session is expired during a post this restores the compose session
217 if (sqsession_is_registered('session_expired_post')) {
218 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
220 * extra check for username so we don't display previous post data from
221 * another user during this session.
223 if ($session_expired_post['username'] != $username) {
224 unset($session_expired_post);
225 sqsession_unregister('session_expired_post');
226 session_write_close();
228 foreach ($session_expired_post as $postvar => $val) {
235 $compose_messages = unserialize(urldecode($restoremessages));
236 sqsession_register($compose_messages,'compose_messages');
237 sqsession_register($composesession,'composesession');
241 $session_expired = true;
243 unset($session_expired_post);
244 sqsession_unregister('session_expired_post');
245 session_write_close();
246 if (!isset($mailbox)) {
249 if ($compose_new_win == '1') {
250 compose_Header($color, $mailbox);
252 displayPageHeader($color, $mailbox);
254 showInputForm($session, false);
257 if (!isset($composesession)) {
259 sqsession_register(0,'composesession');
262 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
263 sqsession_unregister('composesession');
264 $session = "$composesession" +
1;
265 $composesession = $session;
266 sqsession_register($composesession,'composesession');
268 if (!isset($compose_messages)) {
269 $compose_messages = array();
271 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
272 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
273 $composeMessage = new Message();
274 $rfc822_header = new Rfc822Header();
275 $composeMessage->rfc822_header
= $rfc822_header;
276 $composeMessage->reply_rfc822_header
= '';
277 $compose_messages[$session] = $composeMessage;
278 sqsession_register($compose_messages,'compose_messages');
280 $composeMessage=$compose_messages[$session];
283 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
289 * Set $default_charset to correspond with the user's selection
290 * of language interface.
293 $composeMessage=$compose_messages[$session];
294 if (! deliverMessage($composeMessage, true)) {
295 showInputForm($session);
298 unset($compose_messages[$session]);
299 $draft_message = _("Draft Email Saved");
300 /* If this is a resumed draft, then delete the original */
301 if(isset($delete_draft)) {
302 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
303 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
307 if ($compose_new_win == '1') {
308 Header("Location: compose.php?saved_draft=yes&session=$composesession");
312 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
313 "&startMessage=1¬e=".urlencode($draft_message));
321 if (isset($_FILES['attachfile']) &&
322 $_FILES['attachfile']['tmp_name'] &&
323 $_FILES['attachfile']['tmp_name'] != 'none') {
324 $AttachFailure = saveAttachedFiles($session);
326 if (checkInput(false) && !isset($AttachFailure)) {
327 if ($mailbox == "All Folders") {
328 /* We entered compose via the search results page */
329 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
331 $urlMailbox = urlencode (trim($mailbox));
332 if (! isset($passed_id)) {
336 * Set $default_charset to correspond with the user's selection
337 * of language interface.
341 * This is to change all newlines to \n
342 * We'll change them to \r\n later (in the sendMessage function)
344 $body = str_replace("\r\n", "\n", $body);
345 $body = str_replace("\r", "\n", $body);
348 * Rewrap $body so that no line is bigger than $editor_size
349 * This should only really kick in the sqWordWrap function
350 * if the browser doesn't support "VIRTUAL" as the wrap type.
352 $body = explode("\n", $body);
354 foreach ($body as $line) {
355 if( $line <> '-- ' ) {
356 $line = rtrim($line);
358 if (strlen($line) <= $editor_size +
1) {
359 $newBody .= $line . "\n";
361 sqWordWrap($line, $editor_size);
362 $newBody .= $line . "\n";
366 do_hook('compose_send');
367 $composeMessage=$compose_messages[$session];
369 $Result = deliverMessage($composeMessage);
371 showInputForm($session);
374 unset($compose_messages[$session]);
375 if ( isset($delete_draft)) {
376 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
377 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
380 if ($compose_new_win == '1') {
382 Header("Location: compose.php?mail_sent=yes");
385 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
389 if ($compose_new_win == '1') {
390 compose_Header($color, $mailbox);
393 displayPageHeader($color, $mailbox);
395 if (isset($AttachFailure)) {
396 plain_error_message(_("Could not move/copy file. File not attached"),
400 showInputForm($session);
401 /* sqimap_logout($imapConnection); */
403 } elseif (isset($html_addr_search_done)) {
404 if ($compose_new_win == '1') {
405 compose_Header($color, $mailbox);
408 displayPageHeader($color, $mailbox);
411 if (isset($send_to_search) && is_array($send_to_search)) {
412 foreach ($send_to_search as $k => $v) {
413 if (substr($k, 0, 1) == 'T') {
419 elseif (substr($k, 0, 1) == 'C') {
425 elseif (substr($k, 0, 1) == 'B') {
427 $send_to_bcc .= ', ';
433 showInputForm($session);
434 } elseif (isset($html_addr_search)) {
435 if (isset($_FILES['attachfile']) &&
436 $_FILES['attachfile']['tmp_name'] &&
437 $_FILES['attachfile']['tmp_name'] != 'none') {
438 if(saveAttachedFiles($session)) {
439 plain_error_message(_("Could not move/copy file. File not attached"), $color);
443 * I am using an include so as to elminiate an extra unnecessary
444 * click. If you can think of a better way, please implement it.
446 include_once('./addrbook_search_html.php');
447 } elseif (isset($attach)) {
448 if (saveAttachedFiles($session)) {
449 plain_error_message(_("Could not move/copy file. File not attached"), $color);
451 if ($compose_new_win == '1') {
452 compose_Header($color, $mailbox);
455 displayPageHeader($color, $mailbox);
457 showInputForm($session);
459 elseif (isset($sigappend)) {
460 $idents = getPref($data_dir, $username, 'identities', 0);
462 if ($identity == 'default') {
467 $signature = getSig($data_dir, $username, $no);
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 showInputForm($session, $values);
544 /**************** Only function definitions go below *************/
547 /* This function is used when not sending or adding attachments */
548 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
549 global $editor_size, $default_use_priority, $body,
550 $use_signature, $composesession, $data_dir, $username,
551 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
554 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
558 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
561 sqimap_mailbox_select($imapConnection, $mailbox);
562 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
565 if ($passed_ent_id) {
566 /* redefine the messsage in case of message/rfc822 */
567 $message = $message->getEntity($passed_ent_id);
568 /* message is an entity which contains the envelope and type0=message
569 * and type1=rfc822. The actual entities are childs from
570 * $message->entities[0]. That's where the encoding and is located
573 $entities = $message->entities
[0]->findDisplayEntity
574 (array(), $alt_order = array('text/plain'));
575 if (!count($entities)) {
576 $entities = $message->entities
[0]->findDisplayEntity
577 (array(), $alt_order = array('text/plain','html/plain'));
579 $orig_header = $message->rfc822_header
; /* here is the envelope located */
580 /* redefine the message for picking up the attachments */
581 $message = $message->entities
[0];
584 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
585 if (!count($entities)) {
586 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
588 $orig_header = $message->rfc822_header
;
591 $encoding = $message->header
->encoding
;
592 $type0 = $message->type0
;
593 $type1 = $message->type1
;
594 foreach ($entities as $ent) {
595 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
596 $body_part_entity = $message->getEntity($ent);
597 $bodypart = decodeBody($unencoded_bodypart,
598 $body_part_entity->header
->encoding
);
599 if ($type1 == 'html') {
600 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
601 $bodypart = strip_tags($bodypart);
605 if ($default_use_priority) {
606 $mailprio = substr($orig_header->priority
,0,1);
613 //ClearAttachments($session);
616 $idents = getPref($data_dir, $username, 'identities');
617 $from_o = $orig_header->from
;
618 if (is_object($from_o)) {
619 $orig_from = $from_o->getAddress();
623 $identities = array();
624 if (!empty($idents) && $idents > 1) {
625 $identities[] = '"'. getPref($data_dir, $username, 'full_name')
626 . '" <' . getPref($data_dir, $username, 'email_address') . '>';
627 for ($i = 1; $i < $idents; $i++
) {
628 $enc_from_name = '"'.
629 getPref($data_dir, $username, 'full_name' . $i) .
631 getPref($data_dir, $username, 'email_address' . $i) . '>';
632 if ($enc_from_name == $orig_from && $i) {
636 $identities[] = $enc_from_name;
638 $identity_match = $orig_header->findAddress($identities);
639 if ($identity_match) {
640 $identity = $identity_match;
646 $use_signature = FALSE;
647 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
648 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
649 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
650 $subject = decodeHeader($orig_header->subject
,false,true);
651 $body_ary = explode("\n", $body);
652 $cnt = count($body_ary) ;
654 for ($i=0; $i < $cnt; $i++
) {
655 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
656 sqWordWrap($body_ary[$i], $editor_size );
657 $body .= $body_ary[$i] . "\n";
659 unset($body_ary[$i]);
662 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
664 case ('edit_as_new'):
665 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
666 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
667 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
668 $subject = decodeHeader($orig_header->subject
,false,true);
669 $mailprio = $orig_header->priority
;
671 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
676 $subject = decodeHeader($orig_header->subject
,false,true);
677 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
678 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
679 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
680 $subject = '[Fwd: ' . $subject . ']';
682 $body = getforwardHeader($orig_header) . $body;
684 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
685 $body = "\n" . $body;
687 case ('forward_as_attachment'):
688 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
692 $send_to_cc = replyAllString($orig_header);
693 $send_to_cc = decodeHeader($send_to_cc,false,true);
695 $send_to = $orig_header->reply_to
;
696 if (is_array($send_to) && count($send_to)) {
697 $send_to = $orig_header->getAddr_s('reply_to');
698 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
699 $send_to = $orig_header->getAddr_s('reply_to');
701 $send_to = $orig_header->getAddr_s('from');
703 $send_to = decodeHeader($send_to,false,true);
704 $subject = decodeHeader($orig_header->subject
,false,true);
705 $subject = str_replace('"', "'", $subject);
706 $subject = trim($subject);
707 if (substr(strtolower($subject), 0, 3) != 're:') {
708 $subject = 'Re: ' . $subject;
710 /* this corrects some wrapping/quoting problems on replies */
711 $rewrap_body = explode("\n", $body);
712 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
715 $cnt = count($rewrap_body);
716 for ($i=0;$i<$cnt;$i++
) {
717 sqWordWrap($rewrap_body[$i], ($editor_size));
718 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
720 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
722 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
724 unset($rewrap_body[$i]);
726 $body = getReplyCitation($from) . $body;
727 $composeMessage->reply_rfc822_header
= $orig_header;
733 $compose_messages[$session] = $composeMessage;
734 sqsession_register($compose_messages, 'compose_messages');
735 session_write_close();
736 sqimap_logout($imapConnection);
738 $ret = array( 'send_to' => $send_to,
739 'send_to_cc' => $send_to_cc,
740 'send_to_bcc' => $send_to_bcc,
741 'subject' => $subject,
742 'mailprio' => $mailprio,
744 'identity' => $identity );
747 } /* function newMail() */
749 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
750 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
751 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
752 if (!count($message->entities
) ||
753 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
754 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
755 switch ($message->type0
) {
757 if ($message->type1
== 'rfc822') {
758 $filename = $message->rfc822_header
->subject
.'.eml';
759 if ($filename == "") {
760 $filename = "untitled-".$message->entity_id
.'.eml';
763 $filename = $message->getFilename();
767 $filename = $message->getFilename();
770 $filename = decodeHeader($filename);
771 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
772 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
773 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
775 $localfilename = GenerateRandomString(32, '', 7);
776 $full_localfilename = "$hashed_attachment_dir/$localfilename";
777 while (file_exists($full_localfilename)) {
778 $localfilename = GenerateRandomString(32, '', 7);
779 $full_localfilename = "$hashed_attachment_dir/$localfilename";
781 $message->att_local_name
= $full_localfilename;
782 if (!$message->mime_header
) { /* temporary hack */
783 $message->mime_header
= $message->header
;
786 $composeMessage->addEntity($message);
788 /* Write Attachment to file */
789 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
790 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
791 $passed_id, $message->entity_id
),
792 $message->header
->encoding
));
796 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
797 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
800 return $composeMessage;
803 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
804 $passed_ent_id='', $imapConnection) {
805 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
806 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
807 if (!$passed_ent_id) {
808 $body_a = sqimap_run_command($imapConnection,
809 'FETCH '.$passed_id.' RFC822',
810 TRUE, $response, $readmessage,
813 $body_a = sqimap_run_command($imapConnection,
814 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
815 TRUE, $response, $readmessage, $uid_support);
816 $message = $message->parent
;
818 if ($response = 'OK') {
819 $subject = encodeHeader($message->rfc822_header
->subject
);
820 array_shift($body_a);
821 $body = implode('', $body_a) . "\r\n";
823 $localfilename = GenerateRandomString(32, 'FILE', 7);
824 $full_localfilename = "$hashed_attachment_dir/$localfilename";
826 $fp = fopen( $full_localfilename, 'w');
829 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
830 $full_localfilename);
832 return $composeMessage;
835 function showInputForm ($session, $values=false) {
836 global $send_to, $send_to_cc, $body,
837 $passed_body, $color, $use_signature, $signature, $prefix_sig,
838 $editor_size, $attachments, $subject, $newmail,
839 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
840 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
841 $username, $data_dir, $identity, $draft_id, $delete_draft,
842 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
843 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
844 $username, $compose_messages, $composesession, $default_charset;
846 $composeMessage = $compose_messages[$session];
849 $send_to = $values['send_to'];
850 $send_to_cc = $values['send_to_cc'];
851 $send_to_bcc = $values['send_to_bcc'];
852 $subject = $values['subject'];
853 $mailprio = $values['mailprio'];
854 $body = $values['body'];
855 $identity = (int) $values['identity'];
857 $send_to = decodeHeader($send_to);
858 $send_to_cc = decodeHeader($send_to_cc);
859 $send_to_bcc = decodeHeader($send_to_bcc);
862 if ($use_javascript_addr_book) {
863 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
864 'function open_abook() { ' . "\n" .
865 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
866 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
867 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
868 ' nwin.opener = document.windows;' . "\n" .
870 '// --></SCRIPT>' . "\n\n";
873 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
874 'ENCTYPE="multipart/form-data"';
875 do_hook("compose_form");
879 if ($action == 'draft') {
880 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
882 if (isset($delete_draft)) {
883 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
885 if (isset($session)) {
886 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
889 if (isset($passed_id)) {
890 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
893 if ($saved_draft == 'yes') {
894 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
896 if ($mail_sent == 'yes') {
897 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
899 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
900 if ($compose_new_win == '1') {
901 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
902 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
904 if ($location_of_buttons == 'top') {
905 showComposeButtonRow();
908 $idents = getPref($data_dir, $username, 'identities', 0);
910 echo ' <TR>' . "\n" .
911 html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
912 _("From:") . '</TD>' . "\n" .
913 html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
914 ' <select name=identity>' . "\n" .
915 ' <option value=default>' .
916 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
917 $em = getPref($data_dir, $username, 'email_address');
919 echo htmlspecialchars(' <' . $em . '>') . "\n";
921 for ($i = 1; $i < $idents; $i ++
) {
922 echo '<option value="' . $i . '"';
923 if (isset($identity) && $identity == $i) {
926 echo '>' . htmlspecialchars(getPref($data_dir, $username,
928 $em = getPref($data_dir, $username, 'email_address' . $i);
930 echo htmlspecialchars(' <' . $em . '>') . "\n";
934 echo '</select>' . "\n" .
938 echo ' <TR>' . "\n" .
939 html_tag( 'td', '', 'right', $color[4], 'WIDTH="10%"' ) .
940 _("To:") . '</TD>' . "\n" .
941 html_tag( 'td', '', 'left', $color[4], 'WIDTH="90%"' ) .
942 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
943 $send_to . '" SIZE=60><BR>' . "\n" .
947 html_tag( 'td', '', 'right', $color[4] ) .
948 _("CC:") . '</TD>' . "\n" .
949 html_tag( 'td', '', 'left', $color[4] ) .
950 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
951 $send_to_cc . '"><BR>' . "\n" .
955 html_tag( 'td', '', 'right', $color[4] ) .
956 _("BCC:") . '</TD>' . "\n" .
957 html_tag( 'td', '', 'left', $color[4] ) .
958 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
959 $send_to_bcc . '" SIZE=60><BR>' . "\n" .
963 html_tag( 'td', '', 'right', $color[4] ) .
964 _("Subject:") . '</TD>' . "\n" .
965 html_tag( 'td', '', 'left', $color[4] ) . "\n";
966 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
967 $subject . '">' . "\n" .
971 if ($location_of_buttons == 'between') {
972 showComposeButtonRow();
975 if ($compose_new_win == '1') {
976 echo ' <TR>' . "\n" .
977 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
978 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
979 $editor_size . '" WRAP="VIRTUAL">';
982 echo ' <TR>' . "\n" .
983 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
984 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
985 $editor_size . '" WRAP="VIRTUAL">';
987 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
989 if ($identity == 'default') {
994 $signature = getSig($data_dir, $username, $no);
997 if ($sig_first == '1') {
998 if ($default_charset == 'iso-2022-jp') {
999 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1001 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false);
1003 echo "\n\n".decodeHeader($body,false,true);
1006 echo "\n\n".decodeHeader($body,false,true);
1007 if ($default_charset == 'iso-2022-jp') {
1008 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1010 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,true);
1015 echo decodeHeader($body,false,true);
1017 echo '</TEXTAREA><BR>' . "\n" .
1022 if ($location_of_buttons == 'bottom') {
1023 showComposeButtonRow();
1025 echo ' <TR>' . "\n" .
1026 html_tag( 'td', '', 'right', '', 'COLSPAN=2' ) . "\n" .
1027 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' . "\n" .
1028 ' <BR><BR>' . "\n" .
1033 /* This code is for attachments */
1034 if ((bool) ini_get('file_uploads')) {
1036 /* Calculate the max size for an uploaded file.
1037 * This is advisory for the user because we can't actually prevent
1038 * people to upload too large files. */
1040 /* php.ini vars which influence the max for uploads */
1041 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1042 foreach($configvars as $var) {
1043 /* skip 0 or empty values */
1044 if( $size = getByteSize(ini_get($var)) ) {
1049 if(count($sizes) > 0) {
1050 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1055 echo ' <tr>' . "\n" .
1056 ' <td colspan="2">' . "\n" .
1057 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1058 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1061 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1062 ' border="0">' . "\n" .
1064 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1065 _("Attach:") . '</td>' . "\n" .
1066 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1067 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1068 ' <input type="submit" name="attach"' .
1069 ' value="' . _("Add") .'">' . "\n" .
1076 if ($composeMessage->entities
) {
1077 foreach ($composeMessage->entities
as $key => $attachment) {
1078 $attached_file = $attachment->att_local_name
;
1079 if ($attachment->att_local_name ||
$attachment->body_part
) {
1080 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1081 $type = $attachment->mime_header
->type0
.'/'.
1082 $attachment->mime_header
->type1
;
1084 $s_a[] = '<table bgcolor="'.$color[0].
1085 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1086 $key . "\"></td><td>\n" . $attached_filename .
1087 '</td><td>-</td><td> ' . $type . '</td><td>('.
1088 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1093 foreach ($s_a as $s) {
1094 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1096 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1097 _("Delete selected attachments") . "\">\n" .
1100 echo ' </table>' . "\n" .
1103 ' </TABLE>' . "\n" .
1106 } // End of file_uploads if-block
1107 /* End of attachment code */
1108 if ($compose_new_win == '1') {
1109 echo '</TABLE>'."\n";
1112 echo '</TABLE>' . "\n" .
1113 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1114 '<input type=hidden name=action value="' . $action . "\">\n" .
1115 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1118 store the complete ComposeMessages array in a hidden input value
1119 so we can restore them in case of a session timeout.
1121 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1122 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1123 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1124 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1126 if (!(bool) ini_get('file_uploads')) {
1127 /* File uploads are off, so we didn't show that part of the form.
1128 To avoid bogus bug reports, tell the user why. */
1129 echo 'Because PHP file uploads are turned off, you can not attach files ';
1130 echo "to this message. Please see your system administrator for details.\r\n";
1133 do_hook('compose_bottom');
1134 echo '</BODY></HTML>' . "\n";
1138 function showComposeButtonRow() {
1139 global $use_javascript_addr_book, $save_as_draft,
1140 $default_use_priority, $mailprio, $default_use_mdn,
1141 $request_mdn, $request_dr,
1142 $data_dir, $username;
1144 echo ' <TR>' . "\n" .
1145 ' <TD></TD>' . "\n" .
1147 if ($default_use_priority) {
1148 if(!isset($mailprio)) {
1151 echo ' ' . _("Priority") .': <select name="mailprio">'.
1152 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1153 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1154 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1157 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1158 if ($default_use_mdn) {
1159 if ($mdn_user_support) {
1160 echo ' ' . _("Receipt") .': '.
1161 '<input type="checkbox" name="request_mdn" value=1'.
1162 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1163 ' <input type="checkbox" name="request_dr" value=1'.
1164 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1168 echo ' </TD>' . "\n" .
1171 ' <TD></TD>' . "\n" .
1173 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1174 if ($use_javascript_addr_book) {
1175 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1176 " <input type=button value=\\\""._("Addresses").
1177 "\\\" onclick='javascript:open_abook();'>\");".
1178 " // --></SCRIPT><NOSCRIPT>\n".
1179 " <input type=submit name=\"html_addr_search\" value=\"".
1180 _("Addresses")."\">".
1183 echo ' <input type=submit name="html_addr_search" value="'.
1184 _("Addresses").'">' . "\n";
1187 if ($save_as_draft) {
1188 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1191 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1192 do_hook('compose_button_row');
1194 echo ' </TD>' . "\n" .
1198 function checkInput ($show) {
1200 * I implemented the $show variable because the error messages
1201 * were getting sent before the page header. So, I check once
1202 * using $show=false, and then when i'm ready to display the error
1203 * message, show=true
1205 global $body, $send_to, $send_to_bcc, $subject, $color;
1207 if ($send_to == '' && $send_to_bcc == '') {
1209 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1214 } /* function checkInput() */
1217 /* True if FAILURE */
1218 function saveAttachedFiles($session) {
1219 global $_FILES, $attachment_dir, $attachments, $username,
1220 $data_dir, $compose_messages;
1222 /* get out of here if no file was attached at all */
1223 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1227 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1228 $localfilename = GenerateRandomString(32, '', 7);
1229 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1230 while (file_exists($full_localfilename)) {
1231 $localfilename = GenerateRandomString(32, '', 7);
1232 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1235 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1236 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1237 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1238 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1242 $message = $compose_messages[$session];
1243 $type = strtolower($_FILES['attachfile']['type']);
1244 $name = $_FILES['attachfile']['name'];
1245 $message->initAttachment($type, $name, $full_localfilename);
1246 $compose_messages[$session] = $message;
1247 sqsession_register($compose_messages , 'compose_messages');
1250 function ClearAttachments($composeMessage) {
1251 if ($composeMessage->att_local_name
) {
1252 $attached_file = $composeMessage->att_local_name
;
1253 if (file_exists($attached_file)) {
1254 unlink($attached_file);
1257 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1258 ClearAttachments($composeMessage->entities
[$i]);
1262 /* parse values like 8M and 2k into bytes */
1263 function getByteSize($ini_size) {
1265 if(!$ini_size) return FALSE;
1267 $ini_size = trim($ini_size);
1269 switch(strtoupper(substr($ini_size, -1))) {
1271 $bytesize = 1073741824;
1274 $bytesize = 1048576;
1283 $bytesize *= (int)substr($ini_size, 0, -1);
1289 /* temporary function to make use of the deliver class.
1290 In the future the responsable backend should be automaticly loaded
1291 and conf.pl should show a list of available backends.
1292 The message also should be constructed by the message class.
1295 function deliverMessage($composeMessage, $draft=false) {
1296 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1297 $username, $popuser, $usernamedata, $identity, $data_dir,
1298 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1300 global $imapServerAddress, $imapPort, $sent_folder, $key;
1302 $rfc822_header = $composeMessage->rfc822_header
;
1304 $abook = addressbook_init(false, true);
1305 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1306 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1307 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1308 $rfc822_header->priority
= $mailprio;
1309 $rfc822_header->subject
= $subject;
1310 $special_encoding='';
1311 if (strtolower($default_charset) == 'iso-2022-jp') {
1312 if (mb_detect_encoding($body) == 'ASCII') {
1313 $special_encoding = '8bit';
1315 $body = mb_convert_encoding($body, 'JIS');
1316 $special_encoding = '7bit';
1319 $composeMessage->setBody($body);
1321 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1322 $popuser = $usernamedata[1];
1323 $domain = $usernamedata[2];
1324 unset($usernamedata);
1326 $popuser = $username;
1329 if (isset($identity) && $identity != 'default') {
1330 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1331 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1332 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1334 $from_mail = getPref($data_dir, $username, 'email_address');
1335 $full_name = getPref($data_dir, $username, 'full_name');
1336 $reply_to = getPref($data_dir, $username,'reply_to');
1339 $from_mail = "$popuser@$domain";
1342 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1344 $from = $rfc822_header->from
[0];
1345 if (!$from->host
) $from->host
= $domain;
1346 $full_name_encoded = encodeHeader($full_name);
1347 if ($full_name_encoded != $full_name) {
1348 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1350 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1352 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1355 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1357 /* Receipt: On Read */
1358 if (isset($request_mdn) && $request_mdn) {
1359 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1361 /* Receipt: On Delivery */
1362 if (isset($request_dr) && $request_dr) {
1363 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1365 /* multipart messages */
1366 if (count($composeMessage->entities
)) {
1367 $message_body = new Message();
1368 $message_body->body_part
= $composeMessage->body_part
;
1369 $composeMessage->body_part
= '';
1370 $mime_header = new MessageHeader
;
1371 $mime_header->type0
= 'text';
1372 $mime_header->type1
= 'plain';
1373 if ($special_encoding) {
1374 $mime_header->encoding
= $special_encoding;
1376 $mime_header->encoding
= '8bit';
1378 if ($default_charset) {
1379 $mime_header->parameters
['charset'] = $default_charset;
1381 $message_body->mime_header
= $mime_header;
1382 array_unshift($composeMessage->entities
, $message_body);
1383 $content_type = new ContentType('multipart/mixed');
1385 $content_type = new ContentType('text/plain');
1387 if ($default_charset) {
1388 $content_type->properties
['charset']=$default_charset;
1391 $rfc822_header->content_type
= $content_type;
1392 $composeMessage->rfc822_header
= $rfc822_header;
1394 if (!$useSendmail && !$draft) {
1395 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1396 $deliver = new Deliver_SMTP();
1397 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1399 if ($smtp_auth_mech == 'none') {
1403 global $key, $onetimepad;
1405 $pass = OneTimePadDecrypt($key, $onetimepad);
1408 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1409 $stream = $deliver->initStream($composeMessage,$domain,0,
1410 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1411 } elseif (!$draft) {
1412 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1413 global $sendmail_path;
1414 $deliver = new Deliver_SendMail();
1415 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1417 global $draft_folder;
1418 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1419 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1421 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1422 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1423 $imap_deliver = new Deliver_IMAP();
1424 $length = $imap_deliver->mail($composeMessage);
1425 sqimap_append ($imap_stream, $draft_folder, $length);
1426 $imap_deliver->mail($composeMessage, $imap_stream);
1427 sqimap_append_done ($imap_stream, $draft_folder);
1428 sqimap_logout($imap_stream);
1429 unset ($imap_deliver);
1432 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1433 plain_error_message($msg, $color);
1439 $length = $deliver->mail($composeMessage, $stream);
1440 $succes = $deliver->finalizeStream($stream);
1443 $msg = $deliver->dlv_msg
. '<br>' .
1444 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1445 $deliver->dlv_server_msg
;
1446 plain_error_message($msg, $color);
1449 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1451 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1452 sqimap_append ($imap_stream, $sent_folder, $length);
1453 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1454 $imap_deliver = new Deliver_IMAP();
1455 $imap_deliver->mail($composeMessage, $imap_stream);
1456 sqimap_append_done ($imap_stream, $sent_folder);
1457 unset ($imap_deliver);
1459 global $passed_id, $mailbox, $action;
1460 ClearAttachments($composeMessage);
1461 if ($action == 'reply' ||
$action == 'reply_all') {
1462 sqimap_mailbox_select ($imap_stream, $mailbox);
1463 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1465 sqimap_logout($imap_stream);