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 /* Location (For HTTP 1.1 Header("Location: ...") redirects) */
91 $location = get_location();
93 /* --------------------- Specific Functions ------------------------------ */
95 function replyAllString($header) {
96 global $include_self_reply_all, $username, $data_dir;
99 * 1) Remove the addresses we'll be sending the message 'to'
101 $url_replytoall_avoid_addrs = '';
102 if (isset($header->replyto
)) {
103 $excl_ar = $header->getAddr_a('replyto');
106 * 2) Remove our identities from the CC list (they still can be in the
107 * TO list) only if $include_self_reply_all is turned off
109 if (!$include_self_reply_all) {
110 $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address')));
111 $excl_ar[$email_address] = '';
112 $idents = getPref($data_dir, $username, 'identities');
113 if ($idents != '' && $idents > 1) {
115 for ($i = 1; $i < $idents; $i ++
) {
116 $cur_email_address = getPref($data_dir, $username,
117 'email_address' . $i);
118 $cur_email_address = strtolower(trim($cur_email_address));
119 $excl_ar[$cur_email_address] = '';
125 * 3) get the addresses.
127 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
130 * 4) generate the string.
132 $url_replytoallcc = '';
133 foreach( $url_replytoall_ar as $email => $personal) {
135 $url_replytoallcc .= ", $personal <$email>";
137 $url_replytoallcc .= ', '. $email;
140 $url_replytoallcc = substr($url_replytoallcc,2);
142 return $url_replytoallcc;
145 function getReplyCitation($orig_from) {
146 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
147 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
148 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
149 /* First, return an empty string when no citation style selected. */
150 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
154 /* Make sure our final value isn't an empty string. */
155 if ($orig_from == '') {
159 /* Otherwise, try to select the desired citation style. */
160 switch ($reply_citation_style) {
163 $end = ' ' . _("said") . ':';
166 $start = '<' . _("quote") . ' ' . _("who") . '="';
170 $start = $reply_citation_start .
171 ($reply_citation_start == '' ?
'' : ' ');
172 $end = $reply_citation_end;
178 /* Build and return the citation string. */
179 return ($start . $orig_from . $end . "\n");
182 function getforwardHeader($orig_header) {
185 $display = array( _("Subject") => strlen(_("Subject")),
186 _("From") => strlen(_("From")),
187 _("Date") => strlen(_("Date")),
188 _("To") => strlen(_("To")),
189 _("Cc") => strlen(_("Cc")) );
190 $maxsize = max($display);
191 $indent = str_pad('',$maxsize+
2);
192 foreach($display as $key => $val) {
193 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
195 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
196 $from = str_replace(' ',' ',$from);
197 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
198 $to = str_replace(' ',' ',$to);
199 $subject = decodeHeader($orig_header->subject
,false,false);
200 $subject = str_replace(' ',' ',$subject);
201 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
202 "\n". $display[_("Subject")] . $subject . "\n" .
203 $display[_("From")] . $from . "\n" .
204 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
205 $display[_("To")] . $to . "\n";
206 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
207 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
208 $cc = str_replace(' ',' ',$cc);
209 $bodyTop .= $display[_("Cc")] .$cc . "\n";
211 $bodyTop .= str_pad('', $editor_size -2 , '-') .
215 /* ----------------------------------------------------------------------- */
218 * If the session is expired during a post this restores the compose session
221 if (sqsession_is_registered('session_expired_post')) {
222 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
224 * extra check for username so we don't display previous post data from
225 * another user during this session.
227 if ($session_expired_post['username'] != $username) {
228 unset($session_expired_post);
229 sqsession_unregister('session_expired_post');
230 session_write_close();
232 foreach ($session_expired_post as $postvar => $val) {
239 $compose_messages = unserialize(urldecode($restoremessages));
240 sqsession_register($compose_messages,'compose_messages');
241 sqsession_register($composesession,'composesession');
245 $session_expired = true;
247 unset($session_expired_post);
248 sqsession_unregister('session_expired_post');
249 session_write_close();
250 if (!isset($mailbox)) {
253 if ($compose_new_win == '1') {
254 compose_Header($color, $mailbox);
256 displayPageHeader($color, $mailbox);
258 showInputForm($session, false);
261 if (!isset($composesession)) {
263 sqsession_register(0,'composesession');
266 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
267 sqsession_unregister('composesession');
268 $session = "$composesession" +
1;
269 $composesession = $session;
270 sqsession_register($composesession,'composesession');
272 if (!isset($compose_messages)) {
273 $compose_messages = array();
275 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
276 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
277 $composeMessage = new Message();
278 $rfc822_header = new Rfc822Header();
279 $composeMessage->rfc822_header
= $rfc822_header;
280 $composeMessage->reply_rfc822_header
= '';
281 $compose_messages[$session] = $composeMessage;
282 sqsession_register($compose_messages,'compose_messages');
284 $composeMessage=$compose_messages[$session];
287 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
293 * Set $default_charset to correspond with the user's selection
294 * of language interface.
297 $composeMessage=$compose_messages[$session];
298 if (! deliverMessage($composeMessage, true)) {
299 showInputForm($session);
302 unset($compose_messages[$session]);
303 $draft_message = _("Draft Email Saved");
304 /* If this is a resumed draft, then delete the original */
305 if(isset($delete_draft)) {
306 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
307 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
311 if ($compose_new_win == '1') {
312 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
316 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
317 "&startMessage=1¬e=".urlencode($draft_message));
325 if (isset($_FILES['attachfile']) &&
326 $_FILES['attachfile']['tmp_name'] &&
327 $_FILES['attachfile']['tmp_name'] != 'none') {
328 $AttachFailure = saveAttachedFiles($session);
330 if (checkInput(false) && !isset($AttachFailure)) {
331 if ($mailbox == "All Folders") {
332 /* We entered compose via the search results page */
333 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
335 $urlMailbox = urlencode (trim($mailbox));
336 if (! isset($passed_id)) {
340 * Set $default_charset to correspond with the user's selection
341 * of language interface.
345 * This is to change all newlines to \n
346 * We'll change them to \r\n later (in the sendMessage function)
348 $body = str_replace("\r\n", "\n", $body);
349 $body = str_replace("\r", "\n", $body);
352 * Rewrap $body so that no line is bigger than $editor_size
353 * This should only really kick in the sqWordWrap function
354 * if the browser doesn't support "VIRTUAL" as the wrap type.
356 $body = explode("\n", $body);
358 foreach ($body as $line) {
359 if( $line <> '-- ' ) {
360 $line = rtrim($line);
362 if (strlen($line) <= $editor_size +
1) {
363 $newBody .= $line . "\n";
365 sqWordWrap($line, $editor_size);
366 $newBody .= $line . "\n";
373 $composeMessage=$compose_messages[$session];
375 $Result = deliverMessage($composeMessage);
377 showInputForm($session);
380 unset($compose_messages[$session]);
381 if ( isset($delete_draft)) {
382 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
383 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
386 if ($compose_new_win == '1') {
388 Header("Location: $location/compose.php?mail_sent=yes");
391 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
395 if ($compose_new_win == '1') {
396 compose_Header($color, $mailbox);
399 displayPageHeader($color, $mailbox);
401 if (isset($AttachFailure)) {
402 plain_error_message(_("Could not move/copy file. File not attached"),
406 showInputForm($session);
407 /* sqimap_logout($imapConnection); */
409 } elseif (isset($html_addr_search_done)) {
410 if ($compose_new_win == '1') {
411 compose_Header($color, $mailbox);
414 displayPageHeader($color, $mailbox);
417 if (isset($send_to_search) && is_array($send_to_search)) {
418 foreach ($send_to_search as $k => $v) {
419 if (substr($k, 0, 1) == 'T') {
425 elseif (substr($k, 0, 1) == 'C') {
431 elseif (substr($k, 0, 1) == 'B') {
433 $send_to_bcc .= ', ';
439 showInputForm($session);
440 } elseif (isset($html_addr_search)) {
441 if (isset($_FILES['attachfile']) &&
442 $_FILES['attachfile']['tmp_name'] &&
443 $_FILES['attachfile']['tmp_name'] != 'none') {
444 if(saveAttachedFiles($session)) {
445 plain_error_message(_("Could not move/copy file. File not attached"), $color);
449 * I am using an include so as to elminiate an extra unnecessary
450 * click. If you can think of a better way, please implement it.
452 include_once('./addrbook_search_html.php');
453 } elseif (isset($attach)) {
454 if (saveAttachedFiles($session)) {
455 plain_error_message(_("Could not move/copy file. File not attached"), $color);
457 if ($compose_new_win == '1') {
458 compose_Header($color, $mailbox);
461 displayPageHeader($color, $mailbox);
463 showInputForm($session);
465 elseif (isset($sigappend)) {
466 $idents = getPref($data_dir, $username, 'identities', 0);
468 if ($identity == 'default') {
473 $signature = getSig($data_dir, $username, $no);
475 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
476 if ($compose_new_win == '1') {
477 compose_Header($color, $mailbox);
479 displayPageHeader($color, $mailbox);
481 showInputForm($session);
482 } elseif (isset($do_delete)) {
483 if ($compose_new_win == '1') {
484 compose_Header($color, $mailbox);
487 displayPageHeader($color, $mailbox);
490 if (isset($delete) && is_array($delete)) {
491 $composeMessage = $compose_messages[$session];
492 foreach($delete as $index) {
493 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
494 unlink ($attached_file);
495 unset ($composeMessage->entities
[$index]);
497 $new_entities = array();
498 foreach ($composeMessage->entities
as $entity) {
499 $new_entities[] = $entity;
501 $composeMessage->entities
= $new_entities;
502 $compose_messages[$session] = $composeMessage;
503 sqsession_register($compose_messages, 'compose_messages');
505 showInputForm($session);
508 * This handles the default case as well as the error case
509 * (they had the same code) --> if (isset($smtpErrors))
512 if ($compose_new_win == '1') {
513 compose_Header($color, $mailbox);
515 displayPageHeader($color, $mailbox);
520 if (!isset($passed_ent_id)) {
523 if (!isset($passed_id)) {
526 if (!isset($mailbox)) {
529 if (!isset($action)) {
533 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
535 /* in case the origin is not read_body.php */
536 if (isset($send_to)) {
537 $values['send_to'] = $send_to;
539 if (isset($send_to_cc)) {
540 $values['send_to_cc'] = $send_to_cc;
542 if (isset($send_to_bcc)) {
543 $values['send_to_bcc'] = $send_to_bcc;
545 if (isset($subject)) {
546 $values['subject'] = $subject;
548 showInputForm($session, $values);
553 /**************** Only function definitions go below *************/
556 /* This function is used when not sending or adding attachments */
557 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
558 global $editor_size, $default_use_priority, $body,
559 $use_signature, $composesession, $data_dir, $username,
560 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
562 global $languages, $squirrelmail_language;
564 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
568 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
571 sqimap_mailbox_select($imapConnection, $mailbox);
572 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
575 if ($passed_ent_id) {
576 /* redefine the messsage in case of message/rfc822 */
577 $message = $message->getEntity($passed_ent_id);
578 /* message is an entity which contains the envelope and type0=message
579 * and type1=rfc822. The actual entities are childs from
580 * $message->entities[0]. That's where the encoding and is located
583 $entities = $message->entities
[0]->findDisplayEntity
584 (array(), $alt_order = array('text/plain'));
585 if (!count($entities)) {
586 $entities = $message->entities
[0]->findDisplayEntity
587 (array(), $alt_order = array('text/plain','html/plain'));
589 $orig_header = $message->rfc822_header
; /* here is the envelope located */
590 /* redefine the message for picking up the attachments */
591 $message = $message->entities
[0];
594 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
595 if (!count($entities)) {
596 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
598 $orig_header = $message->rfc822_header
;
601 $encoding = $message->header
->encoding
;
602 $type0 = $message->type0
;
603 $type1 = $message->type1
;
604 foreach ($entities as $ent) {
605 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
606 $body_part_entity = $message->getEntity($ent);
607 $bodypart = decodeBody($unencoded_bodypart,
608 $body_part_entity->header
->encoding
);
609 if ($type1 == 'html') {
610 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
611 $bodypart = strip_tags($bodypart);
613 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
614 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
615 if (mb_detect_encoding($bodypart) != 'ASCII') {
616 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
621 if ($default_use_priority) {
622 $mailprio = substr($orig_header->priority
,0,1);
629 //ClearAttachments($session);
632 $idents = getPref($data_dir, $username, 'identities');
633 $from_o = $orig_header->from
;
634 if (is_object($from_o)) {
635 $orig_from = $from_o->getAddress();
639 $identities = array();
640 if (!empty($idents) && $idents > 1) {
641 $identities[] = '"'. getPref($data_dir, $username, 'full_name')
642 . '" <' . getPref($data_dir, $username, 'email_address') . '>';
643 for ($i = 1; $i < $idents; $i++
) {
644 $enc_from_name = '"'.
645 getPref($data_dir, $username, 'full_name' . $i) .
647 getPref($data_dir, $username, 'email_address' . $i) . '>';
648 if ($enc_from_name == $orig_from && $i) {
652 $identities[] = $enc_from_name;
654 $identity_match = $orig_header->findAddress($identities);
655 if ($identity_match) {
656 $identity = $identity_match;
662 $use_signature = FALSE;
663 $composeMessage->rfc822_header
= $orig_header;
664 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
665 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
666 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
667 $subject = decodeHeader($orig_header->subject
,false,true);
668 // /* remember the references and in-reply-to headers in case of an reply */
669 // $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
670 // $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
671 $body_ary = explode("\n", $body);
672 $cnt = count($body_ary) ;
674 for ($i=0; $i < $cnt; $i++
) {
675 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
676 sqWordWrap($body_ary[$i], $editor_size );
677 $body .= $body_ary[$i] . "\n";
679 unset($body_ary[$i]);
682 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
684 case ('edit_as_new'):
685 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
686 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
687 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
688 $subject = decodeHeader($orig_header->subject
,false,true);
689 $mailprio = $orig_header->priority
;
691 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
696 $subject = decodeHeader($orig_header->subject
,false,true);
697 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
698 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
699 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
700 $subject = '[Fwd: ' . $subject . ']';
702 $body = getforwardHeader($orig_header) . $body;
704 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
705 $body = "\n" . $body;
707 case ('forward_as_attachment'):
708 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
712 $send_to_cc = replyAllString($orig_header);
713 $send_to_cc = decodeHeader($send_to_cc,false,true);
715 $send_to = $orig_header->reply_to
;
716 if (is_array($send_to) && count($send_to)) {
717 $send_to = $orig_header->getAddr_s('reply_to');
718 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
719 $send_to = $orig_header->getAddr_s('reply_to');
721 $send_to = $orig_header->getAddr_s('from');
723 $send_to = decodeHeader($send_to,false,true);
724 $subject = decodeHeader($orig_header->subject
,false,true);
725 $subject = str_replace('"', "'", $subject);
726 $subject = trim($subject);
727 if (substr(strtolower($subject), 0, 3) != 're:') {
728 $subject = 'Re: ' . $subject;
730 /* this corrects some wrapping/quoting problems on replies */
731 $rewrap_body = explode("\n", $body);
732 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
735 $cnt = count($rewrap_body);
736 for ($i=0;$i<$cnt;$i++
) {
737 sqWordWrap($rewrap_body[$i], ($editor_size));
738 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
740 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
742 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
744 unset($rewrap_body[$i]);
746 $body = getReplyCitation($from) . $body;
747 $composeMessage->reply_rfc822_header
= $orig_header;
753 $compose_messages[$session] = $composeMessage;
754 sqsession_register($compose_messages, 'compose_messages');
755 session_write_close();
756 sqimap_logout($imapConnection);
758 $ret = array( 'send_to' => $send_to,
759 'send_to_cc' => $send_to_cc,
760 'send_to_bcc' => $send_to_bcc,
761 'subject' => $subject,
762 'mailprio' => $mailprio,
764 'identity' => $identity );
767 } /* function newMail() */
769 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
770 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
771 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
772 if (!count($message->entities
) ||
773 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
774 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
775 switch ($message->type0
) {
777 if ($message->type1
== 'rfc822') {
778 $filename = $message->rfc822_header
->subject
.'.eml';
779 if ($filename == "") {
780 $filename = "untitled-".$message->entity_id
.'.eml';
783 $filename = $message->getFilename();
787 $filename = $message->getFilename();
790 $filename = decodeHeader($filename);
791 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
792 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
793 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
795 $localfilename = GenerateRandomString(32, '', 7);
796 $full_localfilename = "$hashed_attachment_dir/$localfilename";
797 while (file_exists($full_localfilename)) {
798 $localfilename = GenerateRandomString(32, '', 7);
799 $full_localfilename = "$hashed_attachment_dir/$localfilename";
801 $message->att_local_name
= $full_localfilename;
802 if (!$message->mime_header
) { /* temporary hack */
803 $message->mime_header
= $message->header
;
806 $composeMessage->addEntity($message);
808 /* Write Attachment to file */
809 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
810 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
811 $passed_id, $message->entity_id
),
812 $message->header
->encoding
));
816 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
817 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
820 return $composeMessage;
823 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
824 $passed_ent_id='', $imapConnection) {
825 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
826 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
827 if (!$passed_ent_id) {
828 $body_a = sqimap_run_command($imapConnection,
829 'FETCH '.$passed_id.' RFC822',
830 TRUE, $response, $readmessage,
833 $body_a = sqimap_run_command($imapConnection,
834 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
835 TRUE, $response, $readmessage, $uid_support);
836 $message = $message->parent
;
838 if ($response == 'OK') {
839 $subject = encodeHeader($message->rfc822_header
->subject
);
840 array_shift($body_a);
841 $body = implode('', $body_a) . "\r\n";
843 $localfilename = GenerateRandomString(32, 'FILE', 7);
844 $full_localfilename = "$hashed_attachment_dir/$localfilename";
846 $fp = fopen( $full_localfilename, 'w');
849 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
850 $full_localfilename);
852 return $composeMessage;
855 function showInputForm ($session, $values=false) {
856 global $send_to, $send_to_cc, $body,
857 $passed_body, $color, $use_signature, $signature, $prefix_sig,
858 $editor_size, $attachments, $subject, $newmail,
859 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
860 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
861 $username, $data_dir, $identity, $draft_id, $delete_draft,
862 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
863 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
864 $username, $compose_messages, $composesession, $default_charset;
866 $composeMessage = $compose_messages[$session];
869 $send_to = $values['send_to'];
870 $send_to_cc = $values['send_to_cc'];
871 $send_to_bcc = $values['send_to_bcc'];
872 $subject = $values['subject'];
873 $mailprio = $values['mailprio'];
874 $body = $values['body'];
875 $identity = (int) $values['identity'];
877 $send_to = decodeHeader($send_to);
878 $send_to_cc = decodeHeader($send_to_cc);
879 $send_to_bcc = decodeHeader($send_to_bcc);
882 if ($use_javascript_addr_book) {
883 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
884 'function open_abook() { ' . "\n" .
885 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
886 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
887 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
888 ' nwin.opener = document.windows;' . "\n" .
890 '// --></SCRIPT>' . "\n\n";
893 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
894 'ENCTYPE="multipart/form-data"';
895 do_hook("compose_form");
899 if ($action == 'draft') {
900 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
902 if (isset($delete_draft)) {
903 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
905 if (isset($session)) {
906 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
909 if (isset($passed_id)) {
910 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
913 if ($saved_draft == 'yes') {
914 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
916 if ($mail_sent == 'yes') {
917 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
919 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
920 if ($compose_new_win == '1') {
921 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
922 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
924 if ($location_of_buttons == 'top') {
925 showComposeButtonRow();
928 /* display select list for identities */
929 $idents = getPref($data_dir, $username, 'identities', 0);
931 $fn = getPref($data_dir, $username, 'full_name');
932 $em = getPref($data_dir, $username, 'email_address');
933 echo ' <tr>' . "\n" .
934 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
935 _("From:") . '</td>' . "\n" .
936 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
937 ' <select name="identity">' . "\n" .
938 ' <option value="default">' .
939 htmlspecialchars($fn);
942 echo htmlspecialchars(' <' . $em . '>') . "\n";
944 echo htmlspecialchars($em) . "\n";
948 for ($i = 1; $i < $idents; $i ++
) {
949 $fn = getPref($data_dir, $username, 'full_name' . $i);
950 $em = getPref($data_dir, $username, 'email_address' . $i);
952 echo '<option value="' . $i . '"';
953 if (isset($identity) && $identity == $i) {
956 echo '>' . htmlspecialchars($fn);
959 echo htmlspecialchars(' <' . $em . '>') . "\n";
961 echo htmlspecialchars($em) . "\n";
966 echo '</select>' . "\n" .
970 echo ' <tr>' . "\n" .
971 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
972 _("To:") . '</TD>' . "\n" .
973 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
974 ' <input type="text" name="send_to" value="' .
975 $send_to . '" size="60" /><br />' . "\n" .
979 html_tag( 'td', '', 'right', $color[4] ) .
980 _("CC:") . '</td>' . "\n" .
981 html_tag( 'td', '', 'left', $color[4] ) .
982 ' <input type="text" name="send_to_cc" size="60" value="' .
983 $send_to_cc . '" /><br />' . "\n" .
987 html_tag( 'td', '', 'right', $color[4] ) .
988 _("BCC:") . '</td>' . "\n" .
989 html_tag( 'td', '', 'left', $color[4] ) .
990 ' <input type="text" name="send_to_bcc" value="' .
991 $send_to_bcc . '" size="60" /><br />' . "\n" .
995 html_tag( 'td', '', 'right', $color[4] ) .
996 _("Subject:") . '</td>' . "\n" .
997 html_tag( 'td', '', 'left', $color[4] ) . "\n";
998 echo ' <input type="text" name="subject" size="60" value="' .
999 $subject . '" />' . "\n" .
1003 if ($location_of_buttons == 'between') {
1004 showComposeButtonRow();
1007 /* why this distinction? */
1008 if ($compose_new_win == '1') {
1009 echo ' <TR>' . "\n" .
1010 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1011 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1012 $editor_size . '" WRAP="VIRTUAL">';
1015 echo ' <TR>' . "\n" .
1016 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1017 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1018 $editor_size . '" WRAP="VIRTUAL">';
1021 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1023 if ($identity == 'default') {
1028 $signature = getSig($data_dir, $username, $no);
1031 if ($sig_first == '1') {
1032 if ($default_charset == 'iso-2022-jp') {
1033 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1035 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1037 echo "\n\n".decodeHeader($body,false,false);
1040 echo "\n\n".decodeHeader($body,false,false);
1041 if ($default_charset == 'iso-2022-jp') {
1042 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1044 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,false);
1049 echo decodeHeader($body,false,false);
1051 echo '</textarea><br />' . "\n" .
1056 if ($location_of_buttons == 'bottom') {
1057 showComposeButtonRow();
1059 echo ' <tr>' . "\n" .
1060 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1061 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1062 ' <br /><br />' . "\n" .
1067 /* This code is for attachments */
1068 if ((bool) ini_get('file_uploads')) {
1070 /* Calculate the max size for an uploaded file.
1071 * This is advisory for the user because we can't actually prevent
1072 * people to upload too large files. */
1074 /* php.ini vars which influence the max for uploads */
1075 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1076 foreach($configvars as $var) {
1077 /* skip 0 or empty values */
1078 if( $size = getByteSize(ini_get($var)) ) {
1083 if(count($sizes) > 0) {
1084 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1089 echo ' <tr>' . "\n" .
1090 ' <td colspan="2">' . "\n" .
1091 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1092 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1095 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1096 ' border="0">' . "\n" .
1098 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1099 _("Attach:") . '</td>' . "\n" .
1100 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1101 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1102 ' <input type="submit" name="attach"' .
1103 ' value="' . _("Add") .'">' . "\n" .
1110 if ($composeMessage->entities
) {
1111 foreach ($composeMessage->entities
as $key => $attachment) {
1112 $attached_file = $attachment->att_local_name
;
1113 if ($attachment->att_local_name ||
$attachment->body_part
) {
1114 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1115 $type = $attachment->mime_header
->type0
.'/'.
1116 $attachment->mime_header
->type1
;
1118 $s_a[] = '<table bgcolor="'.$color[0].
1119 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1120 $key . "\"></td><td>\n" . $attached_filename .
1121 '</td><td>-</td><td> ' . $type . '</td><td>('.
1122 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1127 foreach ($s_a as $s) {
1128 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1130 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1131 _("Delete selected attachments") . "\">\n" .
1134 echo ' </table>' . "\n" .
1137 ' </TABLE>' . "\n" .
1140 } // End of file_uploads if-block
1141 /* End of attachment code */
1142 if ($compose_new_win == '1') {
1143 echo '</TABLE>'."\n";
1146 echo '</TABLE>' . "\n" .
1147 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1148 '<input type=hidden name=action value="' . $action . "\">\n" .
1149 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1152 store the complete ComposeMessages array in a hidden input value
1153 so we can restore them in case of a session timeout.
1155 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1156 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1157 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1158 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1160 if (!(bool) ini_get('file_uploads')) {
1161 /* File uploads are off, so we didn't show that part of the form.
1162 To avoid bogus bug reports, tell the user why. */
1163 echo 'Because PHP file uploads are turned off, you can not attach files ';
1164 echo "to this message. Please see your system administrator for details.\r\n";
1167 do_hook('compose_bottom');
1168 echo '</BODY></HTML>' . "\n";
1172 function showComposeButtonRow() {
1173 global $use_javascript_addr_book, $save_as_draft,
1174 $default_use_priority, $mailprio, $default_use_mdn,
1175 $request_mdn, $request_dr,
1176 $data_dir, $username;
1178 echo ' <TR>' . "\n" .
1179 ' <TD></TD>' . "\n" .
1181 if ($default_use_priority) {
1182 if(!isset($mailprio)) {
1185 echo ' ' . _("Priority") .': <select name="mailprio">'.
1186 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1187 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1188 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1191 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1192 if ($default_use_mdn) {
1193 if ($mdn_user_support) {
1194 echo ' ' . _("Receipt") .': '.
1195 '<input type="checkbox" name="request_mdn" value=1'.
1196 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1197 ' <input type="checkbox" name="request_dr" value=1'.
1198 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1202 echo ' </TD>' . "\n" .
1205 ' <TD></TD>' . "\n" .
1207 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1208 if ($use_javascript_addr_book) {
1209 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1210 " <input type=button value=\\\""._("Addresses").
1211 "\\\" onclick='javascript:open_abook();'>\");".
1212 " // --></SCRIPT><NOSCRIPT>\n".
1213 " <input type=submit name=\"html_addr_search\" value=\"".
1214 _("Addresses")."\">".
1217 echo ' <input type=submit name="html_addr_search" value="'.
1218 _("Addresses").'">' . "\n";
1221 if ($save_as_draft) {
1222 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1225 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1226 do_hook('compose_button_row');
1228 echo ' </TD>' . "\n" .
1232 function checkInput ($show) {
1234 * I implemented the $show variable because the error messages
1235 * were getting sent before the page header. So, I check once
1236 * using $show=false, and then when i'm ready to display the error
1237 * message, show=true
1239 global $body, $send_to, $send_to_bcc, $subject, $color;
1241 if ($send_to == '' && $send_to_bcc == '') {
1243 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1248 } /* function checkInput() */
1251 /* True if FAILURE */
1252 function saveAttachedFiles($session) {
1253 global $_FILES, $attachment_dir, $attachments, $username,
1254 $data_dir, $compose_messages;
1256 /* get out of here if no file was attached at all */
1257 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1261 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1262 $localfilename = GenerateRandomString(32, '', 7);
1263 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1264 while (file_exists($full_localfilename)) {
1265 $localfilename = GenerateRandomString(32, '', 7);
1266 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1269 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1270 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1271 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1272 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1276 $message = $compose_messages[$session];
1277 $type = strtolower($_FILES['attachfile']['type']);
1278 $name = $_FILES['attachfile']['name'];
1279 $message->initAttachment($type, $name, $full_localfilename);
1280 $compose_messages[$session] = $message;
1281 sqsession_register($compose_messages , 'compose_messages');
1284 function ClearAttachments($composeMessage) {
1285 if ($composeMessage->att_local_name
) {
1286 $attached_file = $composeMessage->att_local_name
;
1287 if (file_exists($attached_file)) {
1288 unlink($attached_file);
1291 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1292 ClearAttachments($composeMessage->entities
[$i]);
1296 /* parse values like 8M and 2k into bytes */
1297 function getByteSize($ini_size) {
1303 $ini_size = trim($ini_size);
1305 // if there's some kind of letter at the end of the string we need to multiply.
1306 if(!is_numeric(substr($ini_size, -1))) {
1308 switch(strtoupper(substr($ini_size, -1))) {
1310 $bytesize = 1073741824;
1313 $bytesize = 1048576;
1320 return ($bytesize * (int)substr($ini_size, 0, -1));
1327 /* temporary function to make use of the deliver class.
1328 In the future the responsable backend should be automaticly loaded
1329 and conf.pl should show a list of available backends.
1330 The message also should be constructed by the message class.
1333 function deliverMessage($composeMessage, $draft=false) {
1334 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1335 $username, $popuser, $usernamedata, $identity, $data_dir,
1336 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1337 $domain, $action, $default_move_to_sent, $move_to_sent;
1338 global $imapServerAddress, $imapPort, $sent_folder, $key;
1340 $rfc822_header = $composeMessage->rfc822_header
;
1342 $abook = addressbook_init(false, true);
1343 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1344 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1345 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1346 $rfc822_header->priority
= $mailprio;
1347 $rfc822_header->subject
= $subject;
1348 $special_encoding='';
1349 if (strtolower($default_charset) == 'iso-2022-jp') {
1350 if (mb_detect_encoding($body) == 'ASCII') {
1351 $special_encoding = '8bit';
1353 $body = mb_convert_encoding($body, 'JIS');
1354 $special_encoding = '7bit';
1357 $composeMessage->setBody($body);
1359 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1360 $popuser = $usernamedata[1];
1361 $domain = $usernamedata[2];
1362 unset($usernamedata);
1364 $popuser = $username;
1367 if (isset($identity) && $identity != 'default') {
1368 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1369 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1370 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1372 $from_mail = getPref($data_dir, $username, 'email_address');
1373 $full_name = getPref($data_dir, $username, 'full_name');
1374 $reply_to = getPref($data_dir, $username,'reply_to');
1377 $from_mail = "$popuser@$domain";
1379 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1381 $from = $rfc822_header->from
[0];
1382 if (!$from->host
) $from->host
= $domain;
1383 $full_name_encoded = encodeHeader($full_name);
1384 if ($full_name_encoded != $full_name) {
1385 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1387 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1389 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1392 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1394 /* Receipt: On Read */
1395 if (isset($request_mdn) && $request_mdn) {
1396 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1398 /* Receipt: On Delivery */
1399 if (isset($request_dr) && $request_dr) {
1400 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1402 /* multipart messages */
1403 if (count($composeMessage->entities
)) {
1404 $message_body = new Message();
1405 $message_body->body_part
= $composeMessage->body_part
;
1406 $composeMessage->body_part
= '';
1407 $mime_header = new MessageHeader
;
1408 $mime_header->type0
= 'text';
1409 $mime_header->type1
= 'plain';
1410 if ($special_encoding) {
1411 $mime_header->encoding
= $special_encoding;
1413 $mime_header->encoding
= '8bit';
1415 if ($default_charset) {
1416 $mime_header->parameters
['charset'] = $default_charset;
1418 $message_body->mime_header
= $mime_header;
1419 array_unshift($composeMessage->entities
, $message_body);
1420 $content_type = new ContentType('multipart/mixed');
1422 $content_type = new ContentType('text/plain');
1423 if ($special_encoding) {
1424 $rfc822_header->encoding
= $special_encoding;
1426 $rfc822_header->encoding
= '8bit';
1429 if ($default_charset) {
1430 $content_type->properties
['charset']=$default_charset;
1433 $rfc822_header->content_type
= $content_type;
1434 $composeMessage->rfc822_header
= $rfc822_header;
1436 /* Here you can modify the message structure just before we hand
1437 it over to deliver */
1438 do_hook('compose_send');
1440 if (!$useSendmail && !$draft) {
1441 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1442 $deliver = new Deliver_SMTP();
1443 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1445 if ($smtp_auth_mech == 'none') {
1449 global $key, $onetimepad;
1451 $pass = OneTimePadDecrypt($key, $onetimepad);
1454 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1455 $stream = $deliver->initStream($composeMessage,$domain,0,
1456 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1457 } elseif (!$draft) {
1458 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1459 global $sendmail_path;
1460 $deliver = new Deliver_SendMail();
1461 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1463 global $draft_folder;
1464 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1465 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1467 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1468 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1469 $imap_deliver = new Deliver_IMAP();
1470 $length = $imap_deliver->mail($composeMessage);
1471 sqimap_append ($imap_stream, $draft_folder, $length);
1472 $imap_deliver->mail($composeMessage, $imap_stream);
1473 sqimap_append_done ($imap_stream, $draft_folder);
1474 sqimap_logout($imap_stream);
1475 unset ($imap_deliver);
1478 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1479 plain_error_message($msg, $color);
1485 $length = $deliver->mail($composeMessage, $stream);
1486 $succes = $deliver->finalizeStream($stream);
1489 $msg = $deliver->dlv_msg
. '<br>' .
1490 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1491 $deliver->dlv_server_msg
;
1492 plain_error_message($msg, $color);
1495 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1496 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1497 if (sqimap_mailbox_exists ($imap_stream, $sent_folder) && ((isset($move_to_sent) && $move_to_sent) ||
1498 (isset($default_move_to_sent) && $default_move_to_sent))) {
1499 sqimap_append ($imap_stream, $sent_folder, $length);
1500 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1501 $imap_deliver = new Deliver_IMAP();
1502 $imap_deliver->mail($composeMessage, $imap_stream);
1503 sqimap_append_done ($imap_stream, $sent_folder);
1504 unset ($imap_deliver);
1506 global $passed_id, $mailbox, $action;
1507 ClearAttachments($composeMessage);
1508 if ($action == 'reply' ||
$action == 'reply_all') {
1509 sqimap_mailbox_select ($imap_stream, $mailbox);
1510 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1512 sqimap_logout($imap_stream);