6 * Copyright (c) 1999-2002 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/imap.php');
26 require_once(SM_PATH
. 'functions/date.php');
27 require_once(SM_PATH
. 'functions/mime.php');
28 //require_once(SM_PATH . 'functions/smtp.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');
33 /* --------------------- Specific Functions ------------------------------ */
35 function replyAllString($header) {
36 global $include_self_reply_all, $username, $data_dir;
39 * 1) Remove the addresses we'll be sending the message 'to'
41 $url_replytoall_avoid_addrs = '';
42 if (isset($header->replyto
)) {
43 $excl_ar = $header->getAddr_a('replyto');
46 * 2) Remove our identities from the CC list (they still can be in the
47 * TO list) only if $include_self_reply_all is turned off
49 if (!$include_self_reply_all) {
50 $email_address = trim(getPref($data_dir, $username, 'email_address'));
51 $excl_ar[$email_address] = '';
53 $idents = getPref($data_dir, $username, 'identities');
54 if ($idents != '' && $idents > 1) {
55 for ($i = 1; $i < $idents; $i ++
) {
56 $cur_email_address = getPref($data_dir, $username,
57 'email_address' . $i);
58 $cur_email_address = strtolower($cur_email_address);
59 $excl_ar[$cur_email_address] = '';
65 * 3) get the addresses.
67 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
70 * 4) generate the string.
72 $url_replytoallcc = '';
73 foreach( $url_replytoall_ar as $email => $personal) {
75 $url_replytoallcc .= ", \"$personal\" <$email>";
77 $url_replytoallcc .= ', '. $email;
80 $url_replytoallcc = substr($url_replytoallcc,2);
81 return $url_replytoallcc;
84 function getforwardHeader($orig_header) {
87 $display = array( _("Subject") => strlen(_("Subject")),
88 _("From") => strlen(_("From")),
89 _("Date") => strlen(_("Date")),
90 _("To") => strlen(_("To")),
91 _("Cc") => strlen(_("Cc")) );
92 $maxsize = max($display);
93 $indent = str_pad('',$maxsize+
2);
94 foreach($display as $key => $val) {
95 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
97 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
98 "\n". $display[_("Subject")] .
99 decodeHeader($orig_header->subject
) . "\n" .
100 $display[_("From")] .
101 decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
102 $display[_("Date")] .
103 getLongDateString( $orig_header->date
). "\n" .
105 decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
106 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
107 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
109 $bodyTop .= str_pad('', $editor_size -2 , '-') .
113 /* ----------------------------------------------------------------------- */
116 * If the session is expired during a post this restores the compose session
119 //$session_expired = false;
120 if (session_is_registered('session_expired_post')) {
121 global $session_expired_post, $session_expired;
123 * extra check for username so we don't display previous post data from
124 * another user during this session.
126 if ($session_expired_post['username'] != $username) {
127 session_unregister('session_expired_post');
128 session_unregister('session_expired');
130 foreach ($session_expired_post as $postvar => $val) {
140 $session_expired = true;
142 session_unregister('session_expired_post');
143 session_unregister('session_expired');
144 if (!isset($mailbox)) {
147 if ($compose_new_win == '1') {
148 compose_Header($color, $mailbox);
150 displayPageHeader($color, $mailbox);
152 showInputForm($session, false);
156 if (!isset($attachments)) {
157 $attachments = array();
158 sqsession_register(array(), 'attachments');
161 if (!isset($composesession)) {
163 sqsession_register(0,'composesession');
166 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
167 $session = "$composesession" +
1;
168 $composesession = $session;
169 sqsession_register($composesession,'composesession');
172 if (!isset($compose_messages)) {
173 $compose_messages = array();
175 if (!isset($compose_messages[$session]) ||
($compose_messages[$session] == NULL)) {
176 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
177 $composeMessage = new message();
178 $rfc822_header = new Rfc822Header();
179 $composeMessage->rfc822_header
= $rfc822_header;
180 $composeMessage->reply_rfc822_header
= '';
181 $compose_messages[$session] = $composeMessage;
183 sqsession_register($compose_messages,'compose_messages');
185 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
191 * Set $default_charset to correspond with the user's selection
192 * of language interface.
195 $composeMessage=$compose_messages[$session];
196 $Result = sendMessage($composeMessage, true);
198 if (! sendMessage($composeMessage, true)) {
199 showInputForm($session);
202 $draft_message = _("Draft Email Saved");
203 /* If this is a resumed draft, then delete the original */
204 if(isset($delete_draft)) {
205 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
206 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
210 if ($compose_new_win == '1') {
211 Header("Location: compose.php?saved_draft=yes&session=$composesession");
215 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
216 "&startMessage=1¬e=".urlencode($draft_message));
224 if (isset($HTTP_POST_FILES['attachfile']) &&
225 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
226 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
227 $AttachFailure = saveAttachedFiles($session);
229 if (checkInput(false) && !isset($AttachFailure)) {
230 $urlMailbox = urlencode (trim($mailbox));
231 if (! isset($passed_id)) {
235 * Set $default_charset to correspond with the user's selection
236 * of language interface.
240 * This is to change all newlines to \n
241 * We'll change them to \r\n later (in the sendMessage function)
243 $body = str_replace("\r\n", "\n", $body);
244 $body = str_replace("\r", "\n", $body);
247 * Rewrap $body so that no line is bigger than $editor_size
248 * This should only really kick in the sqWordWrap function
249 * if the browser doesn't support "VIRTUAL" as the wrap type.
251 $body = explode("\n", $body);
253 foreach ($body as $line) {
254 if( $line <> '-- ' ) {
255 $line = rtrim($line);
257 if (strlen($line) <= $editor_size +
1) {
258 $newBody .= $line . "\n";
260 sqWordWrap($line, $editor_size);
261 $newBody .= $line . "\n";
265 do_hook('compose_send');
266 $composeMessage=$compose_messages[$session];
267 $Result = sendMessage($composeMessage);
269 showInputForm($session);
272 if ( isset($delete_draft)) {
273 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
274 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
277 if ($compose_new_win == '1') {
278 Header("Location: compose.php?mail_sent=yes");
281 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
286 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
289 if ($compose_new_win == '1') {
290 compose_Header($color, $mailbox);
293 displayPageHeader($color, $mailbox);
295 if (isset($AttachFailure)) {
296 plain_error_message(_("Could not move/copy file. File not attached"),
300 showInputForm($session);
301 /* sqimap_logout($imapConnection); */
303 } elseif (isset($html_addr_search_done)) {
304 if ($compose_new_win == '1') {
305 compose_Header($color, $mailbox);
308 displayPageHeader($color, $mailbox);
311 if (isset($send_to_search) && is_array($send_to_search)) {
312 foreach ($send_to_search as $k => $v) {
313 if (substr($k, 0, 1) == 'T') {
319 elseif (substr($k, 0, 1) == 'C') {
325 elseif (substr($k, 0, 1) == 'B') {
327 $send_to_bcc .= ', ';
333 showInputForm($session);
334 } elseif (isset($html_addr_search)) {
335 if (isset($HTTP_POST_FILES['attachfile']) &&
336 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
337 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
338 if (saveAttachedFiles($session)) {
339 plain_error_message(_("Could not move/copy file. File not attached"), $color);
343 * I am using an include so as to elminiate an extra unnecessary
344 * click. If you can think of a better way, please implement it.
346 include_once('./addrbook_search_html.php');
347 } elseif (isset($attach)) {
348 if (saveAttachedFiles($session)) {
349 plain_error_message(_("Could not move/copy file. File not attached"), $color);
351 if ($compose_new_win == '1') {
352 compose_Header($color, $mailbox);
355 displayPageHeader($color, $mailbox);
357 showInputForm($session);
359 elseif (isset($sigappend)) {
360 $idents = getPref($data_dir, $username, 'identities', 0);
362 if ($identity == 'default') {
367 $signature = getSig($data_dir, $username, $no);
369 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
370 if ($compose_new_win == '1') {
371 compose_Header($color, $mailbox);
373 displayPageHeader($color, $mailbox);
375 showInputForm($session);
376 } elseif (isset($do_delete)) {
377 if ($compose_new_win == '1') {
378 compose_Header($color, $mailbox);
381 displayPageHeader($color, $mailbox);
384 if (isset($delete) && is_array($delete)) {
385 $composeMessage = $compose_messages[$session];
386 foreach($delete as $index) {
387 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
388 unlink ($attached_file);
389 unset ($composeMessage->entities
[$index]);
391 $new_entities = array();
392 foreach ($composeMessage->entities
as $entity) {
393 $new_entities[] = $entity;
395 $composeMessage->entities
= $new_entities;
396 $compose_messages[$session] = $composeMessage;
397 sqsession_register($compose_messages, 'compose_messages');
398 // setPref($data_dir, $username, 'attachments', serialize($attachments));
400 showInputForm($session);
403 * This handles the default case as well as the error case
404 * (they had the same code) --> if (isset($smtpErrors))
407 if ($compose_new_win == '1') {
408 compose_Header($color, $mailbox);
410 displayPageHeader($color, $mailbox);
415 if (!isset($passed_ent_id)) {
418 if (!isset($passed_id)) {
421 if (!isset($mailbox)) {
424 if (!isset($action)) {
428 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
430 /* in case the origin is not read_body.php */
431 if (isset($send_to)) {
432 $values['send_to'] = $send_to;
434 if (isset($send_to_cc)) {
435 $values['send_to_cc'] = $send_to_cc;
437 if (isset($send_to_bcc)) {
438 $values['send_to_bcc'] = $send_to_bcc;
440 showInputForm($session, $values);
445 /**************** Only function definitions go below *************/
448 /* This function is used when not sending or adding attachments */
449 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
450 global $editor_size, $default_use_priority, $body,
451 $use_signature, $composesession, $data_dir, $username,
452 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
455 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
459 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
462 sqimap_mailbox_select($imapConnection, $mailbox);
463 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
466 if ($passed_ent_id) {
467 /* redefine the messsage in case of message/rfc822 */
468 $message = $message->getEntity($passed_ent_id);
469 /* message is an entity which contains the envelope and type0=message
470 * and type1=rfc822. The actual entities are childs from
471 * $message->entities[0]. That's where the encoding and is located
474 $entities = $message->entities
[0]->findDisplayEntity
475 (array(), $alt_order = array('text/plain'));
476 if (!count($entities)) {
477 $entities = $message->entities
[0]->findDisplayEntity
478 (array(), $alt_order = array('text/plain','html/plain'));
480 $orig_header = $message->rfc822_header
; /* here is the envelope located */
481 /* redefine the message for picking up the attachments */
482 $message = $message->entities
[0];
485 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
486 if (!count($entities)) {
487 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
489 $orig_header = $message->rfc822_header
;
492 $encoding = $message->header
->encoding
;
493 $type0 = $message->type0
;
494 $type1 = $message->type1
;
495 foreach ($entities as $ent) {
496 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
497 $body_part_entity = $message->getEntity($ent);
498 $bodypart = decodeBody($unencoded_bodypart,
499 $body_part_entity->header
->encoding
);
500 if ($type1 == 'html') {
501 $bodypart = strip_tags($bodypart);
505 if ($default_use_priority) {
506 $mailprio = substr($orig_header->priority
,0,1);
513 //ClearAttachments($session);
516 $idents = getPref($data_dir, $username, 'identities');
517 $from_o = $orig_header->from
;
518 if (is_object($from_o)) {
519 $orig_from = $from_o->getAddress();
523 if (!empty($idents) && $idents > 1) {
524 for ($i = 1; $i < $idents; $i++
) {
525 $enc_from_name = '"'.
529 '" <' . getPref($data_dir, $username,
530 'email_address' . $i) . '>';
531 if ($enc_from_name == $orig_from) {
540 $use_signature = FALSE;
541 $send_to = decodeHeader($orig_header->getAddr_s('to'));
542 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
543 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
544 $subject = decodeHeader($orig_header->subject
);
546 $body_ary = explode("\n", $body);
547 $cnt = count($body_ary) ;
549 for ($i=0; $i < $cnt; $i++
) {
550 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
551 sqWordWrap($body_ary[$i], $editor_size );
552 $body .= $body_ary[$i] . "\n";
554 unset($body_ary[$i]);
557 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
559 case ('edit_as_new'):
560 $send_to = decodeHeader($orig_header->getAddr_s('to'));
561 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
562 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
563 $subject = decodeHeader($orig_header->subject
);
564 $mailprio = $orig_header->priority
;
566 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
571 $subject = decodeHeader($orig_header->subject
);
572 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
573 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
574 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
575 $subject = '[Fwd: ' . $subject . ']';
577 $body = getforwardHeader($orig_header) . $body;
579 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
581 case ('forward_as_attachment'):
582 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
586 $send_to_cc = replyAllString($orig_header);
588 $send_to = $orig_header->reply_to
;
589 if (is_object($send_to)) {
590 $send_to = decodeHeader($send_to->getAddr_s('reply_to'));
592 $send_to = decodeHeader($orig_header->getAddr_s('from'));
594 $subject = decodeHeader($orig_header->subject
);
595 $subject = str_replace('"', "'", $subject);
596 $subject = trim($subject);
597 if (substr(strtolower($subject), 0, 3) != 're:') {
598 $subject = 'Re: ' . $subject;
600 /* this corrects some wrapping/quoting problems on replies */
601 $rewrap_body = explode("\n", $body);
603 $body = getReplyCitation($orig_header->from
->personal
);
604 $cnt = count($rewrap_body);
605 for ($i=0;$i<$cnt;$i++
) {
606 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
607 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
609 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
611 $body .= '> ' . $rewrap_body[$i] . "\n";
613 unset($rewrap_body[$i]);
615 $composeMessage->reply_rfc822_header
= $orig_header;
620 $compose_messages[$session] = $composeMessage;
621 sqsession_register($compose_messages, 'compose_messages');
623 sqimap_logout($imapConnection);
625 $ret = array( 'send_to' => $send_to,
626 'send_to_cc' => $send_to_cc,
627 'send_to_bcc' => $send_to_bcc,
628 'subject' => $subject,
629 'mailprio' => $mailprio,
631 'identity' => $identity );
634 } /* function newMail() */
636 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
637 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
638 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
639 if (!count($message->entities
) ||
640 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
641 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
642 switch ($message->type0
) {
644 if ($message->type1
== 'rfc822') {
645 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
646 if ($filename == "") {
647 $filename = "untitled-".$message->entity_id
.'.eml';
650 $filename = decodeHeader($message->getFilename());
654 $filename = decodeHeader($message->getFilename());
657 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
658 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
659 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
662 $localfilename = GenerateRandomString(32, '', 7);
663 $full_localfilename = "$hashed_attachment_dir/$localfilename";
664 while (file_exists($full_localfilename)) {
665 $localfilename = GenerateRandomString(32, '', 7);
666 $full_localfilename = "$hashed_attachment_dir/$localfilename";
668 $message->att_local_name
= $full_localfilename;
669 if (!$message->mime_header
) { /* temporary hack */
670 $message->mime_header
= $message->header
;
673 $composeMessage->addEntity($message);
675 /* Write Attachment to file */
676 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
677 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
678 $passed_id, $message->entity_id
),
679 $message->header
->encoding
));
683 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
684 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
687 // setPref($data_dir, $username, 'attachments', serialize($attachments));
688 return $composeMessage;
691 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
692 $passed_ent_id='', $imapConnection) {
693 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
694 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
695 if (!$passed_ent_id) {
696 $body_a = sqimap_run_command($imapConnection,
697 'FETCH '.$passed_id.' RFC822',
698 TRUE, $response, $readmessage,
701 $body_a = sqimap_run_command($imapConnection,
702 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
703 TRUE, $response, $readmessage, $uid_support);
704 $message = $message->parent
;
706 if ($response = 'OK') {
707 $subject = encodeHeader($message->rfc822_header
->subject
);
708 array_shift($body_a);
709 $body = implode('', $body_a) . "\r\n";
711 $localfilename = GenerateRandomString(32, 'FILE', 7);
712 $full_localfilename = "$hashed_attachment_dir/$localfilename";
714 $fp = fopen( $full_localfilename, 'w');
717 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
718 $full_localfilename);
720 return $composeMessage;
723 function showInputForm ($session, $values=false) {
724 global $send_to, $send_to_cc, $body,
725 $passed_body, $color, $use_signature, $signature, $prefix_sig,
726 $editor_size, $attachments, $subject, $newmail,
727 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
728 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
729 $username, $data_dir, $identity, $draft_id, $delete_draft,
730 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
731 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
732 $username, $compose_messages;
734 $composeMessage = $compose_messages[$session];
736 $subject = decodeHeader($subject, false);
738 $send_to = $values['send_to'];
739 $send_to_cc = $values['send_to_cc'];
740 $send_to_bcc = $values['send_to_bcc'];
741 $subject = $values['subject'];
742 $mailprio = $values['mailprio'];
743 $body = $values['body'];
744 $identity = $values['identity'];
747 if ($use_javascript_addr_book) {
748 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
749 'function open_abook() { ' . "\n" .
750 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
751 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
752 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
753 ' nwin.opener = document.windows;' . "\n" .
755 '// --></SCRIPT>' . "\n\n";
758 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
759 'ENCTYPE="multipart/form-data"';
760 do_hook("compose_form");
765 if ($action == 'draft') {
766 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
768 if (isset($delete_draft)) {
769 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
771 if (isset($session)) {
772 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
775 if (isset($passed_id)) {
776 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
779 if ($saved_draft == 'yes') {
780 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
782 if ($mail_sent == 'yes') {
783 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
785 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
786 if ($compose_new_win == '1') {
787 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
788 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
790 if ($location_of_buttons == 'top') {
791 showComposeButtonRow();
794 $idents = getPref($data_dir, $username, 'identities', 0);
796 echo ' <TR>' . "\n" .
797 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
800 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
801 '<select name=identity>' . "\n" .
802 '<option value=default>' .
803 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
804 $em = getPref($data_dir, $username, 'email_address');
806 echo htmlspecialchars(' <' . $em . '>') . "\n";
808 for ($i = 1; $i < $idents; $i ++
) {
809 echo '<option value="' . $i . '"';
810 if (isset($identity) && $identity == $i) {
813 echo '>' . htmlspecialchars(getPref($data_dir, $username,
815 $em = getPref($data_dir, $username, 'email_address' . $i);
817 echo htmlspecialchars(' <' . $em . '>') . "\n";
821 echo '</select>' . "\n" .
825 echo ' <TR>' . "\n" .
826 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
828 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
829 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
830 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
834 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
836 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
837 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
838 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
842 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
844 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
845 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
846 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
847 '</TD></TR>' . "\n" .
849 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
851 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
852 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
853 htmlspecialchars($subject) . '">';
854 echo '</td></tr>' . "\n\n";
856 if ($location_of_buttons == 'between') {
857 showComposeButtonRow();
859 if ($compose_new_win == '1') {
860 echo ' <TR>' . "\n" .
861 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
862 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
863 $editor_size . '" WRAP="VIRTUAL">';
866 echo ' <TR>' . "\n" .
867 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
868 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
869 $editor_size . '" WRAP="VIRTUAL">';
871 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
872 if ($sig_first == '1') {
873 if ($charset == 'iso-2022-jp') {
874 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
876 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
878 echo "\n\n".htmlspecialchars($body);
881 echo "\n\n".htmlspecialchars($body);
882 if ($charset == 'iso-2022-jp') {
883 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
885 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
890 echo htmlspecialchars($body);
892 echo '</TEXTAREA><BR>' . "\n" .
896 if ($location_of_buttons == 'bottom') {
897 showComposeButtonRow();
899 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
900 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
901 ' <BR><BR>' .
902 ' </TD></TR>' . "\n";
905 /* This code is for attachments */
906 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
908 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
910 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
912 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
915 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
916 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
917 ' <input type="submit" name="attach"' .
918 ' value="' . _("Add") .'">' . "\n" .
924 foreach ($composeMessage->entities
as $key => $attachment) {
925 $attached_file = $attachment->att_local_name
;
926 if ($attachment->att_local_name ||
$attachment->body_part
) {
927 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
928 $type = $attachment->mime_header
->type0
.'/'.
929 $attachment->mime_header
->type1
;
930 $s_a[] = '<input type="checkbox" name="delete[]" value="' .
931 $key . "\">\n" . $attached_filename . ' - ' . $type .
932 ' ('.show_readable_size( filesize( $attached_file ) )
937 foreach ($s_a as $s) {
938 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
940 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
941 _("Delete selected attachments") . "\">\n" .
944 echo ' </table></td></tr>' .
948 /* End of attachment code */
949 if ($compose_new_win == '1') {
950 echo '</TABLE>'."\n";
952 echo '</TABLE>' . "\n" .
953 '<input type="hidden" name="username" value="'. $username . "\">\n" .
954 '<input type=hidden name=action value=' . $action . ">\n" .
955 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
958 do_hook('compose_bottom');
959 echo '</BODY></HTML>' . "\n";
963 function showComposeButtonRow() {
964 global $use_javascript_addr_book, $save_as_draft,
965 $default_use_priority, $mailprio, $default_use_mdn,
966 $request_mdn, $request_dr,
967 $data_dir, $username;
969 echo " <TR><TD>\n</TD><TD>\n";
970 if ($default_use_priority) {
971 if(!isset($mailprio)) {
974 echo _("Priority") .': <select name="mailprio">'.
975 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
976 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
977 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
980 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
981 if ($default_use_mdn) {
982 if ($mdn_user_support) {
983 echo "\n\t". _("Receipt") .': '.
984 '<input type="checkbox" name="request_mdn" value=1'.
985 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
986 ' <input type="checkbox" name="request_dr" value=1'.
987 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
991 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
992 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
993 if ($use_javascript_addr_book) {
994 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
995 " <input type=button value=\\\""._("Addresses").
996 "\\\" onclick='javascript:open_abook();'>\");".
997 " // --></SCRIPT><NOSCRIPT>\n".
998 " <input type=submit name=\"html_addr_search\" value=\"".
999 _("Addresses")."\">".
1002 echo " <input type=submit name=\"html_addr_search\" value=\"".
1003 _("Addresses")."\">";
1006 if ($save_as_draft) {
1007 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1010 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
1011 do_hook('compose_button_row');
1013 echo " </TD></TR>\n\n";
1016 function checkInput ($show) {
1018 * I implemented the $show variable because the error messages
1019 * were getting sent before the page header. So, I check once
1020 * using $show=false, and then when i'm ready to display the error
1021 * message, show=true
1023 global $body, $send_to, $send_to_bcc, $subject, $color;
1025 if ($send_to == '' && $send_to_bcc == '') {
1027 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1032 } /* function checkInput() */
1035 /* True if FAILURE */
1036 function saveAttachedFiles($session) {
1037 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1038 $data_dir, $compose_messages;
1040 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1041 $localfilename = GenerateRandomString(32, '', 7);
1042 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1043 while (file_exists($full_localfilename)) {
1044 $localfilename = GenerateRandomString(32, '', 7);
1045 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1048 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1049 if (function_exists("move_uploaded_file")) {
1050 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1054 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1059 $message = $compose_messages[$session];
1060 $type = strtolower($HTTP_POST_FILES['attachfile']['type']);
1061 $name = $HTTP_POST_FILES['attachfile']['name'];
1062 $message->initAttachment($type, $name, $full_localfilename);
1063 $compose_messages[$session] = $message;
1066 function ClearAttachments($composeMessage) {
1067 if ($composeMessage->att_local_name
) {
1068 $attached_file = $composeMessage->att_local_name
;
1069 if (file_exists($attached_file)) {
1070 unlink($attached_file);
1073 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1074 ClearAttachments($composeMessage->entities
[$i]);
1080 function getReplyCitation($orig_from) {
1081 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1083 /* First, return an empty string when no citation style selected. */
1084 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1088 /* Make sure our final value isn't an empty string. */
1089 if ($orig_from == '') {
1093 /* Otherwise, try to select the desired citation style. */
1094 switch ($reply_citation_style) {
1097 $end = ' ' . _("said") . ':';
1100 $start = '<' . _("quote") . ' ' . _("who") . '="';
1103 case 'user-defined':
1104 $start = $reply_citation_start .
1105 ($reply_citation_start == '' ?
'' : ' ');
1106 $end = $reply_citation_end;
1112 /* Build and return the citation string. */
1113 return ($start . $orig_from . $end . "\n");
1116 /* temporary function to make use of the deliver class.
1117 In the future the responsable backend should be automaticly loaded
1118 and conf.pl should show a list of available backends.
1119 The message also should be constructed by the message class.
1122 function sendMessage($composeMessage, $draft=false) {
1123 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1124 $username, $popuser, $usernamedata, $identity, $data_dir,
1125 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1127 global $imapServerAddress, $imapPort, $sent_folder, $key;
1129 $rfc822_header = $composeMessage->rfc822_header
;
1130 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
1131 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
1132 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
1133 $rfc822_header->priority
= $mailprio;
1134 $rfc822_header->subject
= $subject;
1135 $special_encoding='';
1136 if (strtolower($default_charset) == 'iso-2022-jp') {
1137 if (mb_detect_encoding($body) == 'ASCII') {
1138 $special_encoding = '8bit';
1140 $body = mb_convert_encoding($body, 'JIS');
1141 $special_encoding = '7bit';
1144 $composeMessage->setBody($body);
1146 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1147 $popuser = $usernamedata[1];
1148 $domain = $usernamedata[2];
1149 unset($usernamedata);
1151 $popuser = $username;
1154 if (isset($identity) && $identity != 'default') {
1155 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1156 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1157 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1159 $from_mail = getPref($data_dir, $username, 'email_address');
1160 $full_name = getPref($data_dir, $username, 'full_name');
1161 $reply_to = getPref($data_dir, $username,'reply_to');
1164 $from_mail = "$popuser@$domain";
1167 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1169 $from = $rfc822_header->from
[0];
1170 if (!$from->host
) $from->host
= $domain;
1171 $from_addr = $full_name .' <'.$from->mailbox
.'@'.$from->host
.'>';
1172 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1175 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1177 /* Receipt: On Read */
1178 if (isset($request_mdn) && $request_mdn) {
1179 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1181 /* Receipt: On Delivery */
1182 if (isset($request_dr) && $request_dr) {
1183 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1185 /* multipart messages */
1186 if (count($composeMessage->entities
)) {
1187 $message_body = new Message();
1188 $message_body->body_part
= $composeMessage->body_part
;
1189 $composeMessage->body_part
= '';
1190 $mime_header = new MessageHeader
;
1191 $mime_header->type0
= 'text';
1192 $mime_header->type1
= 'plain';
1193 if ($special_encoding) {
1194 $mime_header->encoding
= $special_encoding;
1196 $mime_header->encoding
= 'us-ascii';
1198 if ($default_charset) {
1199 $mime_header->parameters
['charset'] = $default_charset;
1201 $message_body->mime_header
= $mime_header;
1202 array_unshift($composeMessage->entities
, $message_body);
1203 $content_type = new ContentType('multipart/mixed');
1205 $content_type = new ContentType('text/plain');
1207 if ($default_charset) {
1208 $content_type->properties
['charset']=$default_charset;
1211 $rfc822_header->content_type
= $content_type;
1212 $composeMessage->rfc822_header
= $rfc822_header;
1214 if (!$useSendmail && !$draft) {
1215 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1216 $deliver = new Deliver_SMTP();
1217 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
1218 if ($use_authenticated_smtp) {
1219 global $key, $onetimepad;
1221 $pass = OneTimePadDecrypt($key, $onetimepad);
1226 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1227 $stream = $deliver->initStream($composeMessage,$domain,0,
1228 $smtpServerAddress, $smtpPort, $authPop);
1229 } elseif (!$draft) {
1230 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1231 global $sendmail_path;
1232 $deliver = new Deliver_SendMail();
1233 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1235 global $draft_folder;
1236 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1237 // $imap_deliver = new Deliver_IMAP();
1238 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1240 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1241 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1242 $imap_deliver = new Deliver_IMAP();
1243 $length = $imap_deliver->mail($composeMessage);
1244 sqimap_append ($imap_stream, $draft_folder, $length);
1245 $imap_deliver->mail($composeMessage, $imap_stream);
1246 sqimap_append_done ($imap_stream);
1247 sqimap_logout($imap_stream);
1248 unset ($imap_deliver);
1255 $length = $deliver->mail($composeMessage, $stream);
1256 $succes = $deliver->finalizeStream($stream);
1259 $msg = $deliver->dlv_msg
. '<br>Server replied: '.$deliver->dlv_ret_nr
;
1260 plain_error_message($msg, $color);
1263 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1265 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1266 sqimap_append ($imap_stream, $sent_folder, $length);
1267 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1268 $imap_deliver = new Deliver_IMAP();
1269 $imap_deliver->mail($composeMessage, $imap_stream);
1270 sqimap_append_done ($imap_stream);
1271 unset ($imap_deliver);
1273 global $passed_id, $mailbox, $action;
1274 ClearAttachments($composeMessage);
1275 if ($action == 'reply' ||
$action == 'reply_all') {
1276 sqimap_mailbox_select ($imap_stream, $mailbox);
1277 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1279 sqimap_logout($imap_stream);