6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
20 /* Path for SquirrelMail required files. */
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 require_once(SM_PATH
. 'functions/global.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/date.php');
28 require_once(SM_PATH
. 'functions/mime.php');
29 require_once(SM_PATH
. 'functions/plugin.php');
30 require_once(SM_PATH
. 'functions/display_messages.php');
31 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
32 require_once(SM_PATH
. 'functions/addressbook.php');
33 require_once(SM_PATH
. 'functions/identity.php');
35 /* --------------------- Get globals ------------------------------------- */
37 sqgetGlobalVar('key', $key, SQ_COOKIE
);
40 sqgetGlobalVar('username', $username, SQ_SESSION
);
41 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
42 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
43 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
45 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
46 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
48 /** SESSION/POST/GET VARS */
49 sqgetGlobalVar('smaction',$action);
50 sqgetGlobalVar('session',$session);
51 sqgetGlobalVar('mailbox',$mailbox);
52 if(!sqgetGlobalVar('identity',$identity)) {
55 sqgetGlobalVar('send_to',$send_to);
56 sqgetGlobalVar('send_to_cc',$send_to_cc);
57 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
58 sqgetGlobalVar('subject',$subject);
59 sqgetGlobalVar('body',$body);
60 sqgetGlobalVar('mailprio',$mailprio);
61 sqgetGlobalVar('request_mdn',$request_mdn);
62 sqgetGlobalVar('request_dr',$request_dr);
63 sqgetGlobalVar('html_addr_search',$html_addr_search);
64 sqgetGlobalVar('mail_sent',$mail_sent);
65 sqgetGlobalVar('passed_id',$passed_id);
66 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
67 sqgetGlobalVar('send',$send);
69 sqgetGlobalVar('attach',$attach);
71 sqgetGlobalVar('draft',$draft);
72 sqgetGlobalVar('draft_id',$draft_id);
73 sqgetGlobalVar('ent_num',$ent_num);
74 sqgetGlobalVar('saved_draft',$saved_draft);
75 sqgetGlobalVar('delete_draft',$delete_draft);
76 sqgetGlobalVar('startmessage',$startMessage);
79 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
80 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
81 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
82 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
83 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
84 sqgetGlobalVar('delete', $delete, SQ_POST
);
85 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
86 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
87 $html_addr_search_done = 'Use Addresses';
91 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
93 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
94 $location = get_location();
95 /* Identities (fetch only once) */
96 $idents = get_identities();
98 /* --------------------- Specific Functions ------------------------------ */
100 function replyAllString($header) {
101 global $include_self_reply_all, $idents;
104 * 1) Remove the addresses we'll be sending the message 'to'
106 $url_replytoall_avoid_addrs = '';
107 if (isset($header->replyto
)) {
108 $excl_ar = $header->getAddr_a('replyto');
111 * 2) Remove our identities from the CC list (they still can be in the
112 * TO list) only if $include_self_reply_all is turned off
114 if (!$include_self_reply_all) {
115 foreach($idents as $id) {
116 $excl_ar[strtolower(trim($id['email_address']))] = '';
121 * 3) get the addresses.
123 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
126 * 4) generate the string.
128 $url_replytoallcc = '';
129 foreach( $url_replytoall_ar as $email => $personal) {
131 $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".
388 "&startMessage=$startMessage&mail_sent=yes");
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 *************/
544 function getforwardSubject($subject)
546 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
547 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
548 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
549 $subject = '[Fwd: ' . $subject . ']';
554 /* This function is used when not sending or adding attachments */
555 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
556 global $editor_size, $default_use_priority, $body, $idents,
557 $use_signature, $composesession, $data_dir, $username,
558 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
560 global $languages, $squirrelmail_language;
562 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
566 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
569 sqimap_mailbox_select($imapConnection, $mailbox);
570 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
573 if ($passed_ent_id) {
574 /* redefine the messsage in case of message/rfc822 */
575 $message = $message->getEntity($passed_ent_id);
576 /* message is an entity which contains the envelope and type0=message
577 * and type1=rfc822. The actual entities are childs from
578 * $message->entities[0]. That's where the encoding and is located
581 $entities = $message->entities
[0]->findDisplayEntity
582 (array(), $alt_order = array('text/plain'));
583 if (!count($entities)) {
584 $entities = $message->entities
[0]->findDisplayEntity
585 (array(), $alt_order = array('text/plain','html/plain'));
587 $orig_header = $message->rfc822_header
; /* here is the envelope located */
588 /* redefine the message for picking up the attachments */
589 $message = $message->entities
[0];
592 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
593 if (!count($entities)) {
594 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
596 $orig_header = $message->rfc822_header
;
599 $encoding = $message->header
->encoding
;
600 $type0 = $message->type0
;
601 $type1 = $message->type1
;
602 foreach ($entities as $ent) {
603 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
604 $body_part_entity = $message->getEntity($ent);
605 $bodypart = decodeBody($unencoded_bodypart,
606 $body_part_entity->header
->encoding
);
607 if ($type1 == 'html') {
608 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
609 $bodypart = strip_tags($bodypart);
611 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
612 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
613 if (mb_detect_encoding($bodypart) != 'ASCII') {
614 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
619 if ($default_use_priority) {
620 $mailprio = substr($orig_header->priority
,0,1);
627 //ClearAttachments($session);
630 $from_o = $orig_header->from
;
631 if (is_object($from_o)) {
632 $orig_from = $from_o->getAddress();
637 $identities = array();
638 if (count($idents) > 1) {
639 foreach($idents as $nr=>$data) {
640 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
641 if($enc_from_name == $orig_from) {
645 $identities[] = $enc_from_name;
648 $identity_match = $orig_header->findAddress($identities);
649 if ($identity_match) {
650 $identity = $identity_match;
656 $use_signature = FALSE;
657 $composeMessage->rfc822_header
= $orig_header;
658 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
659 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
660 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
661 $subject = decodeHeader($orig_header->subject
,false,true);
662 // /* remember the references and in-reply-to headers in case of an reply */
663 $composeMessage->rfc822_header
->more_headers
['References'] = $orig_header->references
;
664 $composeMessage->rfc822_header
->more_headers
['In-Reply-To'] = $orig_header->in_reply_to
;
665 $body_ary = explode("\n", $body);
666 $cnt = count($body_ary) ;
668 for ($i=0; $i < $cnt; $i++
) {
669 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
670 sqWordWrap($body_ary[$i], $editor_size );
671 $body .= $body_ary[$i] . "\n";
673 unset($body_ary[$i]);
676 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
678 case ('edit_as_new'):
679 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
680 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
681 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
682 $subject = decodeHeader($orig_header->subject
,false,true);
683 $mailprio = $orig_header->priority
;
685 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
690 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
691 $body = getforwardHeader($orig_header) . $body;
693 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
694 $body = "\n" . $body;
696 case ('forward_as_attachment'):
697 $subject = getforwardSubject(decodeHeader($orig_header->subject
,false,true));
698 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
702 if(isset($orig_header->mail_followup_to
) && $orig_header->mail_followup_to
) {
703 $send_to = $orig_header->getAddr_s('mail_followup_to');
705 $send_to_cc = replyAllString($orig_header);
706 $send_to_cc = decodeHeader($send_to_cc,false,true);
709 // skip this if send_to was already set right above here
711 $send_to = $orig_header->reply_to
;
712 if (is_array($send_to) && count($send_to)) {
713 $send_to = $orig_header->getAddr_s('reply_to');
714 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
715 $send_to = $orig_header->getAddr_s('reply_to');
717 $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
;
730 sqUnWordWrap($body); // unwrap and then reset it?!
732 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
733 foreach ($rewrap_body as $line) {
734 if ($strip_sigs && substr($line,0,3) == '-- ') {
737 sqWordWrap($line, ($editor_size));
738 if (preg_match("/^(>+)/", $line, $matches)) {
740 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
742 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
745 $body = getReplyCitation($from) . $body;
746 $composeMessage->reply_rfc822_header
= $orig_header;
752 $compose_messages[$session] = $composeMessage;
753 sqsession_register($compose_messages, 'compose_messages');
754 session_write_close();
755 sqimap_logout($imapConnection);
757 $ret = array( 'send_to' => $send_to,
758 'send_to_cc' => $send_to_cc,
759 'send_to_bcc' => $send_to_bcc,
760 'subject' => $subject,
761 'mailprio' => $mailprio,
763 'identity' => $identity );
766 } /* function newMail() */
768 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
769 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
770 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
771 if (!count($message->entities
) ||
772 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
773 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
774 switch ($message->type0
) {
776 if ($message->type1
== 'rfc822') {
777 $filename = $message->rfc822_header
->subject
;
778 if ($filename == "") {
779 $filename = "untitled-".$message->entity_id
;
783 $filename = $message->getFilename();
787 if (!$message->mime_header
) { /* temporary hack */
788 $message->mime_header
= $message->header
;
790 $filename = $message->getFilename();
793 $filename = str_replace(' ', ' ', decodeHeader($filename));
794 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
795 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
796 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
798 $localfilename = GenerateRandomString(32, '', 7);
799 $full_localfilename = "$hashed_attachment_dir/$localfilename";
800 while (file_exists($full_localfilename)) {
801 $localfilename = GenerateRandomString(32, '', 7);
802 $full_localfilename = "$hashed_attachment_dir/$localfilename";
804 $message->att_local_name
= $full_localfilename;
806 $composeMessage->initAttachment($message->type0
.'/'.$message->type1
,$filename,
807 $full_localfilename);
809 /* Write Attachment to file */
810 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
811 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
812 $passed_id, $message->entity_id
),
813 $message->header
->encoding
));
817 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
818 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
821 return $composeMessage;
824 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
825 $passed_ent_id='', $imapConnection) {
826 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
827 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
828 if (!$passed_ent_id) {
829 $body_a = sqimap_run_command($imapConnection,
830 'FETCH '.$passed_id.' RFC822',
831 TRUE, $response, $readmessage,
834 $body_a = sqimap_run_command($imapConnection,
835 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
836 TRUE, $response, $readmessage, $uid_support);
837 $message = $message->parent
;
839 if ($response == 'OK') {
840 $subject = encodeHeader($message->rfc822_header
->subject
);
841 array_shift($body_a);
843 $body = implode('', $body_a) . "\r\n";
845 $localfilename = GenerateRandomString(32, 'FILE', 7);
846 $full_localfilename = "$hashed_attachment_dir/$localfilename";
848 $fp = fopen($full_localfilename, 'w');
851 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
852 $full_localfilename);
854 return $composeMessage;
857 function showInputForm ($session, $values=false) {
858 global $send_to, $send_to_cc, $body, $startMessage,
859 $passed_body, $color, $use_signature, $signature, $prefix_sig,
860 $editor_size, $attachments, $subject, $newmail,
861 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
862 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
863 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
864 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
865 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
866 $username, $compose_messages, $composesession, $default_charset;
868 $composeMessage = $compose_messages[$session];
871 $send_to = $values['send_to'];
872 $send_to_cc = $values['send_to_cc'];
873 $send_to_bcc = $values['send_to_bcc'];
874 $subject = $values['subject'];
875 $mailprio = $values['mailprio'];
876 $body = $values['body'];
877 $identity = (int) $values['identity'];
879 $send_to = decodeHeader($send_to);
880 $send_to_cc = decodeHeader($send_to_cc);
881 $send_to_bcc = decodeHeader($send_to_bcc);
884 if ($use_javascript_addr_book) {
885 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
886 'function open_abook() { ' . "\n" .
887 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
888 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
889 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
890 ' nwin.opener = document.windows;' . "\n" .
892 "// -->\n</SCRIPT>\n\n";
895 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
896 'enctype="multipart/form-data"';
897 do_hook('compose_form');
901 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
903 if ($action == 'draft') {
904 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
906 if (isset($delete_draft)) {
907 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
909 if (isset($session)) {
910 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
913 if (isset($passed_id)) {
914 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
917 if ($saved_draft == 'yes') {
918 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
920 if ($mail_sent == 'yes') {
921 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
923 echo '<table align="center" cellspacing="0" border="0">' . "\n";
924 if ($compose_new_win == '1') {
925 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
926 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
928 if ($location_of_buttons == 'top') {
929 showComposeButtonRow();
932 /* display select list for identities */
933 if (count($idents) > 1) {
934 echo ' <tr>' . "\n" .
935 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
936 _("From:") . '</td>' . "\n" .
937 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
938 ' <select name="identity">' . "\n" ;
939 foreach($idents as $id=>$data) {
940 echo '<option value="'.$id.'"';
941 if($id == $identity) {
944 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
948 echo '</select>' . "\n" .
952 echo ' <tr>' . "\n" .
953 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
954 _("To:") . '</TD>' . "\n" .
955 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
956 ' <input type="text" name="send_to" value="' .
957 $send_to . '" size="60" /><br />' . "\n" .
961 html_tag( 'td', '', 'right', $color[4] ) .
962 _("CC:") . '</td>' . "\n" .
963 html_tag( 'td', '', 'left', $color[4] ) .
964 ' <input type="text" name="send_to_cc" size="60" value="' .
965 $send_to_cc . '" /><br />' . "\n" .
969 html_tag( 'td', '', 'right', $color[4] ) .
970 _("BCC:") . '</td>' . "\n" .
971 html_tag( 'td', '', 'left', $color[4] ) .
972 ' <input type="text" name="send_to_bcc" value="' .
973 $send_to_bcc . '" size="60" /><br />' . "\n" .
977 html_tag( 'td', '', 'right', $color[4] ) .
978 _("Subject:") . '</td>' . "\n" .
979 html_tag( 'td', '', 'left', $color[4] ) . "\n";
980 echo ' <input type="text" name="subject" size="60" value="' .
981 $subject . '" />' . "\n" .
985 if ($location_of_buttons == 'between') {
986 showComposeButtonRow();
989 /* why this distinction? */
990 if ($compose_new_win == '1') {
991 echo ' <TR>' . "\n" .
992 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
993 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
994 $editor_size . '" WRAP="VIRTUAL">';
997 echo ' <TR>' . "\n" .
998 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
999 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1000 $editor_size . '" WRAP="VIRTUAL">';
1003 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1004 $signature = $idents[$identity]['signature'];
1006 if ($sig_first == '1') {
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,false);
1012 echo "\n\n".decodeHeader($body,false,false);
1015 echo "\n\n".decodeHeader($body,false,false);
1016 if ($default_charset == 'iso-2022-jp') {
1017 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1019 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1024 echo decodeHeader($body,false,false);
1026 echo '</textarea><br />' . "\n" .
1031 if ($location_of_buttons == 'bottom') {
1032 showComposeButtonRow();
1034 echo ' <tr>' . "\n" .
1035 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1036 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1037 ' <br /><br />' . "\n" .
1042 /* This code is for attachments */
1043 if ((bool) ini_get('file_uploads')) {
1045 /* Calculate the max size for an uploaded file.
1046 * This is advisory for the user because we can't actually prevent
1047 * people to upload too large files. */
1049 /* php.ini vars which influence the max for uploads */
1050 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1051 foreach($configvars as $var) {
1052 /* skip 0 or empty values */
1053 if( $size = getByteSize(ini_get($var)) ) {
1058 if(count($sizes) > 0) {
1059 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1063 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1064 echo ' <tr>' . "\n" .
1065 ' <td colspan="2">' . "\n" .
1066 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1067 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1070 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1071 ' border="0">' . "\n" .
1073 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1074 _("Attach:") . '</td>' . "\n" .
1075 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1076 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1077 ' <input type="submit" name="attach"' .
1078 ' value="' . _("Add") .'">' . "\n" .
1085 if ($composeMessage->entities
) {
1086 foreach ($composeMessage->entities
as $key => $attachment) {
1087 $attached_file = $attachment->att_local_name
;
1088 if ($attachment->att_local_name ||
$attachment->body_part
) {
1089 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1090 $type = $attachment->mime_header
->type0
.'/'.
1091 $attachment->mime_header
->type1
;
1093 $s_a[] = '<table bgcolor="'.$color[0].
1094 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1095 $key . "\"></td><td>\n" . $attached_filename .
1096 '</td><td>-</td><td> ' . $type . '</td><td>('.
1097 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1102 foreach ($s_a as $s) {
1103 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1105 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1106 _("Delete selected attachments") . "\">\n" .
1109 echo ' </table>' . "\n" .
1112 ' </TABLE>' . "\n" .
1115 } // End of file_uploads if-block
1116 /* End of attachment code */
1117 if ($compose_new_win == '1') {
1118 echo '</TABLE>'."\n";
1121 echo '</TABLE>' . "\n" .
1122 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1123 '<input type=hidden name=smaction value="' . $action . "\">\n" .
1124 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1127 store the complete ComposeMessages array in a hidden input value
1128 so we can restore them in case of a session timeout.
1130 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1131 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1132 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1133 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1135 if (!(bool) ini_get('file_uploads')) {
1136 /* File uploads are off, so we didn't show that part of the form.
1137 To avoid bogus bug reports, tell the user why. */
1138 echo 'Because PHP file uploads are turned off, you can not attach files ';
1139 echo "to this message. Please see your system administrator for details.\r\n";
1142 do_hook('compose_bottom');
1143 echo '</BODY></HTML>' . "\n";
1147 function showComposeButtonRow() {
1148 global $use_javascript_addr_book, $save_as_draft,
1149 $default_use_priority, $mailprio, $default_use_mdn,
1150 $request_mdn, $request_dr,
1151 $data_dir, $username;
1153 echo ' <TR>' . "\n" .
1154 ' <TD></TD>' . "\n" .
1156 if ($default_use_priority) {
1157 if(!isset($mailprio)) {
1160 echo ' ' . _("Priority") .': <select name="mailprio">'.
1161 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1162 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1163 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1166 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1167 if ($default_use_mdn) {
1168 if ($mdn_user_support) {
1169 echo ' ' . _("Receipt") .': '.
1170 '<input type="checkbox" name="request_mdn" value=1'.
1171 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1172 ' <input type="checkbox" name="request_dr" value=1'.
1173 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1177 echo ' </TD>' . "\n" .
1180 ' <TD></TD>' . "\n" .
1182 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1183 if ($use_javascript_addr_book) {
1184 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1185 " <input type=button value=\\\""._("Addresses").
1186 "\\\" onclick='javascript:open_abook();'>\");".
1187 " // --></SCRIPT><NOSCRIPT>\n".
1188 " <input type=submit name=\"html_addr_search\" value=\"".
1189 _("Addresses")."\">".
1192 echo ' <input type=submit name="html_addr_search" value="'.
1193 _("Addresses").'">' . "\n";
1196 if ($save_as_draft) {
1197 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1200 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1201 do_hook('compose_button_row');
1203 echo ' </TD>' . "\n" .
1207 function checkInput ($show) {
1209 * I implemented the $show variable because the error messages
1210 * were getting sent before the page header. So, I check once
1211 * using $show=false, and then when i'm ready to display the error
1212 * message, show=true
1214 global $body, $send_to, $send_to_bcc, $subject, $color;
1216 if ($send_to == '' && $send_to_bcc == '') {
1218 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1223 } /* function checkInput() */
1226 /* True if FAILURE */
1227 function saveAttachedFiles($session) {
1228 global $_FILES, $attachment_dir, $attachments, $username,
1229 $data_dir, $compose_messages;
1231 /* get out of here if no file was attached at all */
1232 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1236 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1237 $localfilename = GenerateRandomString(32, '', 7);
1238 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1239 while (file_exists($full_localfilename)) {
1240 $localfilename = GenerateRandomString(32, '', 7);
1241 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1244 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1245 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1246 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1247 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1251 $message = $compose_messages[$session];
1252 $type = strtolower($_FILES['attachfile']['type']);
1253 $name = $_FILES['attachfile']['name'];
1254 $message->initAttachment($type, $name, $full_localfilename);
1255 $compose_messages[$session] = $message;
1256 sqsession_register($compose_messages , 'compose_messages');
1259 function ClearAttachments($composeMessage) {
1260 if ($composeMessage->att_local_name
) {
1261 $attached_file = $composeMessage->att_local_name
;
1262 if (file_exists($attached_file)) {
1263 unlink($attached_file);
1266 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1267 ClearAttachments($composeMessage->entities
[$i]);
1271 /* parse values like 8M and 2k into bytes */
1272 function getByteSize($ini_size) {
1278 $ini_size = trim($ini_size);
1280 // if there's some kind of letter at the end of the string we need to multiply.
1281 if(!is_numeric(substr($ini_size, -1))) {
1283 switch(strtoupper(substr($ini_size, -1))) {
1285 $bytesize = 1073741824;
1288 $bytesize = 1048576;
1295 return ($bytesize * (int)substr($ini_size, 0, -1));
1302 /* temporary function to make use of the deliver class.
1303 In the future the responsable backend should be automaticly loaded
1304 and conf.pl should show a list of available backends.
1305 The message also should be constructed by the message class.
1308 function deliverMessage($composeMessage, $draft=false) {
1309 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1310 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1311 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1312 $domain, $action, $default_move_to_sent, $move_to_sent;
1313 global $imapServerAddress, $imapPort, $sent_folder, $key;
1315 /* some browsers replace <space> by nonbreaking spaces
1316 by replacing them back to spaces addressparsing works */
1317 /* FIXME: How to handle in case of other charsets where "\240"
1318 is not a non breaking space ??? */
1320 $send_to = str_replace("\240",' ',$send_to);
1321 $send_to_cc = str_replace("\240",' ',$send_to_cc);
1322 $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1324 $rfc822_header = $composeMessage->rfc822_header
;
1326 $abook = addressbook_init(false, true);
1327 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1328 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1329 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1330 $rfc822_header->priority
= $mailprio;
1331 $rfc822_header->subject
= $subject;
1332 $special_encoding='';
1333 if (strtolower($default_charset) == 'iso-2022-jp') {
1334 if (mb_detect_encoding($body) == 'ASCII') {
1335 $special_encoding = '8bit';
1337 $body = mb_convert_encoding($body, 'JIS');
1338 $special_encoding = '7bit';
1341 $composeMessage->setBody($body);
1343 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1344 $popuser = $usernamedata[1];
1345 $domain = $usernamedata[2];
1346 unset($usernamedata);
1348 $popuser = $username;
1351 $from_mail = $idents[$identity]['email_address'];
1352 $full_name = $idents[$identity]['full_name'];
1353 $reply_to = $idents[$identity]['reply_to'];
1355 $from_mail = "$popuser@$domain";
1357 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1359 $from = $rfc822_header->from
[0];
1360 if (!$from->host
) $from->host
= $domain;
1361 $full_name_encoded = encodeHeader($full_name);
1362 if ($full_name_encoded != $full_name) {
1363 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1365 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1367 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1370 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1372 /* Receipt: On Read */
1373 if (isset($request_mdn) && $request_mdn) {
1374 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1376 /* Receipt: On Delivery */
1377 if (isset($request_dr) && $request_dr) {
1378 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1380 /* multipart messages */
1381 if (count($composeMessage->entities
)) {
1382 $message_body = new Message();
1383 $message_body->body_part
= $composeMessage->body_part
;
1384 $composeMessage->body_part
= '';
1385 $mime_header = new MessageHeader
;
1386 $mime_header->type0
= 'text';
1387 $mime_header->type1
= 'plain';
1388 if ($special_encoding) {
1389 $mime_header->encoding
= $special_encoding;
1391 $mime_header->encoding
= '8bit';
1393 if ($default_charset) {
1394 $mime_header->parameters
['charset'] = $default_charset;
1396 $message_body->mime_header
= $mime_header;
1397 array_unshift($composeMessage->entities
, $message_body);
1398 $content_type = new ContentType('multipart/mixed');
1400 $content_type = new ContentType('text/plain');
1401 if ($special_encoding) {
1402 $rfc822_header->encoding
= $special_encoding;
1404 $rfc822_header->encoding
= '8bit';
1406 if ($default_charset) {
1407 $content_type->properties
['charset']=$default_charset;
1411 $rfc822_header->content_type
= $content_type;
1412 $composeMessage->rfc822_header
= $rfc822_header;
1414 /* Here you can modify the message structure just before we hand
1415 it over to deliver */
1416 $hookReturn = do_hook('compose_send', $composeMessage);
1417 /* Get any changes made by plugins to $composeMessage. */
1418 if ( is_object($hookReturn[1]) ) {
1419 $composeMessage = $hookReturn[1];
1422 if (!$useSendmail && !$draft) {
1423 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1424 $deliver = new Deliver_SMTP();
1425 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1427 if ($smtp_auth_mech == 'none') {
1431 global $key, $onetimepad;
1433 $pass = OneTimePadDecrypt($key, $onetimepad);
1436 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1437 $stream = $deliver->initStream($composeMessage,$domain,0,
1438 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1439 } elseif (!$draft) {
1440 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1441 global $sendmail_path;
1442 $deliver = new Deliver_SendMail();
1443 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1445 global $draft_folder;
1446 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1447 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1449 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1450 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1451 $imap_deliver = new Deliver_IMAP();
1452 $length = $imap_deliver->mail($composeMessage);
1453 sqimap_append ($imap_stream, $draft_folder, $length);
1454 $imap_deliver->mail($composeMessage, $imap_stream);
1455 sqimap_append_done ($imap_stream, $draft_folder);
1456 sqimap_logout($imap_stream);
1457 unset ($imap_deliver);
1460 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1461 plain_error_message($msg, $color);
1467 $length = $deliver->mail($composeMessage, $stream);
1468 $succes = $deliver->finalizeStream($stream);
1471 $msg = $deliver->dlv_msg
. '<br>' .
1472 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1473 $deliver->dlv_server_msg
;
1474 plain_error_message($msg, $color);
1477 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1478 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1480 /* Move to sent code */
1481 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1482 $svr_allow_sent = true;
1484 $svr_allow_sent = false;
1487 if (isset($sent_folder) && (($sent_folder != '') ||
($sent_folder != 'none'))
1488 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1494 if ((isset($move_to_sent) && ($move_to_sent != 0)) ||
(!isset($move_to_sent))) {
1495 $lcl_allow_sent = true;
1497 $lcl_allow_sent = false;
1500 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) ||
($fld_sent && $lcl_allow_sent)) {
1501 sqimap_append ($imap_stream, $sent_folder, $length);
1502 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1503 $imap_deliver = new Deliver_IMAP();
1504 $imap_deliver->mail($composeMessage, $imap_stream);
1505 sqimap_append_done ($imap_stream, $sent_folder);
1506 unset ($imap_deliver);
1508 global $passed_id, $mailbox, $action;
1509 ClearAttachments($composeMessage);
1510 if ($action == 'reply' ||
$action == 'reply_all') {
1511 sqimap_mailbox_select ($imap_stream, $mailbox);
1512 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1514 sqimap_logout($imap_stream);