e5d206b7de8ae573785cbb8e9985c408187c68c8
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);
139 return $url_replytoallcc;
142 function getReplyCitation($orig_from) {
143 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
144 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
145 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
146 /* First, return an empty string when no citation style selected. */
147 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
151 /* Make sure our final value isn't an empty string. */
152 if ($orig_from == '') {
156 /* Otherwise, try to select the desired citation style. */
157 switch ($reply_citation_style) {
160 $end = ' ' . _("said") . ':';
163 $start = '<' . _("quote") . ' ' . _("who") . '="';
167 $start = $reply_citation_start .
168 ($reply_citation_start == '' ?
'' : ' ');
169 $end = $reply_citation_end;
175 /* Build and return the citation string. */
176 return ($start . $orig_from . $end . "\n");
179 function getforwardHeader($orig_header) {
182 $display = array( _("Subject") => strlen(_("Subject")),
183 _("From") => strlen(_("From")),
184 _("Date") => strlen(_("Date")),
185 _("To") => strlen(_("To")),
186 _("Cc") => strlen(_("Cc")) );
187 $maxsize = max($display);
188 $indent = str_pad('',$maxsize+
2);
189 foreach($display as $key => $val) {
190 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
192 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
193 $from = str_replace(' ',' ',$from);
194 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
195 $to = str_replace(' ',' ',$to);
196 $subject = decodeHeader($orig_header->subject
,false,false);
197 $subject = str_replace(' ',' ',$subject);
198 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
199 "\n". $display[_("Subject")] . $subject . "\n" .
200 $display[_("From")] . $from . "\n" .
201 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
202 $display[_("To")] . $to . "\n";
203 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
204 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
205 $cc = str_replace(' ',' ',$cc);
206 $bodyTop .= $display[_("Cc")] .$cc . "\n";
208 $bodyTop .= str_pad('', $editor_size -2 , '-') .
212 /* ----------------------------------------------------------------------- */
215 * If the session is expired during a post this restores the compose session
218 if (sqsession_is_registered('session_expired_post')) {
219 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
221 * extra check for username so we don't display previous post data from
222 * another user during this session.
224 if ($session_expired_post['username'] != $username) {
225 unset($session_expired_post);
226 sqsession_unregister('session_expired_post');
227 session_write_close();
229 foreach ($session_expired_post as $postvar => $val) {
236 $compose_messages = unserialize(urldecode($restoremessages));
237 sqsession_register($compose_messages,'compose_messages');
238 sqsession_register($composesession,'composesession');
242 $session_expired = true;
244 unset($session_expired_post);
245 sqsession_unregister('session_expired_post');
246 session_write_close();
247 if (!isset($mailbox)) {
250 if ($compose_new_win == '1') {
251 compose_Header($color, $mailbox);
253 displayPageHeader($color, $mailbox);
255 showInputForm($session, false);
258 if (!isset($composesession)) {
260 sqsession_register(0,'composesession');
263 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
264 sqsession_unregister('composesession');
265 $session = "$composesession" +
1;
266 $composesession = $session;
267 sqsession_register($composesession,'composesession');
269 if (!isset($compose_messages)) {
270 $compose_messages = array();
272 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
273 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
274 $composeMessage = new Message();
275 $rfc822_header = new Rfc822Header();
276 $composeMessage->rfc822_header
= $rfc822_header;
277 $composeMessage->reply_rfc822_header
= '';
278 $compose_messages[$session] = $composeMessage;
279 sqsession_register($compose_messages,'compose_messages');
281 $composeMessage=$compose_messages[$session];
284 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
290 * Set $default_charset to correspond with the user's selection
291 * of language interface.
294 $composeMessage=$compose_messages[$session];
295 if (! deliverMessage($composeMessage, true)) {
296 showInputForm($session);
299 unset($compose_messages[$session]);
300 $draft_message = _("Draft Email Saved");
301 /* If this is a resumed draft, then delete the original */
302 if(isset($delete_draft)) {
303 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
304 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
308 if ($compose_new_win == '1') {
309 Header("Location: compose.php?saved_draft=yes&session=$composesession");
313 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
314 "&startMessage=1¬e=".urlencode($draft_message));
322 if (isset($_FILES['attachfile']) &&
323 $_FILES['attachfile']['tmp_name'] &&
324 $_FILES['attachfile']['tmp_name'] != 'none') {
325 $AttachFailure = saveAttachedFiles($session);
327 if (checkInput(false) && !isset($AttachFailure)) {
328 if ($mailbox == "All Folders") {
329 /* We entered compose via the search results page */
330 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
332 $urlMailbox = urlencode (trim($mailbox));
333 if (! isset($passed_id)) {
337 * Set $default_charset to correspond with the user's selection
338 * of language interface.
342 * This is to change all newlines to \n
343 * We'll change them to \r\n later (in the sendMessage function)
345 $body = str_replace("\r\n", "\n", $body);
346 $body = str_replace("\r", "\n", $body);
349 * Rewrap $body so that no line is bigger than $editor_size
350 * This should only really kick in the sqWordWrap function
351 * if the browser doesn't support "VIRTUAL" as the wrap type.
353 $body = explode("\n", $body);
355 foreach ($body as $line) {
356 if( $line <> '-- ' ) {
357 $line = rtrim($line);
359 if (strlen($line) <= $editor_size +
1) {
360 $newBody .= $line . "\n";
362 sqWordWrap($line, $editor_size);
363 $newBody .= $line . "\n";
369 do_hook('compose_send');
370 $composeMessage=$compose_messages[$session];
372 $Result = deliverMessage($composeMessage);
374 showInputForm($session);
377 unset($compose_messages[$session]);
378 if ( isset($delete_draft)) {
379 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
380 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
383 if ($compose_new_win == '1') {
385 Header("Location: compose.php?mail_sent=yes");
388 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
392 if ($compose_new_win == '1') {
393 compose_Header($color, $mailbox);
396 displayPageHeader($color, $mailbox);
398 if (isset($AttachFailure)) {
399 plain_error_message(_("Could not move/copy file. File not attached"),
403 showInputForm($session);
404 /* sqimap_logout($imapConnection); */
406 } elseif (isset($html_addr_search_done)) {
407 if ($compose_new_win == '1') {
408 compose_Header($color, $mailbox);
411 displayPageHeader($color, $mailbox);
414 if (isset($send_to_search) && is_array($send_to_search)) {
415 foreach ($send_to_search as $k => $v) {
416 if (substr($k, 0, 1) == 'T') {
422 elseif (substr($k, 0, 1) == 'C') {
428 elseif (substr($k, 0, 1) == 'B') {
430 $send_to_bcc .= ', ';
436 showInputForm($session);
437 } elseif (isset($html_addr_search)) {
438 if (isset($_FILES['attachfile']) &&
439 $_FILES['attachfile']['tmp_name'] &&
440 $_FILES['attachfile']['tmp_name'] != 'none') {
441 if(saveAttachedFiles($session)) {
442 plain_error_message(_("Could not move/copy file. File not attached"), $color);
446 * I am using an include so as to elminiate an extra unnecessary
447 * click. If you can think of a better way, please implement it.
449 include_once('./addrbook_search_html.php');
450 } elseif (isset($attach)) {
451 if (saveAttachedFiles($session)) {
452 plain_error_message(_("Could not move/copy file. File not attached"), $color);
454 if ($compose_new_win == '1') {
455 compose_Header($color, $mailbox);
458 displayPageHeader($color, $mailbox);
460 showInputForm($session);
462 elseif (isset($sigappend)) {
463 $idents = getPref($data_dir, $username, 'identities', 0);
465 if ($identity == 'default') {
470 $signature = getSig($data_dir, $username, $no);
472 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
473 if ($compose_new_win == '1') {
474 compose_Header($color, $mailbox);
476 displayPageHeader($color, $mailbox);
478 showInputForm($session);
479 } elseif (isset($do_delete)) {
480 if ($compose_new_win == '1') {
481 compose_Header($color, $mailbox);
484 displayPageHeader($color, $mailbox);
487 if (isset($delete) && is_array($delete)) {
488 $composeMessage = $compose_messages[$session];
489 foreach($delete as $index) {
490 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
491 unlink ($attached_file);
492 unset ($composeMessage->entities
[$index]);
494 $new_entities = array();
495 foreach ($composeMessage->entities
as $entity) {
496 $new_entities[] = $entity;
498 $composeMessage->entities
= $new_entities;
499 $compose_messages[$session] = $composeMessage;
500 sqsession_register($compose_messages, 'compose_messages');
502 showInputForm($session);
505 * This handles the default case as well as the error case
506 * (they had the same code) --> if (isset($smtpErrors))
509 if ($compose_new_win == '1') {
510 compose_Header($color, $mailbox);
512 displayPageHeader($color, $mailbox);
517 if (!isset($passed_ent_id)) {
520 if (!isset($passed_id)) {
523 if (!isset($mailbox)) {
526 if (!isset($action)) {
530 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
532 /* in case the origin is not read_body.php */
533 if (isset($send_to)) {
534 $values['send_to'] = $send_to;
536 if (isset($send_to_cc)) {
537 $values['send_to_cc'] = $send_to_cc;
539 if (isset($send_to_bcc)) {
540 $values['send_to_bcc'] = $send_to_bcc;
542 if (isset($subject)) {
543 $values['subject'] = $subject;
545 showInputForm($session, $values);
550 /**************** Only function definitions go below *************/
553 /* This function is used when not sending or adding attachments */
554 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
555 global $editor_size, $default_use_priority, $body,
556 $use_signature, $composesession, $data_dir, $username,
557 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
559 global $languages, $squirrelmail_language;
561 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
565 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
568 sqimap_mailbox_select($imapConnection, $mailbox);
569 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
572 if ($passed_ent_id) {
573 /* redefine the messsage in case of message/rfc822 */
574 $message = $message->getEntity($passed_ent_id);
575 /* message is an entity which contains the envelope and type0=message
576 * and type1=rfc822. The actual entities are childs from
577 * $message->entities[0]. That's where the encoding and is located
580 $entities = $message->entities
[0]->findDisplayEntity
581 (array(), $alt_order = array('text/plain'));
582 if (!count($entities)) {
583 $entities = $message->entities
[0]->findDisplayEntity
584 (array(), $alt_order = array('text/plain','html/plain'));
586 $orig_header = $message->rfc822_header
; /* here is the envelope located */
587 /* redefine the message for picking up the attachments */
588 $message = $message->entities
[0];
591 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
592 if (!count($entities)) {
593 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
595 $orig_header = $message->rfc822_header
;
598 $encoding = $message->header
->encoding
;
599 $type0 = $message->type0
;
600 $type1 = $message->type1
;
601 foreach ($entities as $ent) {
602 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
603 $body_part_entity = $message->getEntity($ent);
604 $bodypart = decodeBody($unencoded_bodypart,
605 $body_part_entity->header
->encoding
);
606 if ($type1 == 'html') {
607 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
608 $bodypart = strip_tags($bodypart);
610 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
611 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
612 if (mb_detect_encoding($bodypart) != 'ASCII') {
613 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
618 if ($default_use_priority) {
619 $mailprio = substr($orig_header->priority
,0,1);
626 //ClearAttachments($session);
629 $idents = getPref($data_dir, $username, 'identities');
630 $from_o = $orig_header->from
;
631 if (is_object($from_o)) {
632 $orig_from = $from_o->getAddress();
636 $identities = array();
637 if (!empty($idents) && $idents > 1) {
638 $identities[] = '"'. getPref($data_dir, $username, 'full_name')
639 . '" <' . getPref($data_dir, $username, 'email_address') . '>';
640 for ($i = 1; $i < $idents; $i++
) {
641 $enc_from_name = '"'.
642 getPref($data_dir, $username, 'full_name' . $i) .
644 getPref($data_dir, $username, 'email_address' . $i) . '>';
645 if ($enc_from_name == $orig_from && $i) {
649 $identities[] = $enc_from_name;
651 $identity_match = $orig_header->findAddress($identities);
652 if ($identity_match) {
653 $identity = $identity_match;
659 $use_signature = FALSE;
660 $composeMessage->rfc822_header
= $orig_header;
661 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
662 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
663 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
664 $subject = decodeHeader($orig_header->subject
,false,true);
665 // /* remember the references and in-reply-to headers in case of an reply */
666 // $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
667 // $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
668 $body_ary = explode("\n", $body);
669 $cnt = count($body_ary) ;
671 for ($i=0; $i < $cnt; $i++
) {
672 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
673 sqWordWrap($body_ary[$i], $editor_size );
674 $body .= $body_ary[$i] . "\n";
676 unset($body_ary[$i]);
679 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
681 case ('edit_as_new'):
682 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
683 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
684 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
685 $subject = decodeHeader($orig_header->subject
,false,true);
686 $mailprio = $orig_header->priority
;
688 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
693 $subject = decodeHeader($orig_header->subject
,false,true);
694 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
695 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
696 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
697 $subject = '[Fwd: ' . $subject . ']';
699 $body = getforwardHeader($orig_header) . $body;
701 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
702 $body = "\n" . $body;
704 case ('forward_as_attachment'):
705 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
709 $send_to_cc = replyAllString($orig_header);
710 $send_to_cc = decodeHeader($send_to_cc,false,true);
712 $send_to = $orig_header->reply_to
;
713 if (is_array($send_to) && count($send_to)) {
714 $send_to = $orig_header->getAddr_s('reply_to');
715 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
716 $send_to = $orig_header->getAddr_s('reply_to');
718 $send_to = $orig_header->getAddr_s('from');
720 $send_to = decodeHeader($send_to,false,true);
721 $subject = decodeHeader($orig_header->subject
,false,true);
722 $subject = str_replace('"', "'", $subject);
723 $subject = trim($subject);
724 if (substr(strtolower($subject), 0, 3) != 're:') {
725 $subject = 'Re: ' . $subject;
727 /* this corrects some wrapping/quoting problems on replies */
728 $rewrap_body = explode("\n", $body);
729 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
732 $cnt = count($rewrap_body);
733 for ($i=0;$i<$cnt;$i++
) {
734 sqWordWrap($rewrap_body[$i], ($editor_size));
735 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
737 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
739 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
741 unset($rewrap_body[$i]);
743 $body = getReplyCitation($from) . $body;
744 $composeMessage->reply_rfc822_header
= $orig_header;
750 $compose_messages[$session] = $composeMessage;
751 sqsession_register($compose_messages, 'compose_messages');
752 session_write_close();
753 sqimap_logout($imapConnection);
755 $ret = array( 'send_to' => $send_to,
756 'send_to_cc' => $send_to_cc,
757 'send_to_bcc' => $send_to_bcc,
758 'subject' => $subject,
759 'mailprio' => $mailprio,
761 'identity' => $identity );
764 } /* function newMail() */
766 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
767 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
768 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
769 if (!count($message->entities
) ||
770 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
771 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
772 switch ($message->type0
) {
774 if ($message->type1
== 'rfc822') {
775 $filename = $message->rfc822_header
->subject
.'.eml';
776 if ($filename == "") {
777 $filename = "untitled-".$message->entity_id
.'.eml';
780 $filename = $message->getFilename();
784 $filename = $message->getFilename();
787 $filename = decodeHeader($filename);
788 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
789 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
790 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
792 $localfilename = GenerateRandomString(32, '', 7);
793 $full_localfilename = "$hashed_attachment_dir/$localfilename";
794 while (file_exists($full_localfilename)) {
795 $localfilename = GenerateRandomString(32, '', 7);
796 $full_localfilename = "$hashed_attachment_dir/$localfilename";
798 $message->att_local_name
= $full_localfilename;
799 if (!$message->mime_header
) { /* temporary hack */
800 $message->mime_header
= $message->header
;
803 $composeMessage->addEntity($message);
805 /* Write Attachment to file */
806 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
807 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
808 $passed_id, $message->entity_id
),
809 $message->header
->encoding
));
813 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
814 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
817 return $composeMessage;
820 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
821 $passed_ent_id='', $imapConnection) {
822 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
823 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
824 if (!$passed_ent_id) {
825 $body_a = sqimap_run_command($imapConnection,
826 'FETCH '.$passed_id.' RFC822',
827 TRUE, $response, $readmessage,
830 $body_a = sqimap_run_command($imapConnection,
831 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
832 TRUE, $response, $readmessage, $uid_support);
833 $message = $message->parent
;
835 if ($response == 'OK') {
836 $subject = encodeHeader($message->rfc822_header
->subject
);
837 array_shift($body_a);
838 $body = implode('', $body_a) . "\r\n";
840 $localfilename = GenerateRandomString(32, 'FILE', 7);
841 $full_localfilename = "$hashed_attachment_dir/$localfilename";
843 $fp = fopen( $full_localfilename, 'w');
846 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
847 $full_localfilename);
849 return $composeMessage;
852 function showInputForm ($session, $values=false) {
853 global $send_to, $send_to_cc, $body,
854 $passed_body, $color, $use_signature, $signature, $prefix_sig,
855 $editor_size, $attachments, $subject, $newmail,
856 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
857 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
858 $username, $data_dir, $identity, $draft_id, $delete_draft,
859 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
860 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
861 $username, $compose_messages, $composesession, $default_charset;
863 $composeMessage = $compose_messages[$session];
866 $send_to = $values['send_to'];
867 $send_to_cc = $values['send_to_cc'];
868 $send_to_bcc = $values['send_to_bcc'];
869 $subject = $values['subject'];
870 $mailprio = $values['mailprio'];
871 $body = $values['body'];
872 $identity = (int) $values['identity'];
874 $send_to = decodeHeader($send_to);
875 $send_to_cc = decodeHeader($send_to_cc);
876 $send_to_bcc = decodeHeader($send_to_bcc);
879 if ($use_javascript_addr_book) {
880 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
881 'function open_abook() { ' . "\n" .
882 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
883 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
884 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
885 ' nwin.opener = document.windows;' . "\n" .
887 '// --></SCRIPT>' . "\n\n";
890 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
891 'ENCTYPE="multipart/form-data"';
892 do_hook("compose_form");
896 if ($action == 'draft') {
897 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
899 if (isset($delete_draft)) {
900 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
902 if (isset($session)) {
903 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
906 if (isset($passed_id)) {
907 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
910 if ($saved_draft == 'yes') {
911 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
913 if ($mail_sent == 'yes') {
914 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
916 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
917 if ($compose_new_win == '1') {
918 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
919 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
921 if ($location_of_buttons == 'top') {
922 showComposeButtonRow();
925 /* display select list for identities */
926 $idents = getPref($data_dir, $username, 'identities', 0);
928 $fn = getPref($data_dir, $username, 'full_name');
929 $em = getPref($data_dir, $username, 'email_address');
930 echo ' <tr>' . "\n" .
931 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
932 _("From:") . '</td>' . "\n" .
933 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
934 ' <select name="identity">' . "\n" .
935 ' <option value="default">' .
936 htmlspecialchars($fn);
939 echo htmlspecialchars(' <' . $em . '>') . "\n";
941 echo htmlspecialchars($em) . "\n";
944 for ($i = 1; $i < $idents; $i ++
) {
945 $fn = getPref($data_dir, $username, 'full_name' . $i);
946 $em = getPref($data_dir, $username, 'email_address' . $i);
948 echo '<option value="' . $i . '"';
949 if (isset($identity) && $identity == $i) {
952 echo '>' . htmlspecialchars($fn);
955 echo htmlspecialchars(' <' . $em . '>') . "\n";
957 echo htmlspecialchars($em) . "\n";
962 echo '</select>' . "\n" .
966 echo ' <tr>' . "\n" .
967 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
968 _("To:") . '</TD>' . "\n" .
969 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
970 ' <input type="text" name="send_to" value="' .
971 $send_to . '" size="60" /><br />' . "\n" .
975 html_tag( 'td', '', 'right', $color[4] ) .
976 _("CC:") . '</td>' . "\n" .
977 html_tag( 'td', '', 'left', $color[4] ) .
978 ' <input type="text" name="send_to_cc" size="60" value="' .
979 $send_to_cc . '" /><br />' . "\n" .
983 html_tag( 'td', '', 'right', $color[4] ) .
984 _("BCC:") . '</td>' . "\n" .
985 html_tag( 'td', '', 'left', $color[4] ) .
986 ' <input type="text" name="send_to_bcc" value="' .
987 $send_to_bcc . '" size="60" /><br />' . "\n" .
991 html_tag( 'td', '', 'right', $color[4] ) .
992 _("Subject:") . '</td>' . "\n" .
993 html_tag( 'td', '', 'left', $color[4] ) . "\n";
994 echo ' <input type="text" name="subject" size="60" value="' .
995 $subject . '" />' . "\n" .
999 if ($location_of_buttons == 'between') {
1000 showComposeButtonRow();
1003 /* why this distinction? */
1004 if ($compose_new_win == '1') {
1005 echo ' <TR>' . "\n" .
1006 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1007 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1008 $editor_size . '" WRAP="VIRTUAL">';
1011 echo ' <TR>' . "\n" .
1012 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1013 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1014 $editor_size . '" WRAP="VIRTUAL">';
1017 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1019 if ($identity == 'default') {
1024 $signature = getSig($data_dir, $username, $no);
1027 if ($sig_first == '1') {
1028 if ($default_charset == 'iso-2022-jp') {
1029 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1031 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1033 echo "\n\n".decodeHeader($body,false,false);
1036 echo "\n\n".decodeHeader($body,false,false);
1037 if ($default_charset == 'iso-2022-jp') {
1038 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1040 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1045 echo decodeHeader($body,false,false);
1047 echo '</textarea><br />' . "\n" .
1052 if ($location_of_buttons == 'bottom') {
1053 showComposeButtonRow();
1055 echo ' <tr>' . "\n" .
1056 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1057 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1058 ' <br /><br />' . "\n" .
1063 /* This code is for attachments */
1064 if ((bool) ini_get('file_uploads')) {
1066 /* Calculate the max size for an uploaded file.
1067 * This is advisory for the user because we can't actually prevent
1068 * people to upload too large files. */
1070 /* php.ini vars which influence the max for uploads */
1071 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1072 foreach($configvars as $var) {
1073 /* skip 0 or empty values */
1074 if( $size = getByteSize(ini_get($var)) ) {
1079 if(count($sizes) > 0) {
1080 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1085 echo ' <tr>' . "\n" .
1086 ' <td colspan="2">' . "\n" .
1087 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1088 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1091 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1092 ' border="0">' . "\n" .
1094 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1095 _("Attach:") . '</td>' . "\n" .
1096 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1097 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1098 ' <input type="submit" name="attach"' .
1099 ' value="' . _("Add") .'">' . "\n" .
1106 if ($composeMessage->entities
) {
1107 foreach ($composeMessage->entities
as $key => $attachment) {
1108 $attached_file = $attachment->att_local_name
;
1109 if ($attachment->att_local_name ||
$attachment->body_part
) {
1110 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1111 $type = $attachment->mime_header
->type0
.'/'.
1112 $attachment->mime_header
->type1
;
1114 $s_a[] = '<table bgcolor="'.$color[0].
1115 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1116 $key . "\"></td><td>\n" . $attached_filename .
1117 '</td><td>-</td><td> ' . $type . '</td><td>('.
1118 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1123 foreach ($s_a as $s) {
1124 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1126 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1127 _("Delete selected attachments") . "\">\n" .
1130 echo ' </table>' . "\n" .
1133 ' </TABLE>' . "\n" .
1136 } // End of file_uploads if-block
1137 /* End of attachment code */
1138 if ($compose_new_win == '1') {
1139 echo '</TABLE>'."\n";
1142 echo '</TABLE>' . "\n" .
1143 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1144 '<input type=hidden name=action value="' . $action . "\">\n" .
1145 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1148 store the complete ComposeMessages array in a hidden input value
1149 so we can restore them in case of a session timeout.
1151 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1152 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1153 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1154 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1156 if (!(bool) ini_get('file_uploads')) {
1157 /* File uploads are off, so we didn't show that part of the form.
1158 To avoid bogus bug reports, tell the user why. */
1159 echo 'Because PHP file uploads are turned off, you can not attach files ';
1160 echo "to this message. Please see your system administrator for details.\r\n";
1163 do_hook('compose_bottom');
1164 echo '</BODY></HTML>' . "\n";
1168 function showComposeButtonRow() {
1169 global $use_javascript_addr_book, $save_as_draft,
1170 $default_use_priority, $mailprio, $default_use_mdn,
1171 $request_mdn, $request_dr,
1172 $data_dir, $username;
1174 echo ' <TR>' . "\n" .
1175 ' <TD></TD>' . "\n" .
1177 if ($default_use_priority) {
1178 if(!isset($mailprio)) {
1181 echo ' ' . _("Priority") .': <select name="mailprio">'.
1182 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1183 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1184 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1187 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1188 if ($default_use_mdn) {
1189 if ($mdn_user_support) {
1190 echo ' ' . _("Receipt") .': '.
1191 '<input type="checkbox" name="request_mdn" value=1'.
1192 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1193 ' <input type="checkbox" name="request_dr" value=1'.
1194 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1198 echo ' </TD>' . "\n" .
1201 ' <TD></TD>' . "\n" .
1203 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1204 if ($use_javascript_addr_book) {
1205 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1206 " <input type=button value=\\\""._("Addresses").
1207 "\\\" onclick='javascript:open_abook();'>\");".
1208 " // --></SCRIPT><NOSCRIPT>\n".
1209 " <input type=submit name=\"html_addr_search\" value=\"".
1210 _("Addresses")."\">".
1213 echo ' <input type=submit name="html_addr_search" value="'.
1214 _("Addresses").'">' . "\n";
1217 if ($save_as_draft) {
1218 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1221 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1222 do_hook('compose_button_row');
1224 echo ' </TD>' . "\n" .
1228 function checkInput ($show) {
1230 * I implemented the $show variable because the error messages
1231 * were getting sent before the page header. So, I check once
1232 * using $show=false, and then when i'm ready to display the error
1233 * message, show=true
1235 global $body, $send_to, $send_to_bcc, $subject, $color;
1237 if ($send_to == '' && $send_to_bcc == '') {
1239 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1244 } /* function checkInput() */
1247 /* True if FAILURE */
1248 function saveAttachedFiles($session) {
1249 global $_FILES, $attachment_dir, $attachments, $username,
1250 $data_dir, $compose_messages;
1252 /* get out of here if no file was attached at all */
1253 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1257 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1258 $localfilename = GenerateRandomString(32, '', 7);
1259 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1260 while (file_exists($full_localfilename)) {
1261 $localfilename = GenerateRandomString(32, '', 7);
1262 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1265 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1266 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1267 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1268 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1272 $message = $compose_messages[$session];
1273 $type = strtolower($_FILES['attachfile']['type']);
1274 $name = $_FILES['attachfile']['name'];
1275 $message->initAttachment($type, $name, $full_localfilename);
1276 $compose_messages[$session] = $message;
1277 sqsession_register($compose_messages , 'compose_messages');
1280 function ClearAttachments($composeMessage) {
1281 if ($composeMessage->att_local_name
) {
1282 $attached_file = $composeMessage->att_local_name
;
1283 if (file_exists($attached_file)) {
1284 unlink($attached_file);
1287 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1288 ClearAttachments($composeMessage->entities
[$i]);
1292 /* parse values like 8M and 2k into bytes */
1293 function getByteSize($ini_size) {
1299 $ini_size = trim($ini_size);
1301 // if there's some kind of letter at the end of the string we need to multiply.
1302 if(!is_numeric(substr($ini_size, -1))) {
1304 switch(strtoupper(substr($ini_size, -1))) {
1306 $bytesize = 1073741824;
1309 $bytesize = 1048576;
1316 return ($bytesize * (int)substr($ini_size, 0, -1));
1323 /* temporary function to make use of the deliver class.
1324 In the future the responsable backend should be automaticly loaded
1325 and conf.pl should show a list of available backends.
1326 The message also should be constructed by the message class.
1329 function deliverMessage($composeMessage, $draft=false) {
1330 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1331 $username, $popuser, $usernamedata, $identity, $data_dir,
1332 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1333 $domain, $action, $default_move_to_sent, $move_to_sent;
1334 global $imapServerAddress, $imapPort, $sent_folder, $key;
1336 $rfc822_header = $composeMessage->rfc822_header
;
1338 $abook = addressbook_init(false, true);
1339 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1340 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1341 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1342 $rfc822_header->priority
= $mailprio;
1343 $rfc822_header->subject
= $subject;
1344 $special_encoding='';
1345 if (strtolower($default_charset) == 'iso-2022-jp') {
1346 if (mb_detect_encoding($body) == 'ASCII') {
1347 $special_encoding = '8bit';
1349 $body = mb_convert_encoding($body, 'JIS');
1350 $special_encoding = '7bit';
1353 $composeMessage->setBody($body);
1355 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1356 $popuser = $usernamedata[1];
1357 $domain = $usernamedata[2];
1358 unset($usernamedata);
1360 $popuser = $username;
1363 if (isset($identity) && $identity != 'default') {
1364 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1365 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1366 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1368 $from_mail = getPref($data_dir, $username, 'email_address');
1369 $full_name = getPref($data_dir, $username, 'full_name');
1370 $reply_to = getPref($data_dir, $username,'reply_to');
1373 $from_mail = "$popuser@$domain";
1376 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1378 $from = $rfc822_header->from
[0];
1379 if (!$from->host
) $from->host
= $domain;
1380 $full_name_encoded = encodeHeader($full_name);
1381 if ($full_name_encoded != $full_name) {
1382 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1384 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1386 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1389 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1391 /* Receipt: On Read */
1392 if (isset($request_mdn) && $request_mdn) {
1393 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1395 /* Receipt: On Delivery */
1396 if (isset($request_dr) && $request_dr) {
1397 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1399 /* multipart messages */
1400 if (count($composeMessage->entities
)) {
1401 $message_body = new Message();
1402 $message_body->body_part
= $composeMessage->body_part
;
1403 $composeMessage->body_part
= '';
1404 $mime_header = new MessageHeader
;
1405 $mime_header->type0
= 'text';
1406 $mime_header->type1
= 'plain';
1407 if ($special_encoding) {
1408 $mime_header->encoding
= $special_encoding;
1410 $mime_header->encoding
= '8bit';
1412 if ($default_charset) {
1413 $mime_header->parameters
['charset'] = $default_charset;
1415 $message_body->mime_header
= $mime_header;
1416 array_unshift($composeMessage->entities
, $message_body);
1417 $content_type = new ContentType('multipart/mixed');
1419 $content_type = new ContentType('text/plain');
1420 if ($special_encoding) {
1421 $rfc822_header->encoding
= $special_encoding;
1423 $rfc822_header->encoding
= '8bit';
1426 if ($default_charset) {
1427 $content_type->properties
['charset']=$default_charset;
1430 $rfc822_header->content_type
= $content_type;
1431 $composeMessage->rfc822_header
= $rfc822_header;
1433 if (!$useSendmail && !$draft) {
1434 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1435 $deliver = new Deliver_SMTP();
1436 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1438 if ($smtp_auth_mech == 'none') {
1442 global $key, $onetimepad;
1444 $pass = OneTimePadDecrypt($key, $onetimepad);
1447 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1448 $stream = $deliver->initStream($composeMessage,$domain,0,
1449 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1450 } elseif (!$draft) {
1451 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1452 global $sendmail_path;
1453 $deliver = new Deliver_SendMail();
1454 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1456 global $draft_folder;
1457 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1458 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1460 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1461 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1462 $imap_deliver = new Deliver_IMAP();
1463 $length = $imap_deliver->mail($composeMessage);
1464 sqimap_append ($imap_stream, $draft_folder, $length);
1465 $imap_deliver->mail($composeMessage, $imap_stream);
1466 sqimap_append_done ($imap_stream, $draft_folder);
1467 sqimap_logout($imap_stream);
1468 unset ($imap_deliver);
1471 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1472 plain_error_message($msg, $color);
1478 $length = $deliver->mail($composeMessage, $stream);
1479 $succes = $deliver->finalizeStream($stream);
1482 $msg = $deliver->dlv_msg
. '<br>' .
1483 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1484 $deliver->dlv_server_msg
;
1485 plain_error_message($msg, $color);
1488 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1489 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1490 if (sqimap_mailbox_exists ($imap_stream, $sent_folder) && ((isset($move_to_sent) && $move_to_sent) ||
1491 (isset($default_move_to_sent) && $default_move_to_sent))) {
1492 sqimap_append ($imap_stream, $sent_folder, $length);
1493 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1494 $imap_deliver = new Deliver_IMAP();
1495 $imap_deliver->mail($composeMessage, $imap_stream);
1496 sqimap_append_done ($imap_stream, $sent_folder);
1497 unset ($imap_deliver);
1499 global $passed_id, $mailbox, $action;
1500 ClearAttachments($composeMessage);
1501 if ($action == 'reply' ||
$action == 'reply_all') {
1502 sqimap_mailbox_select ($imap_stream, $mailbox);
1503 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1505 sqimap_logout($imap_stream);