99af71aabca55b35348ecf8ef86647b880b22281
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This code sends a mail.
11 * There are 4 modes of operation:
20 /* Path for SquirrelMail required files. */
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 require_once(SM_PATH
. 'functions/global.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/date.php');
28 require_once(SM_PATH
. 'functions/mime.php');
29 require_once(SM_PATH
. 'functions/plugin.php');
30 require_once(SM_PATH
. 'functions/display_messages.php');
31 require_once(SM_PATH
. 'class/deliver/Deliver.class.php');
32 require_once(SM_PATH
. 'functions/addressbook.php');
34 /* --------------------- Get globals ------------------------------------- */
36 sqgetGlobalVar('key', $key, SQ_COOKIE
);
39 sqgetGlobalVar('username', $username, SQ_SESSION
);
40 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
41 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
42 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
44 sqgetGlobalVar('composesession', $composesession, SQ_SESSION
);
45 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION
);
47 /** SESSION/POST/GET VARS */
48 sqgetGlobalVar('action',$action);
49 sqgetGlobalVar('session',$session);
50 sqgetGlobalVar('mailbox',$mailbox);
51 sqgetGlobalVar('identity',$identity);
52 sqgetGlobalVar('send_to',$send_to);
53 sqgetGlobalVar('send_to_cc',$send_to_cc);
54 sqgetGlobalVar('send_to_bcc',$send_to_bcc);
55 sqgetGlobalVar('subject',$subject);
56 sqgetGlobalVar('body',$body);
57 sqgetGlobalVar('mailprio',$mailprio);
58 sqgetGlobalVar('request_mdn',$request_mdn);
59 sqgetGlobalVar('request_dr',$request_dr);
60 sqgetGlobalVar('html_addr_search',$html_addr_search);
61 sqgetGlobalVar('mail_sent',$mail_sent);
62 sqgetGlobalVar('passed_id',$passed_id);
63 sqgetGlobalVar('passed_ent_id',$passed_ent_id);
64 sqgetGlobalVar('send',$send);
66 sqgetGlobalVar('attach',$attach);
68 sqgetGlobalVar('draft',$draft);
69 sqgetGlobalVar('draft_id',$draft_id);
70 sqgetGlobalVar('ent_num',$ent_num);
71 sqgetGlobalVar('saved_draft',$saved_draft);
72 sqgetGlobalVar('delete_draft',$delete_draft);
76 sqgetGlobalVar('sigappend', $sigappend, SQ_POST
);
77 sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST
);
78 sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST
);
79 sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST
);
80 sqgetGlobalVar('do_delete', $do_delete, SQ_POST
);
81 sqgetGlobalVar('delete', $delete, SQ_POST
);
82 sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST
);
83 if ( sqgetGlobalVar('return', $temp, SQ_POST
) ) {
84 $html_addr_search_done = 'Use Addresses';
88 sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET
);
90 /* --------------------- Specific Functions ------------------------------ */
92 function replyAllString($header) {
93 global $include_self_reply_all, $username, $data_dir;
96 * 1) Remove the addresses we'll be sending the message 'to'
98 $url_replytoall_avoid_addrs = '';
99 if (isset($header->replyto
)) {
100 $excl_ar = $header->getAddr_a('replyto');
103 * 2) Remove our identities from the CC list (they still can be in the
104 * TO list) only if $include_self_reply_all is turned off
106 if (!$include_self_reply_all) {
107 $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address')));
108 $excl_ar[$email_address] = '';
109 $idents = getPref($data_dir, $username, 'identities');
110 if ($idents != '' && $idents > 1) {
112 for ($i = 1; $i < $idents; $i ++
) {
113 $cur_email_address = getPref($data_dir, $username,
114 'email_address' . $i);
115 $cur_email_address = strtolower(trim($cur_email_address));
116 $excl_ar[$cur_email_address] = '';
122 * 3) get the addresses.
124 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
127 * 4) generate the string.
129 $url_replytoallcc = '';
130 foreach( $url_replytoall_ar as $email => $personal) {
132 $url_replytoallcc .= ", $personal <$email>";
134 $url_replytoallcc .= ', '. $email;
137 $url_replytoallcc = substr($url_replytoallcc,2);
139 return $url_replytoallcc;
142 function getReplyCitation($orig_from) {
143 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
144 $orig_from = decodeHeader($orig_from->getAddress(false),false,false);
145 // $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
146 /* First, return an empty string when no citation style selected. */
147 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
151 /* Make sure our final value isn't an empty string. */
152 if ($orig_from == '') {
156 /* Otherwise, try to select the desired citation style. */
157 switch ($reply_citation_style) {
160 $end = ' ' . _("said") . ':';
163 $start = '<' . _("quote") . ' ' . _("who") . '="';
167 $start = $reply_citation_start .
168 ($reply_citation_start == '' ?
'' : ' ');
169 $end = $reply_citation_end;
175 /* Build and return the citation string. */
176 return ($start . $orig_from . $end . "\n");
179 function getforwardHeader($orig_header) {
182 $display = array( _("Subject") => strlen(_("Subject")),
183 _("From") => strlen(_("From")),
184 _("Date") => strlen(_("Date")),
185 _("To") => strlen(_("To")),
186 _("Cc") => strlen(_("Cc")) );
187 $maxsize = max($display);
188 $indent = str_pad('',$maxsize+
2);
189 foreach($display as $key => $val) {
190 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
192 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
193 $from = str_replace(' ',' ',$from);
194 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false);
195 $to = str_replace(' ',' ',$to);
196 $subject = decodeHeader($orig_header->subject
,false,false);
197 $subject = str_replace(' ',' ',$subject);
198 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
199 "\n". $display[_("Subject")] . $subject . "\n" .
200 $display[_("From")] . $from . "\n" .
201 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
202 $display[_("To")] . $to . "\n";
203 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
204 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false);
205 $cc = str_replace(' ',' ',$cc);
206 $bodyTop .= $display[_("Cc")] .$cc . "\n";
208 $bodyTop .= str_pad('', $editor_size -2 , '-') .
212 /* ----------------------------------------------------------------------- */
215 * If the session is expired during a post this restores the compose session
218 if (sqsession_is_registered('session_expired_post')) {
219 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION
);
221 * extra check for username so we don't display previous post data from
222 * another user during this session.
224 if ($session_expired_post['username'] != $username) {
225 unset($session_expired_post);
226 sqsession_unregister('session_expired_post');
227 session_write_close();
229 foreach ($session_expired_post as $postvar => $val) {
236 $compose_messages = unserialize(urldecode($restoremessages));
237 sqsession_register($compose_messages,'compose_messages');
238 sqsession_register($composesession,'composesession');
242 $session_expired = true;
244 unset($session_expired_post);
245 sqsession_unregister('session_expired_post');
246 session_write_close();
247 if (!isset($mailbox)) {
250 if ($compose_new_win == '1') {
251 compose_Header($color, $mailbox);
253 displayPageHeader($color, $mailbox);
255 showInputForm($session, false);
258 if (!isset($composesession)) {
260 sqsession_register(0,'composesession');
263 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
264 sqsession_unregister('composesession');
265 $session = "$composesession" +
1;
266 $composesession = $session;
267 sqsession_register($composesession,'composesession');
269 if (!isset($compose_messages)) {
270 $compose_messages = array();
272 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
273 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
274 $composeMessage = new Message();
275 $rfc822_header = new Rfc822Header();
276 $composeMessage->rfc822_header
= $rfc822_header;
277 $composeMessage->reply_rfc822_header
= '';
278 $compose_messages[$session] = $composeMessage;
279 sqsession_register($compose_messages,'compose_messages');
281 $composeMessage=$compose_messages[$session];
284 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
290 * Set $default_charset to correspond with the user's selection
291 * of language interface.
294 $composeMessage=$compose_messages[$session];
295 if (! deliverMessage($composeMessage, true)) {
296 showInputForm($session);
299 unset($compose_messages[$session]);
300 $draft_message = _("Draft Email Saved");
301 /* If this is a resumed draft, then delete the original */
302 if(isset($delete_draft)) {
303 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
304 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
308 if ($compose_new_win == '1') {
309 Header("Location: compose.php?saved_draft=yes&session=$composesession");
313 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
314 "&startMessage=1¬e=".urlencode($draft_message));
322 if (isset($_FILES['attachfile']) &&
323 $_FILES['attachfile']['tmp_name'] &&
324 $_FILES['attachfile']['tmp_name'] != 'none') {
325 $AttachFailure = saveAttachedFiles($session);
327 if (checkInput(false) && !isset($AttachFailure)) {
328 if ($mailbox == "All Folders") {
329 /* We entered compose via the search results page */
330 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
332 $urlMailbox = urlencode (trim($mailbox));
333 if (! isset($passed_id)) {
337 * Set $default_charset to correspond with the user's selection
338 * of language interface.
342 * This is to change all newlines to \n
343 * We'll change them to \r\n later (in the sendMessage function)
345 $body = str_replace("\r\n", "\n", $body);
346 $body = str_replace("\r", "\n", $body);
349 * Rewrap $body so that no line is bigger than $editor_size
350 * This should only really kick in the sqWordWrap function
351 * if the browser doesn't support "VIRTUAL" as the wrap type.
353 $body = explode("\n", $body);
355 foreach ($body as $line) {
356 if( $line <> '-- ' ) {
357 $line = rtrim($line);
359 if (strlen($line) <= $editor_size +
1) {
360 $newBody .= $line . "\n";
362 sqWordWrap($line, $editor_size);
363 $newBody .= $line . "\n";
367 do_hook('compose_send');
368 $composeMessage=$compose_messages[$session];
370 $Result = deliverMessage($composeMessage);
372 showInputForm($session);
375 unset($compose_messages[$session]);
376 if ( isset($delete_draft)) {
377 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
378 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
381 if ($compose_new_win == '1') {
383 Header("Location: compose.php?mail_sent=yes");
386 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
390 if ($compose_new_win == '1') {
391 compose_Header($color, $mailbox);
394 displayPageHeader($color, $mailbox);
396 if (isset($AttachFailure)) {
397 plain_error_message(_("Could not move/copy file. File not attached"),
401 showInputForm($session);
402 /* sqimap_logout($imapConnection); */
404 } elseif (isset($html_addr_search_done)) {
405 if ($compose_new_win == '1') {
406 compose_Header($color, $mailbox);
409 displayPageHeader($color, $mailbox);
412 if (isset($send_to_search) && is_array($send_to_search)) {
413 foreach ($send_to_search as $k => $v) {
414 if (substr($k, 0, 1) == 'T') {
420 elseif (substr($k, 0, 1) == 'C') {
426 elseif (substr($k, 0, 1) == 'B') {
428 $send_to_bcc .= ', ';
434 showInputForm($session);
435 } elseif (isset($html_addr_search)) {
436 if (isset($_FILES['attachfile']) &&
437 $_FILES['attachfile']['tmp_name'] &&
438 $_FILES['attachfile']['tmp_name'] != 'none') {
439 if(saveAttachedFiles($session)) {
440 plain_error_message(_("Could not move/copy file. File not attached"), $color);
444 * I am using an include so as to elminiate an extra unnecessary
445 * click. If you can think of a better way, please implement it.
447 include_once('./addrbook_search_html.php');
448 } elseif (isset($attach)) {
449 if (saveAttachedFiles($session)) {
450 plain_error_message(_("Could not move/copy file. File not attached"), $color);
452 if ($compose_new_win == '1') {
453 compose_Header($color, $mailbox);
456 displayPageHeader($color, $mailbox);
458 showInputForm($session);
460 elseif (isset($sigappend)) {
461 $idents = getPref($data_dir, $username, 'identities', 0);
463 if ($identity == 'default') {
468 $signature = getSig($data_dir, $username, $no);
470 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
471 if ($compose_new_win == '1') {
472 compose_Header($color, $mailbox);
474 displayPageHeader($color, $mailbox);
476 showInputForm($session);
477 } elseif (isset($do_delete)) {
478 if ($compose_new_win == '1') {
479 compose_Header($color, $mailbox);
482 displayPageHeader($color, $mailbox);
485 if (isset($delete) && is_array($delete)) {
486 $composeMessage = $compose_messages[$session];
487 foreach($delete as $index) {
488 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
489 unlink ($attached_file);
490 unset ($composeMessage->entities
[$index]);
492 $new_entities = array();
493 foreach ($composeMessage->entities
as $entity) {
494 $new_entities[] = $entity;
496 $composeMessage->entities
= $new_entities;
497 $compose_messages[$session] = $composeMessage;
498 sqsession_register($compose_messages, 'compose_messages');
500 showInputForm($session);
503 * This handles the default case as well as the error case
504 * (they had the same code) --> if (isset($smtpErrors))
507 if ($compose_new_win == '1') {
508 compose_Header($color, $mailbox);
510 displayPageHeader($color, $mailbox);
515 if (!isset($passed_ent_id)) {
518 if (!isset($passed_id)) {
521 if (!isset($mailbox)) {
524 if (!isset($action)) {
528 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
530 /* in case the origin is not read_body.php */
531 if (isset($send_to)) {
532 $values['send_to'] = $send_to;
534 if (isset($send_to_cc)) {
535 $values['send_to_cc'] = $send_to_cc;
537 if (isset($send_to_bcc)) {
538 $values['send_to_bcc'] = $send_to_bcc;
540 if (isset($subject)) {
541 $values['subject'] = $subject;
543 showInputForm($session, $values);
548 /**************** Only function definitions go below *************/
551 /* This function is used when not sending or adding attachments */
552 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
553 global $editor_size, $default_use_priority, $body,
554 $use_signature, $composesession, $data_dir, $username,
555 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
557 global $languages, $squirrelmail_language;
559 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
563 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
566 sqimap_mailbox_select($imapConnection, $mailbox);
567 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
570 if ($passed_ent_id) {
571 /* redefine the messsage in case of message/rfc822 */
572 $message = $message->getEntity($passed_ent_id);
573 /* message is an entity which contains the envelope and type0=message
574 * and type1=rfc822. The actual entities are childs from
575 * $message->entities[0]. That's where the encoding and is located
578 $entities = $message->entities
[0]->findDisplayEntity
579 (array(), $alt_order = array('text/plain'));
580 if (!count($entities)) {
581 $entities = $message->entities
[0]->findDisplayEntity
582 (array(), $alt_order = array('text/plain','html/plain'));
584 $orig_header = $message->rfc822_header
; /* here is the envelope located */
585 /* redefine the message for picking up the attachments */
586 $message = $message->entities
[0];
589 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
590 if (!count($entities)) {
591 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
593 $orig_header = $message->rfc822_header
;
596 $encoding = $message->header
->encoding
;
597 $type0 = $message->type0
;
598 $type1 = $message->type1
;
599 foreach ($entities as $ent) {
600 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
601 $body_part_entity = $message->getEntity($ent);
602 $bodypart = decodeBody($unencoded_bodypart,
603 $body_part_entity->header
->encoding
);
604 if ($type1 == 'html') {
605 $bodypart = str_replace(array(' ','>','<'),array(' ','<','>'),$bodypart);
606 $bodypart = strip_tags($bodypart);
608 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
609 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
610 if (mb_detect_encoding($bodypart) != 'ASCII') {
611 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
616 if ($default_use_priority) {
617 $mailprio = substr($orig_header->priority
,0,1);
624 //ClearAttachments($session);
627 $idents = getPref($data_dir, $username, 'identities');
628 $from_o = $orig_header->from
;
629 if (is_object($from_o)) {
630 $orig_from = $from_o->getAddress();
634 $identities = array();
635 if (!empty($idents) && $idents > 1) {
636 $identities[] = '"'. getPref($data_dir, $username, 'full_name')
637 . '" <' . getPref($data_dir, $username, 'email_address') . '>';
638 for ($i = 1; $i < $idents; $i++
) {
639 $enc_from_name = '"'.
640 getPref($data_dir, $username, 'full_name' . $i) .
642 getPref($data_dir, $username, 'email_address' . $i) . '>';
643 if ($enc_from_name == $orig_from && $i) {
647 $identities[] = $enc_from_name;
649 $identity_match = $orig_header->findAddress($identities);
650 if ($identity_match) {
651 $identity = $identity_match;
657 $use_signature = FALSE;
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 $body_ary = explode("\n", $body);
663 $cnt = count($body_ary) ;
665 for ($i=0; $i < $cnt; $i++
) {
666 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
667 sqWordWrap($body_ary[$i], $editor_size );
668 $body .= $body_ary[$i] . "\n";
670 unset($body_ary[$i]);
673 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
675 case ('edit_as_new'):
676 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true);
677 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true);
678 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true);
679 $subject = decodeHeader($orig_header->subject
,false,true);
680 $mailprio = $orig_header->priority
;
682 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
687 $subject = decodeHeader($orig_header->subject
,false,true);
688 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
689 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
690 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
691 $subject = '[Fwd: ' . $subject . ']';
693 $body = getforwardHeader($orig_header) . $body;
695 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
696 $body = "\n" . $body;
698 case ('forward_as_attachment'):
699 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
703 $send_to_cc = replyAllString($orig_header);
704 $send_to_cc = decodeHeader($send_to_cc,false,true);
706 $send_to = $orig_header->reply_to
;
707 if (is_array($send_to) && count($send_to)) {
708 $send_to = $orig_header->getAddr_s('reply_to');
709 } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
710 $send_to = $orig_header->getAddr_s('reply_to');
712 $send_to = $orig_header->getAddr_s('from');
714 $send_to = decodeHeader($send_to,false,true);
715 $subject = decodeHeader($orig_header->subject
,false,true);
716 $subject = str_replace('"', "'", $subject);
717 $subject = trim($subject);
718 if (substr(strtolower($subject), 0, 3) != 're:') {
719 $subject = 'Re: ' . $subject;
721 /* this corrects some wrapping/quoting problems on replies */
722 $rewrap_body = explode("\n", $body);
723 $from = (is_array($orig_header->from
)) ?
$orig_header->from
[0] : $orig_header->from
;
726 $cnt = count($rewrap_body);
727 for ($i=0;$i<$cnt;$i++
) {
728 sqWordWrap($rewrap_body[$i], ($editor_size));
729 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
731 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
733 $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
735 unset($rewrap_body[$i]);
737 $body = getReplyCitation($from) . $body;
738 $composeMessage->reply_rfc822_header
= $orig_header;
744 $compose_messages[$session] = $composeMessage;
745 sqsession_register($compose_messages, 'compose_messages');
746 session_write_close();
747 sqimap_logout($imapConnection);
749 $ret = array( 'send_to' => $send_to,
750 'send_to_cc' => $send_to_cc,
751 'send_to_bcc' => $send_to_bcc,
752 'subject' => $subject,
753 'mailprio' => $mailprio,
755 'identity' => $identity );
758 } /* function newMail() */
760 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
761 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
762 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
763 if (!count($message->entities
) ||
764 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
765 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
766 switch ($message->type0
) {
768 if ($message->type1
== 'rfc822') {
769 $filename = $message->rfc822_header
->subject
.'.eml';
770 if ($filename == "") {
771 $filename = "untitled-".$message->entity_id
.'.eml';
774 $filename = $message->getFilename();
778 $filename = $message->getFilename();
781 $filename = decodeHeader($filename);
782 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
783 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
784 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
786 $localfilename = GenerateRandomString(32, '', 7);
787 $full_localfilename = "$hashed_attachment_dir/$localfilename";
788 while (file_exists($full_localfilename)) {
789 $localfilename = GenerateRandomString(32, '', 7);
790 $full_localfilename = "$hashed_attachment_dir/$localfilename";
792 $message->att_local_name
= $full_localfilename;
793 if (!$message->mime_header
) { /* temporary hack */
794 $message->mime_header
= $message->header
;
797 $composeMessage->addEntity($message);
799 /* Write Attachment to file */
800 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
801 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
802 $passed_id, $message->entity_id
),
803 $message->header
->encoding
));
807 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
808 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
811 return $composeMessage;
814 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
815 $passed_ent_id='', $imapConnection) {
816 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
817 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
818 if (!$passed_ent_id) {
819 $body_a = sqimap_run_command($imapConnection,
820 'FETCH '.$passed_id.' RFC822',
821 TRUE, $response, $readmessage,
824 $body_a = sqimap_run_command($imapConnection,
825 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
826 TRUE, $response, $readmessage, $uid_support);
827 $message = $message->parent
;
829 if ($response == 'OK') {
830 $subject = encodeHeader($message->rfc822_header
->subject
);
831 array_shift($body_a);
832 $body = implode('', $body_a) . "\r\n";
834 $localfilename = GenerateRandomString(32, 'FILE', 7);
835 $full_localfilename = "$hashed_attachment_dir/$localfilename";
837 $fp = fopen( $full_localfilename, 'w');
840 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
841 $full_localfilename);
843 return $composeMessage;
846 function showInputForm ($session, $values=false) {
847 global $send_to, $send_to_cc, $body,
848 $passed_body, $color, $use_signature, $signature, $prefix_sig,
849 $editor_size, $attachments, $subject, $newmail,
850 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
851 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
852 $username, $data_dir, $identity, $draft_id, $delete_draft,
853 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
854 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
855 $username, $compose_messages, $composesession, $default_charset;
857 $composeMessage = $compose_messages[$session];
860 $send_to = $values['send_to'];
861 $send_to_cc = $values['send_to_cc'];
862 $send_to_bcc = $values['send_to_bcc'];
863 $subject = $values['subject'];
864 $mailprio = $values['mailprio'];
865 $body = $values['body'];
866 $identity = (int) $values['identity'];
868 $send_to = decodeHeader($send_to);
869 $send_to_cc = decodeHeader($send_to_cc);
870 $send_to_bcc = decodeHeader($send_to_bcc);
873 if ($use_javascript_addr_book) {
874 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
875 'function open_abook() { ' . "\n" .
876 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
877 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
878 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
879 ' nwin.opener = document.windows;' . "\n" .
881 '// --></SCRIPT>' . "\n\n";
884 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
885 'ENCTYPE="multipart/form-data"';
886 do_hook("compose_form");
890 if ($action == 'draft') {
891 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
893 if (isset($delete_draft)) {
894 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
896 if (isset($session)) {
897 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
900 if (isset($passed_id)) {
901 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
904 if ($saved_draft == 'yes') {
905 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
907 if ($mail_sent == 'yes') {
908 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
910 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
911 if ($compose_new_win == '1') {
912 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
913 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
915 if ($location_of_buttons == 'top') {
916 showComposeButtonRow();
919 /* display select list for identities */
920 $idents = getPref($data_dir, $username, 'identities', 0);
922 $fn = getPref($data_dir, $username, 'full_name');
923 $em = getPref($data_dir, $username, 'email_address');
924 echo ' <tr>' . "\n" .
925 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
926 _("From:") . '</td>' . "\n" .
927 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
928 ' <select name="identity">' . "\n" .
929 ' <option value="default">' .
930 htmlspecialchars($fn);
933 echo htmlspecialchars(' <' . $em . '>') . "\n";
935 echo htmlspecialchars($em) . "\n";
938 for ($i = 1; $i < $idents; $i ++
) {
939 $fn = getPref($data_dir, $username, 'full_name' . $i);
940 $em = getPref($data_dir, $username, 'email_address' . $i);
942 echo '<option value="' . $i . '"';
943 if (isset($identity) && $identity == $i) {
946 echo '>' . htmlspecialchars($fn);
949 echo htmlspecialchars(' <' . $em . '>') . "\n";
951 echo htmlspecialchars($em) . "\n";
956 echo '</select>' . "\n" .
960 echo ' <tr>' . "\n" .
961 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
962 _("To:") . '</TD>' . "\n" .
963 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
964 ' <input type="text" name="send_to" value="' .
965 $send_to . '" size="60" /><br />' . "\n" .
969 html_tag( 'td', '', 'right', $color[4] ) .
970 _("CC:") . '</td>' . "\n" .
971 html_tag( 'td', '', 'left', $color[4] ) .
972 ' <input type="text" name="send_to_cc" size="60" value="' .
973 $send_to_cc . '" /><br />' . "\n" .
977 html_tag( 'td', '', 'right', $color[4] ) .
978 _("BCC:") . '</td>' . "\n" .
979 html_tag( 'td', '', 'left', $color[4] ) .
980 ' <input type="text" name="send_to_bcc" value="' .
981 $send_to_bcc . '" size="60" /><br />' . "\n" .
985 html_tag( 'td', '', 'right', $color[4] ) .
986 _("Subject:") . '</td>' . "\n" .
987 html_tag( 'td', '', 'left', $color[4] ) . "\n";
988 echo ' <input type="text" name="subject" size="60" value="' .
989 $subject . '" />' . "\n" .
993 if ($location_of_buttons == 'between') {
994 showComposeButtonRow();
997 /* why this distinction? */
998 if ($compose_new_win == '1') {
999 echo ' <TR>' . "\n" .
1000 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1001 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1002 $editor_size . '" WRAP="VIRTUAL">';
1005 echo ' <TR>' . "\n" .
1006 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1007 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
1008 $editor_size . '" WRAP="VIRTUAL">';
1011 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1013 if ($identity == 'default') {
1018 $signature = getSig($data_dir, $username, $no);
1021 if ($sig_first == '1') {
1022 if ($default_charset == 'iso-2022-jp') {
1023 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1025 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false);
1027 echo "\n\n".decodeHeader($body,false,true);
1030 echo "\n\n".decodeHeader($body,false,true);
1031 if ($default_charset == 'iso-2022-jp') {
1032 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1034 echo "\n\n".($prefix_sig==true?
"-- \n":'').decodeHeader($signature,false,true);
1039 echo decodeHeader($body,false,true);
1041 echo '</textarea><br />' . "\n" .
1046 if ($location_of_buttons == 'bottom') {
1047 showComposeButtonRow();
1049 echo ' <tr>' . "\n" .
1050 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1051 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1052 ' <br /><br />' . "\n" .
1057 /* This code is for attachments */
1058 if ((bool) ini_get('file_uploads')) {
1060 /* Calculate the max size for an uploaded file.
1061 * This is advisory for the user because we can't actually prevent
1062 * people to upload too large files. */
1064 /* php.ini vars which influence the max for uploads */
1065 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1066 foreach($configvars as $var) {
1067 /* skip 0 or empty values */
1068 if( $size = getByteSize(ini_get($var)) ) {
1073 if(count($sizes) > 0) {
1074 $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')';
1079 echo ' <tr>' . "\n" .
1080 ' <td colspan="2">' . "\n" .
1081 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1082 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1085 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1086 ' border="0">' . "\n" .
1088 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1089 _("Attach:") . '</td>' . "\n" .
1090 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1091 ' <input name="attachfile" size="48" type="file" />' . "\n" .
1092 ' <input type="submit" name="attach"' .
1093 ' value="' . _("Add") .'">' . "\n" .
1100 if ($composeMessage->entities
) {
1101 foreach ($composeMessage->entities
as $key => $attachment) {
1102 $attached_file = $attachment->att_local_name
;
1103 if ($attachment->att_local_name ||
$attachment->body_part
) {
1104 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
1105 $type = $attachment->mime_header
->type0
.'/'.
1106 $attachment->mime_header
->type1
;
1108 $s_a[] = '<table bgcolor="'.$color[0].
1109 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1110 $key . "\"></td><td>\n" . $attached_filename .
1111 '</td><td>-</td><td> ' . $type . '</td><td>('.
1112 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1117 foreach ($s_a as $s) {
1118 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1120 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1121 _("Delete selected attachments") . "\">\n" .
1124 echo ' </table>' . "\n" .
1127 ' </TABLE>' . "\n" .
1130 } // End of file_uploads if-block
1131 /* End of attachment code */
1132 if ($compose_new_win == '1') {
1133 echo '</TABLE>'."\n";
1136 echo '</TABLE>' . "\n" .
1137 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1138 '<input type=hidden name=action value="' . $action . "\">\n" .
1139 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1142 store the complete ComposeMessages array in a hidden input value
1143 so we can restore them in case of a session timeout.
1145 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER
);
1146 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1147 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1148 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1150 if (!(bool) ini_get('file_uploads')) {
1151 /* File uploads are off, so we didn't show that part of the form.
1152 To avoid bogus bug reports, tell the user why. */
1153 echo 'Because PHP file uploads are turned off, you can not attach files ';
1154 echo "to this message. Please see your system administrator for details.\r\n";
1157 do_hook('compose_bottom');
1158 echo '</BODY></HTML>' . "\n";
1162 function showComposeButtonRow() {
1163 global $use_javascript_addr_book, $save_as_draft,
1164 $default_use_priority, $mailprio, $default_use_mdn,
1165 $request_mdn, $request_dr,
1166 $data_dir, $username;
1168 echo ' <TR>' . "\n" .
1169 ' <TD></TD>' . "\n" .
1171 if ($default_use_priority) {
1172 if(!isset($mailprio)) {
1175 echo ' ' . _("Priority") .': <select name="mailprio">'.
1176 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
1177 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
1178 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
1181 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1182 if ($default_use_mdn) {
1183 if ($mdn_user_support) {
1184 echo ' ' . _("Receipt") .': '.
1185 '<input type="checkbox" name="request_mdn" value=1'.
1186 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
1187 ' <input type="checkbox" name="request_dr" value=1'.
1188 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
1192 echo ' </TD>' . "\n" .
1195 ' <TD></TD>' . "\n" .
1197 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
1198 if ($use_javascript_addr_book) {
1199 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1200 " <input type=button value=\\\""._("Addresses").
1201 "\\\" onclick='javascript:open_abook();'>\");".
1202 " // --></SCRIPT><NOSCRIPT>\n".
1203 " <input type=submit name=\"html_addr_search\" value=\"".
1204 _("Addresses")."\">".
1207 echo ' <input type=submit name="html_addr_search" value="'.
1208 _("Addresses").'">' . "\n";
1211 if ($save_as_draft) {
1212 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1215 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
1216 do_hook('compose_button_row');
1218 echo ' </TD>' . "\n" .
1222 function checkInput ($show) {
1224 * I implemented the $show variable because the error messages
1225 * were getting sent before the page header. So, I check once
1226 * using $show=false, and then when i'm ready to display the error
1227 * message, show=true
1229 global $body, $send_to, $send_to_bcc, $subject, $color;
1231 if ($send_to == '' && $send_to_bcc == '') {
1233 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1238 } /* function checkInput() */
1241 /* True if FAILURE */
1242 function saveAttachedFiles($session) {
1243 global $_FILES, $attachment_dir, $attachments, $username,
1244 $data_dir, $compose_messages;
1246 /* get out of here if no file was attached at all */
1247 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1251 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1252 $localfilename = GenerateRandomString(32, '', 7);
1253 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1254 while (file_exists($full_localfilename)) {
1255 $localfilename = GenerateRandomString(32, '', 7);
1256 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1259 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1260 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1261 if (!@rename
($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1262 if (!@move_uploaded_file
($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1266 $message = $compose_messages[$session];
1267 $type = strtolower($_FILES['attachfile']['type']);
1268 $name = $_FILES['attachfile']['name'];
1269 $message->initAttachment($type, $name, $full_localfilename);
1270 $compose_messages[$session] = $message;
1271 sqsession_register($compose_messages , 'compose_messages');
1274 function ClearAttachments($composeMessage) {
1275 if ($composeMessage->att_local_name
) {
1276 $attached_file = $composeMessage->att_local_name
;
1277 if (file_exists($attached_file)) {
1278 unlink($attached_file);
1281 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1282 ClearAttachments($composeMessage->entities
[$i]);
1286 /* parse values like 8M and 2k into bytes */
1287 function getByteSize($ini_size) {
1293 $ini_size = trim($ini_size);
1295 // if there's some kind of letter at the end of the string we need to multiply.
1296 if(!is_numeric(substr($ini_size, -1))) {
1298 switch(strtoupper(substr($ini_size, -1))) {
1300 $bytesize = 1073741824;
1303 $bytesize = 1048576;
1310 return ($bytesize * (int)substr($ini_size, 0, -1));
1317 /* temporary function to make use of the deliver class.
1318 In the future the responsable backend should be automaticly loaded
1319 and conf.pl should show a list of available backends.
1320 The message also should be constructed by the message class.
1323 function deliverMessage($composeMessage, $draft=false) {
1324 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1325 $username, $popuser, $usernamedata, $identity, $data_dir,
1326 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1327 $domain, $action, $default_move_to_sent, $move_to_sent;
1328 global $imapServerAddress, $imapPort, $sent_folder, $key;
1330 $rfc822_header = $composeMessage->rfc822_header
;
1332 $abook = addressbook_init(false, true);
1333 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1334 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1335 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1336 $rfc822_header->priority
= $mailprio;
1337 $rfc822_header->subject
= $subject;
1338 $special_encoding='';
1339 if (strtolower($default_charset) == 'iso-2022-jp') {
1340 if (mb_detect_encoding($body) == 'ASCII') {
1341 $special_encoding = '8bit';
1343 $body = mb_convert_encoding($body, 'JIS');
1344 $special_encoding = '7bit';
1347 $composeMessage->setBody($body);
1349 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1350 $popuser = $usernamedata[1];
1351 $domain = $usernamedata[2];
1352 unset($usernamedata);
1354 $popuser = $username;
1357 if (isset($identity) && $identity != 'default') {
1358 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1359 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1360 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1362 $from_mail = getPref($data_dir, $username, 'email_address');
1363 $full_name = getPref($data_dir, $username, 'full_name');
1364 $reply_to = getPref($data_dir, $username,'reply_to');
1367 $from_mail = "$popuser@$domain";
1370 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1372 $from = $rfc822_header->from
[0];
1373 if (!$from->host
) $from->host
= $domain;
1374 $full_name_encoded = encodeHeader($full_name);
1375 if ($full_name_encoded != $full_name) {
1376 $from_addr = $full_name_encoded .' <'.$from->mailbox
.'@'.$from->host
.'>';
1378 $from_addr = '"'.$full_name .'" <'.$from->mailbox
.'@'.$from->host
.'>';
1380 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1383 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1385 /* Receipt: On Read */
1386 if (isset($request_mdn) && $request_mdn) {
1387 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1389 /* Receipt: On Delivery */
1390 if (isset($request_dr) && $request_dr) {
1391 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1393 /* multipart messages */
1394 if (count($composeMessage->entities
)) {
1395 $message_body = new Message();
1396 $message_body->body_part
= $composeMessage->body_part
;
1397 $composeMessage->body_part
= '';
1398 $mime_header = new MessageHeader
;
1399 $mime_header->type0
= 'text';
1400 $mime_header->type1
= 'plain';
1401 if ($special_encoding) {
1402 $mime_header->encoding
= $special_encoding;
1404 $mime_header->encoding
= '8bit';
1406 if ($default_charset) {
1407 $mime_header->parameters
['charset'] = $default_charset;
1409 $message_body->mime_header
= $mime_header;
1410 array_unshift($composeMessage->entities
, $message_body);
1411 $content_type = new ContentType('multipart/mixed');
1413 $content_type = new ContentType('text/plain');
1414 if ($special_encoding) {
1415 $rfc822_header->encoding
= $special_encoding;
1417 $rfc822_header->encoding
= '8bit';
1420 if ($default_charset) {
1421 $content_type->properties
['charset']=$default_charset;
1424 $rfc822_header->content_type
= $content_type;
1425 $composeMessage->rfc822_header
= $rfc822_header;
1427 if (!$useSendmail && !$draft) {
1428 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1429 $deliver = new Deliver_SMTP();
1430 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1432 if ($smtp_auth_mech == 'none') {
1436 global $key, $onetimepad;
1438 $pass = OneTimePadDecrypt($key, $onetimepad);
1441 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1442 $stream = $deliver->initStream($composeMessage,$domain,0,
1443 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1444 } elseif (!$draft) {
1445 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1446 global $sendmail_path;
1447 $deliver = new Deliver_SendMail();
1448 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1450 global $draft_folder;
1451 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1452 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1454 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1455 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1456 $imap_deliver = new Deliver_IMAP();
1457 $length = $imap_deliver->mail($composeMessage);
1458 sqimap_append ($imap_stream, $draft_folder, $length);
1459 $imap_deliver->mail($composeMessage, $imap_stream);
1460 sqimap_append_done ($imap_stream, $draft_folder);
1461 sqimap_logout($imap_stream);
1462 unset ($imap_deliver);
1465 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1466 plain_error_message($msg, $color);
1472 $length = $deliver->mail($composeMessage, $stream);
1473 $succes = $deliver->finalizeStream($stream);
1476 $msg = $deliver->dlv_msg
. '<br>' .
1477 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
1478 $deliver->dlv_server_msg
;
1479 plain_error_message($msg, $color);
1482 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1483 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
1484 if (sqimap_mailbox_exists ($imap_stream, $sent_folder) && ((isset($move_to_sent) && $move_to_sent) ||
1485 (isset($default_move_to_sent) && $default_move_to_sent))) {
1486 sqimap_append ($imap_stream, $sent_folder, $length);
1487 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1488 $imap_deliver = new Deliver_IMAP();
1489 $imap_deliver->mail($composeMessage, $imap_stream);
1490 sqimap_append_done ($imap_stream, $sent_folder);
1491 unset ($imap_deliver);
1493 global $passed_id, $mailbox, $action;
1494 ClearAttachments($composeMessage);
1495 if ($action == 'reply' ||
$action == 'reply_all') {
1496 sqimap_mailbox_select ($imap_stream, $mailbox);
1497 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1499 sqimap_logout($imap_stream);