e1c67a644f10388bdff4b76f50db8d87ac5d2ea2
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('action',$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);
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 $url_replytoallcc .= ", $personal <$email>";
133 $url_replytoallcc .= ', '. $email;
136 $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". $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: $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: $location/compose.php?saved_draft=yes&session=$composesession");
312 Header("Location: $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";
369 $composeMessage=$compose_messages[$session];
371 $Result = deliverMessage($composeMessage);
373 showInputForm($session);
376 unset($compose_messages[$session]);
377 if ( isset($delete_draft)) {
378 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
379 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
382 if ($compose_new_win == '1') {
384 Header("Location: $location/compose.php?mail_sent=yes");
387 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
391 if ($compose_new_win == '1') {
392 compose_Header($color, $mailbox);
395 displayPageHeader($color, $mailbox);
397 if (isset($AttachFailure)) {
398 plain_error_message(_("Could not move/copy file. File not attached"),
402 showInputForm($session);
403 /* sqimap_logout($imapConnection); */
405 } elseif (isset($html_addr_search_done)) {
406 if ($compose_new_win == '1') {
407 compose_Header($color, $mailbox);
410 displayPageHeader($color, $mailbox);
413 if (isset($send_to_search) && is_array($send_to_search)) {
414 foreach ($send_to_search as $k => $v) {
415 if (substr($k, 0, 1) == 'T') {
421 elseif (substr($k, 0, 1) == 'C') {
427 elseif (substr($k, 0, 1) == 'B') {
429 $send_to_bcc .= ', ';
435 showInputForm($session);
436 } elseif (isset($html_addr_search)) {
437 if (isset($_FILES['attachfile']) &&
438 $_FILES['attachfile']['tmp_name'] &&
439 $_FILES['attachfile']['tmp_name'] != 'none') {
440 if(saveAttachedFiles($session)) {
441 plain_error_message(_("Could not move/copy file. File not attached"), $color);
445 * I am using an include so as to elminiate an extra unnecessary
446 * click. If you can think of a better way, please implement it.
448 include_once('./addrbook_search_html.php');
449 } elseif (isset($attach)) {
450 if (saveAttachedFiles($session)) {
451 plain_error_message(_("Could not move/copy file. File not attached"), $color);
453 if ($compose_new_win == '1') {
454 compose_Header($color, $mailbox);
457 displayPageHeader($color, $mailbox);
459 showInputForm($session);
461 elseif (isset($sigappend)) {
462 $signature = $idents[$identity]['signature'];
464 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
465 if ($compose_new_win == '1') {
466 compose_Header($color, $mailbox);
468 displayPageHeader($color, $mailbox);
470 showInputForm($session);
471 } elseif (isset($do_delete)) {
472 if ($compose_new_win == '1') {
473 compose_Header($color, $mailbox);
476 displayPageHeader($color, $mailbox);
479 if (isset($delete) && is_array($delete)) {
480 $composeMessage = $compose_messages[$session];
481 foreach($delete as $index) {
482 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
483 unlink ($attached_file);
484 unset ($composeMessage->entities
[$index]);
486 $new_entities = array();
487 foreach ($composeMessage->entities
as $entity) {
488 $new_entities[] = $entity;
490 $composeMessage->entities
= $new_entities;
491 $compose_messages[$session] = $composeMessage;
492 sqsession_register($compose_messages, 'compose_messages');
494 showInputForm($session);
497 * This handles the default case as well as the error case
498 * (they had the same code) --> if (isset($smtpErrors))
501 if ($compose_new_win == '1') {
502 compose_Header($color, $mailbox);
504 displayPageHeader($color, $mailbox);
509 if (!isset($passed_ent_id)) {
512 if (!isset($passed_id)) {
515 if (!isset($mailbox)) {
518 if (!isset($action)) {
522 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
524 /* in case the origin is not read_body.php */
525 if (isset($send_to)) {
526 $values['send_to'] = $send_to;
528 if (isset($send_to_cc)) {
529 $values['send_to_cc'] = $send_to_cc;
531 if (isset($send_to_bcc)) {
532 $values['send_to_bcc'] = $send_to_bcc;
534 if (isset($subject)) {
535 $values['subject'] = $subject;
537 showInputForm($session, $values);
542 /**************** Only function definitions go below *************/
545 /* This function is used when not sending or adding attachments */
546 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
547 global $editor_size, $default_use_priority, $body, $idents,
548 $use_signature, $composesession, $data_dir, $username,
549 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
551 global $languages, $squirrelmail_language;
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);
602 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
603 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
604 if (mb_detect_encoding($bodypart) != 'ASCII') {
605 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
610 if ($default_use_priority) {
611 $mailprio = substr($orig_header->priority
,0,1);
618 //ClearAttachments($session);
621 $from_o = $orig_header->from
;
622 if (is_object($from_o)) {
623 $orig_from = $from_o->getAddress();
628 $identities = array();
629 if (count($idents) > 1) {
630 foreach($idents as $nr=>$data) {
631 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
632 if($enc_from_name == $orig_from) {
636 $identities[] = $enc_from_name;
639 $identity_match = $orig_header->findAddress($identities);
640 if ($identity_match) {
641 $identity = $identity_match;
647 $use_signature = FALSE;
648 $composeMessage->rfc822_header
= $orig_header;
649 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
650 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
651 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
652 $subject = decodeHeader($orig_header->subject
,false,true);
653 // /* remember the references and in-reply-to headers in case of an reply */
654 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
655 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
656 $body_ary = explode("\n", $body);
657 $cnt = count($body_ary) ;
659 for ($i=0; $i < $cnt; $i++
) {
660 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
661 sqWordWrap($body_ary[$i], $editor_size );
662 $body .= $body_ary[$i] . "\n";
664 unset($body_ary[$i]);
667 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
669 case ('edit_as_new'):
670 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
671 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
672 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
673 $subject = decodeHeader($orig_header->subject
,false,true);
674 $mailprio = $orig_header->priority
;
676 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
681 $subject = decodeHeader($orig_header->subject
,false,true);
682 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
683 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
684 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
685 $subject = '[Fwd: ' . $subject . ']';
687 $body = getforwardHeader($orig_header) . $body;
689 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
690 $body = "\n" . $body;
692 case ('forward_as_attachment'):
693 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
697 $send_to_cc = replyAllString($orig_header);
698 $send_to_cc = decodeHeader($send_to_cc,false,true);
700 $send_to = $orig_header->reply_to
;
701 if (is_array($send_to) && count($send_to)) {
702 $send_to = $orig_header->getAddr_s('reply_to');
703 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
704 $send_to = $orig_header->getAddr_s('reply_to');
706 $send_to = $orig_header->getAddr_s('from');
708 $send_to = decodeHeader($send_to,false,true);
709 $subject = decodeHeader($orig_header->subject
,false,true);
710 $subject = str_replace('"', "'", $subject);
711 $subject = trim($subject);
712 if (substr(strtolower($subject), 0, 3) != 're:') {
713 $subject = 'Re: ' . $subject;
715 /* this corrects some wrapping/quoting problems on replies */
716 $rewrap_body = explode("\n", $body);
717 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
720 $cnt = count($rewrap_body);
721 for ($i=0;$i<$cnt;$i++
) {
722 sqWordWrap($rewrap_body[$i], ($editor_size));
723 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
725 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
727 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
729 unset($rewrap_body[$i]);
731 $body = getReplyCitation($from) . $body;
732 $composeMessage->reply_rfc822_header
= $orig_header;
738 $compose_messages[$session] = $composeMessage;
739 sqsession_register($compose_messages, 'compose_messages');
740 session_write_close();
741 sqimap_logout($imapConnection);
743 $ret = array( 'send_to' => $send_to,
744 'send_to_cc' => $send_to_cc,
745 'send_to_bcc' => $send_to_bcc,
746 'subject' => $subject,
747 'mailprio' => $mailprio,
749 'identity' => $identity );
752 } /* function newMail() */
754 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
755 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
756 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
757 if (!count($message->entities
) ||
758 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
759 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
760 switch ($message->type0
) {
762 if ($message->type1
== 'rfc822') {
763 $filename = $message->rfc822_header
->subject
.'.eml';
764 if ($filename == "") {
765 $filename = "untitled-".$message->entity_id
.'.eml';
768 $filename = $message->getFilename();
772 if (!$message->mime_header
) { /* temporary hack */
773 $message->mime_header
= $message->header
;
775 $filename = $message->getFilename();
778 $filename = decodeHeader($filename);
779 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
780 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
781 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
783 $localfilename = GenerateRandomString(32, '', 7);
784 $full_localfilename = "$hashed_attachment_dir/$localfilename";
785 while (file_exists($full_localfilename)) {
786 $localfilename = GenerateRandomString(32, '', 7);
787 $full_localfilename = "$hashed_attachment_dir/$localfilename";
789 $message->att_local_name
= $full_localfilename;
791 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
792 $full_localfilename);
794 /* Write Attachment to file */
795 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
796 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
797 $passed_id, $message->entity_id
),
798 $message->header
->encoding
));
802 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
803 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
806 return $composeMessage;
809 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
810 $passed_ent_id='', $imapConnection) {
811 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
812 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
813 if (!$passed_ent_id) {
814 $body_a = sqimap_run_command($imapConnection,
815 'FETCH '.$passed_id.' RFC822',
816 TRUE, $response, $readmessage,
819 $body_a = sqimap_run_command($imapConnection,
820 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
821 TRUE, $response, $readmessage, $uid_support);
822 $message = $message->parent
;
824 if ($response == 'OK') {
825 $subject = encodeHeader($message->rfc822_header
->subject
);
826 array_shift($body_a);
827 $body = implode('', $body_a) . "\r\n";
829 $localfilename = GenerateRandomString(32, 'FILE', 7);
830 $full_localfilename = "$hashed_attachment_dir/$localfilename";
832 $fp = fopen( $full_localfilename, 'w');
835 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
836 $full_localfilename);
838 return $composeMessage;
841 function showInputForm ($session, $values=false) {
842 global $send_to, $send_to_cc, $body,
843 $passed_body, $color, $use_signature, $signature, $prefix_sig,
844 $editor_size, $attachments, $subject, $newmail,
845 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
846 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
847 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
848 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
849 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
850 $username, $compose_messages, $composesession, $default_charset;
852 $composeMessage = $compose_messages[$session];
855 $send_to = $values['send_to'];
856 $send_to_cc = $values['send_to_cc'];
857 $send_to_bcc = $values['send_to_bcc'];
858 $subject = $values['subject'];
859 $mailprio = $values['mailprio'];
860 $body = $values['body'];
861 $identity = (int) $values['identity'];
863 $send_to = decodeHeader($send_to);
864 $send_to_cc = decodeHeader($send_to_cc);
865 $send_to_bcc = decodeHeader($send_to_bcc);
868 if ($use_javascript_addr_book) {
869 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
870 'function open_abook() { ' . "\n" .
871 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
872 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
873 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
874 ' nwin.opener = document.windows;' . "\n" .
876 "// -->\n</SCRIPT>\n\n";
879 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
880 'ENCTYPE="multipart/form-data"';
881 do_hook("compose_form");
885 if ($action == 'draft') {
886 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
888 if (isset($delete_draft)) {
889 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
891 if (isset($session)) {
892 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
895 if (isset($passed_id)) {
896 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
899 if ($saved_draft == 'yes') {
900 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
902 if ($mail_sent == 'yes') {
903 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
905 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
906 if ($compose_new_win == '1') {
907 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
908 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
910 if ($location_of_buttons == 'top') {
911 showComposeButtonRow();
914 /* display select list for identities */
915 if (count($idents) > 1) {
916 echo ' <tr>' . "\n" .
917 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
918 _("From:") . '</td>' . "\n" .
919 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
920 ' <select name="identity">' . "\n" ;
921 foreach($idents as $id=>$data) {
922 echo '<option value="'.$id.'"';
923 if($id == $identity) {
926 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
930 echo '</select>' . "\n" .
934 echo ' <tr>' . "\n" .
935 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
936 _("To:") . '</TD>' . "\n" .
937 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
938 ' <input type="text" name="send_to" value="' .
939 $send_to . '" size="60" /><br />' . "\n" .
943 html_tag( 'td', '', 'right', $color[4] ) .
944 _("CC:") . '</td>' . "\n" .
945 html_tag( 'td', '', 'left', $color[4] ) .
946 ' <input type="text" name="send_to_cc" size="60" value="' .
947 $send_to_cc . '" /><br />' . "\n" .
951 html_tag( 'td', '', 'right', $color[4] ) .
952 _("BCC:") . '</td>' . "\n" .
953 html_tag( 'td', '', 'left', $color[4] ) .
954 ' <input type="text" name="send_to_bcc" value="' .
955 $send_to_bcc . '" size="60" /><br />' . "\n" .
959 html_tag( 'td', '', 'right', $color[4] ) .
960 _("Subject:") . '</td>' . "\n" .
961 html_tag( 'td', '', 'left', $color[4] ) . "\n";
962 echo ' <input type="text" name="subject" size="60" value="' .
963 $subject . '" />' . "\n" .
967 if ($location_of_buttons == 'between') {
968 showComposeButtonRow();
971 /* why this distinction? */
972 if ($compose_new_win == '1') {
973 echo ' <TR>' . "\n" .
974 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
975 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
976 $editor_size . '" WRAP="VIRTUAL">';
979 echo ' <TR>' . "\n" .
980 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
981 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
982 $editor_size . '" WRAP="VIRTUAL">';
985 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
986 $signature = $idents[$identity]['signature'];
988 if ($sig_first == '1') {
989 if ($default_charset == 'iso-2022-jp') {
990 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
992 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
994 echo "\n\n".decodeHeader($body,false,false);
997 echo "\n\n".decodeHeader($body,false,false);
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,false);
1006 echo decodeHeader($body,false,false);
1008 echo '</textarea><br />' . "\n" .
1013 if ($location_of_buttons == 'bottom') {
1014 showComposeButtonRow();
1016 echo ' <tr>' . "\n" .
1017 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1018 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1019 ' <br /><br />' . "\n" .
1024 /* This code is for attachments */
1025 if ((bool) ini_get('file_uploads')) {
1027 /* Calculate the max size for an uploaded file.
1028 * This is advisory for the user because we can't actually prevent
1029 * people to upload too large files. */
1031 /* php.ini vars which influence the max for uploads */
1032 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1033 foreach($configvars as $var) {
1034 /* skip 0 or empty values */
1035 if( $size = getByteSize(ini_get($var)) ) {
1040 if(count($sizes) > 0) {
1041 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1045 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1046 echo ' <tr>' . "\n" .
1047 ' <td colspan="2">' . "\n" .
1048 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1049 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1052 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1053 ' border="0">' . "\n" .
1055 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1056 _("Attach:") . '</td>' . "\n" .
1057 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1058 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1059 ' <input type="submit" name="attach"' .
1060 ' value="' . _("Add") .'">' . "\n" .
1067 if ($composeMessage->entities
) {
1068 foreach ($composeMessage->entities
as $key => $attachment) {
1069 $attached_file = $attachment->att_local_name
;
1070 if ($attachment->att_local_name ||
$attachment->body_part
) {
1071 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1072 $type = $attachment->mime_header
->type0
.'/'.
1073 $attachment->mime_header
->type1
;
1075 $s_a[] = '<table bgcolor="'.$color[0].
1076 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1077 $key . "\"></td><td>\n" . $attached_filename .
1078 '</td><td>-</td><td> ' . $type . '</td><td>('.
1079 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1084 foreach ($s_a as $s) {
1085 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1087 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1088 _("Delete selected attachments") . "\">\n" .
1091 echo ' </table>' . "\n" .
1094 ' </TABLE>' . "\n" .
1097 } // End of file_uploads if-block
1098 /* End of attachment code */
1099 if ($compose_new_win == '1') {
1100 echo '</TABLE>'."\n";
1103 echo '</TABLE>' . "\n" .
1104 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1105 '<input type=hidden name=action value="' . $action . "\">\n" .
1106 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1109 store the complete ComposeMessages array in a hidden input value
1110 so we can restore them in case of a session timeout.
1112 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1113 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1114 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1115 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1117 if (!(bool) ini_get('file_uploads')) {
1118 /* File uploads are off, so we didn't show that part of the form.
1119 To avoid bogus bug reports, tell the user why. */
1120 echo 'Because PHP file uploads are turned off, you can not attach files ';
1121 echo "to this message. Please see your system administrator for details.\r\n";
1124 do_hook('compose_bottom');
1125 echo '</BODY></HTML>' . "\n";
1129 function showComposeButtonRow() {
1130 global $use_javascript_addr_book, $save_as_draft,
1131 $default_use_priority, $mailprio, $default_use_mdn,
1132 $request_mdn, $request_dr,
1133 $data_dir, $username;
1135 echo ' <TR>' . "\n" .
1136 ' <TD></TD>' . "\n" .
1138 if ($default_use_priority) {
1139 if(!isset($mailprio)) {
1142 echo ' ' . _("Priority") .': <select name="mailprio">'.
1143 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1144 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1145 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1148 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1149 if ($default_use_mdn) {
1150 if ($mdn_user_support) {
1151 echo ' ' . _("Receipt") .': '.
1152 '<input type="checkbox" name="request_mdn" value=1'.
1153 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1154 ' <input type="checkbox" name="request_dr" value=1'.
1155 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1159 echo ' </TD>' . "\n" .
1162 ' <TD></TD>' . "\n" .
1164 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1165 if ($use_javascript_addr_book) {
1166 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1167 " <input type=button value=\\\""._("Addresses").
1168 "\\\" onclick='javascript:open_abook();'>\");".
1169 " // --></SCRIPT><NOSCRIPT>\n".
1170 " <input type=submit name=\"html_addr_search\" value=\"".
1171 _("Addresses")."\">".
1174 echo ' <input type=submit name="html_addr_search" value="'.
1175 _("Addresses").'">' . "\n";
1178 if ($save_as_draft) {
1179 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1182 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1183 do_hook('compose_button_row');
1185 echo ' </TD>' . "\n" .
1189 function checkInput ($show) {
1191 * I implemented the $show variable because the error messages
1192 * were getting sent before the page header. So, I check once
1193 * using $show=false, and then when i'm ready to display the error
1194 * message, show=true
1196 global $body, $send_to, $send_to_bcc, $subject, $color;
1198 if ($send_to == '' && $send_to_bcc == '') {
1200 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1205 } /* function checkInput() */
1208 /* True if FAILURE */
1209 function saveAttachedFiles($session) {
1210 global $_FILES, $attachment_dir, $attachments, $username,
1211 $data_dir, $compose_messages;
1213 /* get out of here if no file was attached at all */
1214 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1218 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1219 $localfilename = GenerateRandomString(32, '', 7);
1220 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1221 while (file_exists($full_localfilename)) {
1222 $localfilename = GenerateRandomString(32, '', 7);
1223 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1226 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1227 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1228 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1229 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1233 $message = $compose_messages[$session];
1234 $type = strtolower($_FILES['attachfile']['type']);
1235 $name = $_FILES['attachfile']['name'];
1236 $message->initAttachment($type, $name, $full_localfilename);
1237 $compose_messages[$session] = $message;
1238 sqsession_register($compose_messages , 'compose_messages');
1241 function ClearAttachments($composeMessage) {
1242 if ($composeMessage->att_local_name
) {
1243 $attached_file = $composeMessage->att_local_name
;
1244 if (file_exists($attached_file)) {
1245 unlink($attached_file);
1248 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1249 ClearAttachments($composeMessage->entities
[$i]);
1253 /* parse values like 8M and 2k into bytes */
1254 function getByteSize($ini_size) {
1260 $ini_size = trim($ini_size);
1262 // if there's some kind of letter at the end of the string we need to multiply.
1263 if(!is_numeric(substr($ini_size, -1))) {
1265 switch(strtoupper(substr($ini_size, -1))) {
1267 $bytesize = 1073741824;
1270 $bytesize = 1048576;
1277 return ($bytesize * (int)substr($ini_size, 0, -1));
1284 /* temporary function to make use of the deliver class.
1285 In the future the responsable backend should be automaticly loaded
1286 and conf.pl should show a list of available backends.
1287 The message also should be constructed by the message class.
1290 function deliverMessage($composeMessage, $draft=false) {
1291 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1292 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1293 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1294 $domain, $action, $default_move_to_sent, $move_to_sent;
1295 global $imapServerAddress, $imapPort, $sent_folder, $key;
1297 /* some browsers replace <space> by nonbreaking spaces
1298 by replacing them back to spaces addressparsing works */
1299 /* FIXME: How to handle in case of other charsets where "\240"
1300 is not a non breaking space ??? */
1302 $send_to = str_replace("\240",' ',$send_to);
1303 $send_to_cc = str_replace("\240",' ',$send_to_cc);
1304 $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1306 $rfc822_header = $composeMessage->rfc822_header
;
1308 $abook = addressbook_init(false, true);
1309 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1310 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1311 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1312 $rfc822_header->priority
= $mailprio;
1313 $rfc822_header->subject
= $subject;
1314 $special_encoding='';
1315 if (strtolower($default_charset) == 'iso-2022-jp') {
1316 if (mb_detect_encoding($body) == 'ASCII') {
1317 $special_encoding = '8bit';
1319 $body = mb_convert_encoding($body, 'JIS');
1320 $special_encoding = '7bit';
1323 $composeMessage->setBody($body);
1325 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1326 $popuser = $usernamedata[1];
1327 $domain = $usernamedata[2];
1328 unset($usernamedata);
1330 $popuser = $username;
1333 $from_mail = $idents[$identity]['email_address'];
1334 $full_name = $idents[$identity]['full_name'];
1335 $reply_to = $idents[$identity]['reply_to'];
1337 $from_mail = "$popuser@$domain";
1339 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1341 $from = $rfc822_header->from
[0];
1342 if (!$from->host
) $from->host
= $domain;
1343 $full_name_encoded = encodeHeader($full_name);
1344 if ($full_name_encoded != $full_name) {
1345 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1347 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1349 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1352 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1354 /* Receipt: On Read */
1355 if (isset($request_mdn) && $request_mdn) {
1356 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1358 /* Receipt: On Delivery */
1359 if (isset($request_dr) && $request_dr) {
1360 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1362 /* multipart messages */
1363 if (count($composeMessage->entities
)) {
1364 $message_body = new Message();
1365 $message_body->body_part
= $composeMessage->body_part
;
1366 $composeMessage->body_part
= '';
1367 $mime_header = new MessageHeader
;
1368 $mime_header->type0
= 'text';
1369 $mime_header->type1
= 'plain';
1370 if ($special_encoding) {
1371 $mime_header->encoding
= $special_encoding;
1373 $mime_header->encoding
= '8bit';
1375 if ($default_charset) {
1376 $mime_header->parameters
['charset'] = $default_charset;
1378 $message_body->mime_header
= $mime_header;
1379 array_unshift($composeMessage->entities
, $message_body);
1380 $content_type = new ContentType('multipart/mixed');
1382 $content_type = new ContentType('text/plain');
1383 if ($special_encoding) {
1384 $rfc822_header->encoding
= $special_encoding;
1386 $rfc822_header->encoding
= '8bit';
1388 if ($default_charset) {
1389 $content_type->properties
['charset']=$default_charset;
1393 $rfc822_header->content_type
= $content_type;
1394 $composeMessage->rfc822_header
= $rfc822_header;
1396 /* Here you can modify the message structure just before we hand
1397 it over to deliver */
1398 do_hook('compose_send');
1400 if (!$useSendmail && !$draft) {
1401 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1402 $deliver = new Deliver_SMTP();
1403 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1405 if ($smtp_auth_mech == 'none') {
1409 global $key, $onetimepad;
1411 $pass = OneTimePadDecrypt($key, $onetimepad);
1414 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1415 $stream = $deliver->initStream($composeMessage,$domain,0,
1416 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1417 } elseif (!$draft) {
1418 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1419 global $sendmail_path;
1420 $deliver = new Deliver_SendMail();
1421 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1423 global $draft_folder;
1424 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1425 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1427 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1428 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1429 $imap_deliver = new Deliver_IMAP();
1430 $length = $imap_deliver->mail($composeMessage);
1431 sqimap_append ($imap_stream, $draft_folder, $length);
1432 $imap_deliver->mail($composeMessage, $imap_stream);
1433 sqimap_append_done ($imap_stream, $draft_folder);
1434 sqimap_logout($imap_stream);
1435 unset ($imap_deliver);
1438 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1439 plain_error_message($msg, $color);
1445 $length = $deliver->mail($composeMessage, $stream);
1446 $succes = $deliver->finalizeStream($stream);
1449 $msg = $deliver->dlv_msg
. '<br>' .
1450 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1451 $deliver->dlv_server_msg
;
1452 plain_error_message($msg, $color);
1455 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1456 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1458 /* Move to sent code */
1459 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1460 $svr_allow_sent = true;
1462 $svr_allow_sent = false;
1465 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1466 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1472 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1473 $lcl_allow_sent = true;
1475 $lcl_allow_sent = false;
1478 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1479 sqimap_append ($imap_stream, $sent_folder, $length);
1480 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1481 $imap_deliver = new Deliver_IMAP();
1482 $imap_deliver->mail($composeMessage, $imap_stream);
1483 sqimap_append_done ($imap_stream, $sent_folder);
1484 unset ($imap_deliver);
1486 global $passed_id, $mailbox, $action;
1487 ClearAttachments($composeMessage);
1488 if ($action == 'reply' ||
$action == 'reply_all') {
1489 sqimap_mailbox_select ($imap_stream, $mailbox);
1490 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1492 sqimap_logout($imap_stream);