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 require_once('../src/validate.php');
21 require_once('../functions/imap.php');
22 require_once('../functions/date.php');
23 require_once('../functions/mime.php');
24 //require_once('../functions/smtp.php');
25 require_once('../functions/plugin.php');
26 require_once('../functions/display_messages.php');
27 require_once('../class/deliver/Deliver.class.php');
29 /* --------------------- Specific Functions ------------------------------ */
31 function replyAllString($header) {
32 global $include_self_reply_all, $username, $data_dir;
35 * 1) Remove the addresses we'll be sending the message 'to'
37 $url_replytoall_avoid_addrs = '';
38 if (isset($header->replyto
)) {
39 $excl_ar = $header->getAddr_a('replyto');
42 * 2) Remove our identities from the CC list (they still can be in the
43 * TO list) only if $include_self_reply_all is turned off
45 if (!$include_self_reply_all) {
46 $email_address = trim(getPref($data_dir, $username, 'email_address'));
47 $excl_ar[$email_address] = '';
49 $idents = getPref($data_dir, $username, 'identities');
50 if ($idents != '' && $idents > 1) {
51 for ($i = 1; $i < $idents; $i ++
) {
52 $cur_email_address = getPref($data_dir, $username,
53 'email_address' . $i);
54 $cur_email_address = strtolower($cur_email_address);
55 $excl_ar[$cur_email_address] = '';
61 * 3) get the addresses.
63 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
66 * 4) generate the string.
68 $url_replytoallcc = '';
69 foreach( $url_replytoall_ar as $email => $personal) {
71 $url_replytoallcc .= ", \"$personal\" <$email>";
73 $url_replytoallcc .= ', '. $email;
76 $url_replytoallcc = substr($url_replytoallcc,2);
77 return $url_replytoallcc;
80 function getforwardHeader($orig_header) {
83 $display = array( _("Subject") => strlen(_("Subject")),
84 _("From") => strlen(_("From")),
85 _("Date") => strlen(_("Date")),
86 _("To") => strlen(_("To")),
87 _("Cc") => strlen(_("Cc")) );
88 $maxsize = max($display);
89 $indent = str_pad('',$maxsize+
2);
90 foreach($display as $key => $val) {
91 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
93 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
94 "\n". $display[_("Subject")] .
95 decodeHeader($orig_header->subject
) . "\n" .
97 decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
99 getLongDateString( $orig_header->date
). "\n" .
101 decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
102 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
103 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
105 $bodyTop .= str_pad('', $editor_size -2 , '-') .
109 /* ----------------------------------------------------------------------- */
112 * If the session is expired during a post this restores the compose session
115 //$session_expired = false;
116 if (session_is_registered('session_expired_post')) {
117 global $session_expired_post, $session_expired;
119 * extra check for username so we don't display previous post data from
120 * another user during this session.
122 if ($session_expired_post['username'] != $username) {
123 session_unregister('session_expired_post');
124 session_unregister('session_expired');
126 foreach ($session_expired_post as $postvar => $val) {
136 $session_expired = true;
138 session_unregister('session_expired_post');
139 session_unregister('session_expired');
140 if (!isset($mailbox)) {
143 if ($compose_new_win == '1') {
144 compose_Header($color, $mailbox);
146 displayPageHeader($color, $mailbox);
148 showInputForm($session, false);
152 if (!isset($attachments)) {
153 $attachments = array();
154 sqsession_register(array(), 'attachments');
157 if (!isset($composesession)) {
159 sqsession_register(0,'composesession');
162 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
163 $session = "$composesession" +
1;
164 $composesession = $session;
165 sqsession_register($composesession,'composesession');
168 if (!isset($compose_messages)) {
169 $compose_messages = array();
171 if (!array_key_exists($session, $compose_messages)) {
172 $composeMessage = new message();
173 $rfc822_header = new Rfc822Header();
174 $composeMessage->rfc822_header
= $rfc822_header;
175 $composeMessage->reply_rfc822_header
= '';
176 $compose_messages[$session] = $composeMessage;
178 sqsession_register($compose_messages,'compose_messages');
180 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
186 * Set $default_charset to correspond with the user's selection
187 * of language interface.
190 $composeMessage=$compose_messages[$session];
191 $Result = sendMessage($composeMessage, true);
193 if (! sendMessage($composeMessage, true)) {
194 showInputForm($session);
197 $draft_message = _("Draft Email Saved");
198 /* If this is a resumed draft, then delete the original */
199 if(isset($delete_draft)) {
200 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
201 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
205 if ($compose_new_win == '1') {
206 Header("Location: compose.php?saved_draft=yes&session=$composesession");
210 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
211 "&startMessage=1¬e=".urlencode($draft_message));
219 if (isset($HTTP_POST_FILES['attachfile']) &&
220 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
221 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
222 $AttachFailure = saveAttachedFiles($session);
224 if (checkInput(false) && !isset($AttachFailure)) {
225 $urlMailbox = urlencode (trim($mailbox));
226 if (! isset($passed_id)) {
230 * Set $default_charset to correspond with the user's selection
231 * of language interface.
235 * This is to change all newlines to \n
236 * We'll change them to \r\n later (in the sendMessage function)
238 $body = str_replace("\r\n", "\n", $body);
239 $body = str_replace("\r", "\n", $body);
242 * Rewrap $body so that no line is bigger than $editor_size
243 * This should only really kick in the sqWordWrap function
244 * if the browser doesn't support "VIRTUAL" as the wrap type.
246 $body = explode("\n", $body);
248 foreach ($body as $line) {
249 if( $line <> '-- ' ) {
250 $line = rtrim($line);
252 if (strlen($line) <= $editor_size +
1) {
253 $newBody .= $line . "\n";
255 sqWordWrap($line, $editor_size);
256 $newBody .= $line . "\n";
260 do_hook('compose_send');
261 $composeMessage=$compose_messages[$session];
262 $Result = sendMessage($composeMessage);
264 showInputForm($session);
267 if ( isset($delete_draft)) {
268 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
269 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
272 if ($compose_new_win == '1') {
273 Header("Location: compose.php?mail_sent=yes");
276 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
281 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
284 if ($compose_new_win == '1') {
285 compose_Header($color, $mailbox);
288 displayPageHeader($color, $mailbox);
290 if (isset($AttachFailure)) {
291 plain_error_message(_("Could not move/copy file. File not attached"),
295 showInputForm($session);
296 /* sqimap_logout($imapConnection); */
298 } elseif (isset($html_addr_search_done)) {
299 if ($compose_new_win == '1') {
300 compose_Header($color, $mailbox);
303 displayPageHeader($color, $mailbox);
306 if (isset($send_to_search) && is_array($send_to_search)) {
307 foreach ($send_to_search as $k => $v) {
308 if (substr($k, 0, 1) == 'T') {
314 elseif (substr($k, 0, 1) == 'C') {
320 elseif (substr($k, 0, 1) == 'B') {
322 $send_to_bcc .= ', ';
328 showInputForm($session);
329 } elseif (isset($html_addr_search)) {
330 if (isset($HTTP_POST_FILES['attachfile']) &&
331 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
332 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
333 if (saveAttachedFiles($session)) {
334 plain_error_message(_("Could not move/copy file. File not attached"), $color);
338 * I am using an include so as to elminiate an extra unnecessary
339 * click. If you can think of a better way, please implement it.
341 include_once('./addrbook_search_html.php');
342 } elseif (isset($attach)) {
343 if (saveAttachedFiles($session)) {
344 plain_error_message(_("Could not move/copy file. File not attached"), $color);
346 if ($compose_new_win == '1') {
347 compose_Header($color, $mailbox);
350 displayPageHeader($color, $mailbox);
352 showInputForm($session);
354 elseif (isset($sigappend)) {
355 $idents = getPref($data_dir, $username, 'identities', 0);
357 if ($identity == 'default') {
362 $signature = getSig($data_dir, $username, $no);
364 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
365 if ($compose_new_win == '1') {
366 compose_Header($color, $mailbox);
368 displayPageHeader($color, $mailbox);
370 showInputForm($session);
371 } elseif (isset($do_delete)) {
372 if ($compose_new_win == '1') {
373 compose_Header($color, $mailbox);
376 displayPageHeader($color, $mailbox);
379 if (isset($delete) && is_array($delete)) {
380 $composeMessage = $compose_messages[$session];
381 foreach($delete as $index) {
382 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
383 unlink ($attached_file);
384 unset ($composeMessage->entities
[$index]);
386 $new_entities = array();
387 foreach ($composeMessage->entities
as $entity) {
388 $new_entities[] = $entity;
390 $composeMessage->entities
= $new_entities;
391 $compose_messages[$session] = $composeMessage;
392 sqsession_register($compose_messages, 'compose_messages');
393 // setPref($data_dir, $username, 'attachments', serialize($attachments));
395 showInputForm($session);
398 * This handles the default case as well as the error case
399 * (they had the same code) --> if (isset($smtpErrors))
402 if ($compose_new_win == '1') {
403 compose_Header($color, $mailbox);
405 displayPageHeader($color, $mailbox);
410 if (!isset($passed_ent_id)) {
413 if (!isset($passed_id)) {
416 if (!isset($mailbox)) {
419 if (!isset($action)) {
423 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
425 /* in case the origin is not read_body.php */
426 if (isset($send_to)) {
427 $values['send_to'] = $send_to;
429 if (isset($send_to_cc)) {
430 $values['send_to_cc'] = $send_to_cc;
432 if (isset($send_to_bcc)) {
433 $values['send_to_bcc'] = $send_to_bcc;
435 showInputForm($session, $values);
440 /**************** Only function definitions go below *************/
443 /* This function is used when not sending or adding attachments */
444 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
445 global $editor_size, $default_use_priority, $body,
446 $use_signature, $composesession, $data_dir, $username,
447 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
450 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
454 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
457 sqimap_mailbox_select($imapConnection, $mailbox);
458 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
461 if ($passed_ent_id) {
462 /* redefine the messsage in case of message/rfc822 */
463 $message = $message->getEntity($passed_ent_id);
464 /* message is an entity which contains the envelope and type0=message
465 * and type1=rfc822. The actual entities are childs from
466 * $message->entities[0]. That's where the encoding and is located
469 $entities = $message->entities
[0]->findDisplayEntity
470 (array(), $alt_order = array('text/plain'));
471 if (!count($entities)) {
472 $entities = $message->entities
[0]->findDisplayEntity
473 (array(), $alt_order = array('text/plain','html/plain'));
475 $orig_header = $message->rfc822_header
; /* here is the envelope located */
476 /* redefine the message for picking up the attachments */
477 $message = $message->entities
[0];
480 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
481 if (!count($entities)) {
482 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
484 $orig_header = $message->rfc822_header
;
487 $encoding = $message->header
->encoding
;
488 $type0 = $message->type0
;
489 $type1 = $message->type1
;
490 foreach ($entities as $ent) {
491 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
492 $body_part_entity = $message->getEntity($ent);
493 $bodypart = decodeBody($unencoded_bodypart,
494 $body_part_entity->header
->encoding
);
495 if ($type1 == 'html') {
496 $bodypart = strip_tags($bodypart);
500 if ($default_use_priority) {
501 $mailprio = substr($orig_header->priority
,0,1);
508 //ClearAttachments($session);
511 $idents = getPref($data_dir, $username, 'identities');
512 $from_o = $orig_header->from
;
513 if (is_object($from_o)) {
514 $orig_from = $from_o->getAddress();
518 if (!empty($idents) && $idents > 1) {
519 for ($i = 1; $i < $idents; $i++
) {
520 $enc_from_name = '"'.
524 '" <' . getPref($data_dir, $username,
525 'email_address' . $i) . '>';
526 if ($enc_from_name == $orig_from) {
535 $use_signature = FALSE;
536 $send_to = $orig_header->getAddr_s('to');
537 $send_to_cc = $orig_header->getAddr_s('cc');
538 $send_to_bcc = $orig_header->getAddr_s('bcc');
539 $subject = decodeHeader($orig_header->subject
);
541 $body_ary = explode("\n", $body);
542 $cnt = count($body_ary) ;
544 for ($i=0; $i < $cnt; $i++
) {
545 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
546 sqWordWrap($body_ary[$i], $editor_size );
547 $body .= $body_ary[$i] . "\n";
549 unset($body_ary[$i]);
552 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
554 case ('edit_as_new'):
555 $send_to = $orig_header->getAddr_s('to');
556 $send_to_cc = $orig_header->getAddr_s('cc');
557 $send_to_bcc = $orig_header->getAddr_s('bcc');
558 $subject = decodeHeader($orig_header->subject
);
559 $mailprio = $orig_header->priority
;
561 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
566 $subject = decodeHeader($orig_header->subject
);
567 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
568 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
569 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
570 $subject = '[Fwd: ' . $subject . ']';
572 $body = getforwardHeader($orig_header) . $body;
574 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
576 case ('forward_as_attachment'):
577 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
581 $send_to_cc = replyAllString($orig_header);
583 $send_to = $orig_header->reply_to
;
584 if (is_object($send_to)) {
585 $send_to = $send_to->getAddr_s('reply_to');
587 $send_to = $orig_header->getAddr_s('from');
589 $subject = decodeHeader($orig_header->subject
);
590 $subject = str_replace('"', "'", $subject);
591 $subject = trim($subject);
592 if (substr(strtolower($subject), 0, 3) != 're:') {
593 $subject = 'Re: ' . $subject;
595 /* this corrects some wrapping/quoting problems on replies */
596 $rewrap_body = explode("\n", $body);
598 $body = getReplyCitation($orig_header->from
->personal
);
599 $cnt = count($rewrap_body);
600 for ($i=0;$i<$cnt;$i++
) {
601 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
602 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
604 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
606 $body .= '> ' . $rewrap_body[$i] . "\n";
608 unset($rewrap_body[$i]);
610 $composeMessage->reply_rfc822_header
= $orig_header;
615 $compose_messages[$session] = $composeMessage;
616 sqsession_register($compose_messages, 'compose_messages');
618 sqimap_logout($imapConnection);
620 $ret = array( 'send_to' => $send_to,
621 'send_to_cc' => $send_to_cc,
622 'send_to_bcc' => $send_to_bcc,
623 'subject' => $subject,
624 'mailprio' => $mailprio,
626 'identity' => $identity );
629 } /* function newMail() */
631 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
632 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
633 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
634 if (!count($message->entities
) ||
635 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
636 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
637 switch ($message->type0
) {
639 if ($message->type1
== 'rfc822') {
640 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
641 if ($filename == "") {
642 $filename = "untitled-".$message->entity_id
.'.eml';
645 $filename = decodeHeader($message->getFilename());
649 $filename = decodeHeader($message->getFilename());
652 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
653 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
654 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
657 $localfilename = GenerateRandomString(32, '', 7);
658 $full_localfilename = "$hashed_attachment_dir/$localfilename";
659 while (file_exists($full_localfilename)) {
660 $localfilename = GenerateRandomString(32, '', 7);
661 $full_localfilename = "$hashed_attachment_dir/$localfilename";
663 $message->att_local_name
= $full_localfilename;
664 if (!$message->mime_header
) { /* temporary hack */
665 $message->mime_header
= $message->header
;
668 $composeMessage->addEntity($message);
670 /* Write Attachment to file */
671 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
672 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
673 $passed_id, $message->entity_id
),
674 $message->header
->encoding
));
678 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
679 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
682 // setPref($data_dir, $username, 'attachments', serialize($attachments));
683 return $composeMessage;
686 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
687 $passed_ent_id='', $imapConnection) {
688 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
689 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
690 if (!$passed_ent_id) {
691 $body_a = sqimap_run_command($imapConnection,
692 'FETCH '.$passed_id.' RFC822',
693 TRUE, $response, $readmessage,
696 $body_a = sqimap_run_command($imapConnection,
697 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
698 TRUE, $response, $readmessage, $uid_support);
699 $message = $message->parent
;
701 if ($response = 'OK') {
702 $subject = encodeHeader($message->rfc822_header
->subject
);
703 array_shift($body_a);
704 $body = implode('', $body_a) . "\r\n";
706 $localfilename = GenerateRandomString(32, 'FILE', 7);
707 $full_localfilename = "$hashed_attachment_dir/$localfilename";
709 $fp = fopen( $full_localfilename, 'w');
712 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
713 $full_localfilename);
715 return $composeMessage;
718 function showInputForm ($session, $values=false) {
719 global $send_to, $send_to_cc, $body,
720 $passed_body, $color, $use_signature, $signature, $prefix_sig,
721 $editor_size, $attachments, $subject, $newmail,
722 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
723 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
724 $username, $data_dir, $identity, $draft_id, $delete_draft,
725 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
726 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
727 $username, $compose_messages;
729 $composeMessage = $compose_messages[$session];
731 $subject = decodeHeader($subject, false);
733 $send_to = $values['send_to'];
734 $send_to_cc = $values['send_to_cc'];
735 $send_to_bcc = $values['send_to_bcc'];
736 $subject = $values['subject'];
737 $mailprio = $values['mailprio'];
738 $body = $values['body'];
739 $identity = $values['identity'];
742 if ($use_javascript_addr_book) {
743 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
744 'function open_abook() { ' . "\n" .
745 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
746 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
747 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
748 ' nwin.opener = document.windows;' . "\n" .
750 '// --></SCRIPT>' . "\n\n";
753 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
754 'ENCTYPE="multipart/form-data"';
755 do_hook("compose_form");
760 if ($action == 'draft') {
761 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
763 if (isset($delete_draft)) {
764 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
766 if (isset($session)) {
767 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
770 if (isset($passed_id)) {
771 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
774 if ($saved_draft == 'yes') {
775 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
777 if ($mail_sent == 'yes') {
778 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
780 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
781 if ($compose_new_win == '1') {
782 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
783 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
785 if ($location_of_buttons == 'top') {
786 showComposeButtonRow();
789 $idents = getPref($data_dir, $username, 'identities', 0);
791 echo ' <TR>' . "\n" .
792 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
795 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
796 '<select name=identity>' . "\n" .
797 '<option value=default>' .
798 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
799 $em = getPref($data_dir, $username, 'email_address');
801 echo htmlspecialchars(' <' . $em . '>') . "\n";
803 for ($i = 1; $i < $idents; $i ++
) {
804 echo '<option value="' . $i . '"';
805 if (isset($identity) && $identity == $i) {
808 echo '>' . htmlspecialchars(getPref($data_dir, $username,
810 $em = getPref($data_dir, $username, 'email_address' . $i);
812 echo htmlspecialchars(' <' . $em . '>') . "\n";
816 echo '</select>' . "\n" .
820 echo ' <TR>' . "\n" .
821 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
823 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
824 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
825 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
829 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
831 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
832 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
833 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
837 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
839 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
840 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
841 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
842 '</TD></TR>' . "\n" .
844 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
846 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
847 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
848 htmlspecialchars($subject) . '">';
849 echo '</td></tr>' . "\n\n";
851 if ($location_of_buttons == 'between') {
852 showComposeButtonRow();
854 if ($compose_new_win == '1') {
855 echo ' <TR>' . "\n" .
856 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
857 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
858 $editor_size . '" WRAP="VIRTUAL">';
861 echo ' <TR>' . "\n" .
862 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
863 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
864 $editor_size . '" WRAP="VIRTUAL">';
866 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
867 if ($sig_first == '1') {
868 if ($charset == 'iso-2022-jp') {
869 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
871 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
873 echo "\n\n".htmlspecialchars($body);
876 echo "\n\n".htmlspecialchars($body);
877 if ($charset == 'iso-2022-jp') {
878 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
880 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
885 echo htmlspecialchars($body);
887 echo '</TEXTAREA><BR>' . "\n" .
891 if ($location_of_buttons == 'bottom') {
892 showComposeButtonRow();
894 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
895 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
896 ' <BR><BR>' .
897 ' </TD></TR>' . "\n";
900 /* This code is for attachments */
901 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
903 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
905 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
907 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
910 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
911 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
912 ' <input type="submit" name="attach"' .
913 ' value="' . _("Add") .'">' . "\n" .
919 foreach ($composeMessage->entities
as $key => $attachment) {
920 $attached_file = $attachment->att_local_name
;
921 if ($attachment->att_local_name ||
$attachment->body_part
) {
922 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
923 $type = $attachment->mime_header
->type0
.'/'.
924 $attachment->mime_header
->type1
;
925 $s_a[] = '<input type="checkbox" name="delete[]" value="' .
926 $key . "\">\n" . $attached_filename . ' - ' . $type .
927 ' ('.show_readable_size( filesize( $attached_file ) )
932 foreach ($s_a as $s) {
933 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
935 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
936 _("Delete selected attachments") . "\">\n" .
939 echo ' </table></td></tr>' .
943 /* End of attachment code */
944 if ($compose_new_win == '1') {
945 echo '</TABLE>'."\n";
947 echo '</TABLE>' . "\n" .
948 '<input type="hidden" name="username" value="'. $username . "\">\n" .
949 '<input type=hidden name=action value=' . $action . ">\n" .
950 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
953 do_hook('compose_bottom');
954 echo '</BODY></HTML>' . "\n";
958 function showComposeButtonRow() {
959 global $use_javascript_addr_book, $save_as_draft,
960 $default_use_priority, $mailprio, $default_use_mdn,
961 $request_mdn, $request_dr,
962 $data_dir, $username;
964 echo " <TR><TD>\n</TD><TD>\n";
965 if ($default_use_priority) {
966 if(!isset($mailprio)) {
969 echo _("Priority") .': <select name="mailprio">'.
970 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
971 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
972 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
975 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
976 if ($default_use_mdn) {
977 if ($mdn_user_support) {
978 echo "\n\t". _("Receipt") .': '.
979 '<input type="checkbox" name="request_mdn" value=1'.
980 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
981 ' <input type="checkbox" name="request_dr" value=1'.
982 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
986 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
987 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
988 if ($use_javascript_addr_book) {
989 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
990 " <input type=button value=\\\""._("Addresses").
991 "\\\" onclick='javascript:open_abook();'>\");".
992 " // --></SCRIPT><NOSCRIPT>\n".
993 " <input type=submit name=\"html_addr_search\" value=\"".
994 _("Addresses")."\">".
997 echo " <input type=submit name=\"html_addr_search\" value=\"".
998 _("Addresses")."\">";
1001 if ($save_as_draft) {
1002 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1005 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
1006 do_hook('compose_button_row');
1008 echo " </TD></TR>\n\n";
1011 function checkInput ($show) {
1013 * I implemented the $show variable because the error messages
1014 * were getting sent before the page header. So, I check once
1015 * using $show=false, and then when i'm ready to display the error
1016 * message, show=true
1018 global $body, $send_to, $send_to_bcc, $subject, $color;
1020 if ($send_to == '' && $send_to_bcc == '') {
1022 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1027 } /* function checkInput() */
1030 /* True if FAILURE */
1031 function saveAttachedFiles($session) {
1032 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1033 $data_dir, $compose_messages;
1035 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1036 $localfilename = GenerateRandomString(32, '', 7);
1037 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1038 while (file_exists($full_localfilename)) {
1039 $localfilename = GenerateRandomString(32, '', 7);
1040 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1043 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1044 if (function_exists("move_uploaded_file")) {
1045 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1049 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1054 $message = $compose_messages[$session];
1055 $type = strtolower($HTTP_POST_FILES['attachfile']['type']);
1056 $name = $HTTP_POST_FILES['attachfile']['name'];
1057 $message->initAttachment($type, $name, $full_localfilename);
1058 $compose_messages[$session] = $message;
1061 function ClearAttachments($composeMessage) {
1062 if ($composeMessage->att_local_name
) {
1063 $attached_file = $composeMessage->att_local_name
;
1064 if (file_exists($attached_file)) {
1065 unlink($attached_file);
1068 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1069 ClearAttachments($composeMessage->entities
[$i]);
1075 function getReplyCitation($orig_from) {
1076 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1078 /* First, return an empty string when no citation style selected. */
1079 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1083 /* Make sure our final value isn't an empty string. */
1084 if ($orig_from == '') {
1088 /* Otherwise, try to select the desired citation style. */
1089 switch ($reply_citation_style) {
1092 $end = ' ' . _("said") . ':';
1095 $start = '<' . _("quote") . ' ' . _("who") . '="';
1098 case 'user-defined':
1099 $start = $reply_citation_start .
1100 ($reply_citation_start == '' ?
'' : ' ');
1101 $end = $reply_citation_end;
1107 /* Build and return the citation string. */
1108 return ($start . $orig_from . $end . "\n");
1111 /* temporary function to make use of the deliver class.
1112 In the future the responsable backend should be automaticly loaded
1113 and conf.pl should show a list of available backends.
1114 The message also should be constructed by the message class.
1117 function sendMessage($composeMessage, $draft=false) {
1118 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1119 $username, $popuser, $usernamedata, $identity, $data_dir,
1120 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1122 global $imapServerAddress, $imapPort, $sent_folder, $key;
1124 $rfc822_header = $composeMessage->rfc822_header
;
1125 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
1126 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
1127 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
1128 $rfc822_header->priority
= $mailprio;
1129 $rfc822_header->subject
= $subject;
1130 $special_encoding='';
1131 if (strtolower($default_charset) == 'iso-2022-jp') {
1132 if (mb_detect_encoding($body) == 'ASCII') {
1133 $special_encoding = '8bit';
1135 $body = mb_convert_encoding($body, 'JIS');
1136 $special_encoding = '7bit';
1139 $composeMessage->setBody($body);
1141 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1142 $popuser = $usernamedata[1];
1143 $domain = $usernamedata[2];
1144 unset($usernamedata);
1146 $popuser = $username;
1149 if (isset($identity) && $identity != 'default') {
1150 $from_mail = getPref($data_dir, $username,
1151 'email_address' . $identity);
1152 $full_name = getPref($data_dir, $username,
1153 'full_name' . $identity);
1154 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
1155 $reply_to = getPref($data_dir, $username,
1156 'reply_to' . $identity);
1158 $from_mail = getPref($data_dir, $username, 'email_address');
1159 $full_name = getPref($data_dir, $username, 'full_name');
1160 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
1161 $reply_to = getPref($data_dir, $username,'reply_to');
1164 $from_addr = "$popuser@$domain";
1165 $from_mail = $from_addr;
1167 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1169 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1171 /* Receipt: On Read */
1172 if (isset($request_mdn) && $request_mdn) {
1173 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1175 /* Receipt: On Delivery */
1176 if (isset($request_dr) && $request_dr) {
1177 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1179 /* multipart messages */
1180 if (count($composeMessage->entities
)) {
1181 $message_body = new Message();
1182 $message_body->body_part
= $composeMessage->body_part
;
1183 $composeMessage->body_part
= '';
1184 $mime_header = new MessageHeader
;
1185 $mime_header->type0
= 'text';
1186 $mime_header->type1
= 'plain';
1187 if ($special_encoding) {
1188 $mime_header->encoding
= $special_encoding;
1190 $mime_header->encoding
= 'us-ascii';
1192 if ($default_charset) {
1193 $mime_header->parameters
['charset'] = $default_charset;
1195 $message_body->mime_header
= $mime_header;
1196 array_unshift($composeMessage->entities
, $message_body);
1197 $content_type = new ContentType('multipart/mixed');
1199 $content_type = new ContentType('text/plain');
1201 if ($default_charset) {
1202 $content_type->properties
['charset']=$default_charset;
1205 $rfc822_header->content_type
= $content_type;
1206 $composeMessage->rfc822_header
= $rfc822_header;
1208 if (!$useSendmail && !$draft) {
1209 require_once('../class/deliver/Deliver_SMTP.class.php');
1210 $deliver = new Deliver_SMTP();
1211 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
1212 if ($use_authenticated_smtp) {
1213 global $key, $onetimepad;
1215 $pass = OneTimePadDecrypt($key, $onetimepad);
1220 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1221 $stream = $deliver->initStream($composeMessage,$domain,0,
1222 $smtpServerAddress, $smtpPort, $authPop);
1223 } elseif (!$draft) {
1224 require_once('../class/deliver/Deliver_SentMail.class.php');
1225 global $sendmail_path;
1226 $deliver = new Deliver_SendMail();
1227 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1229 global $draft_folder;
1230 require_once('../class/deliver/Deliver_IMAP.class.php');
1231 $imap_deliver = new Deliver_IMAP();
1232 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1234 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1235 require_once('../class/deliver/Deliver_IMAP.class.php');
1236 $imap_deliver = new Deliver_IMAP();
1237 $length = $imap_deliver->mail($composeMessage);
1238 sqimap_append ($imap_stream, $draft_folder, $length);
1239 $imap_deliver->mail($composeMessage, $imap_stream);
1240 sqimap_append_done ($imap_stream);
1241 sqimap_logout($imap_stream);
1242 unset ($imap_deliver);
1249 $length = $deliver->mail($composeMessage, $stream);
1250 $succes = $deliver->finalizeStream($stream);
1253 $msg = $deliver->dlv_msg
. '<br>Server replied: '.$deliver->dlv_ret_nr
;
1254 plain_error_message($msg, $color);
1257 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1259 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1260 sqimap_append ($imap_stream, $sent_folder, $length);
1261 require_once('../class/deliver/Deliver_IMAP.class.php');
1262 $imap_deliver = new Deliver_IMAP();
1263 $imap_deliver->mail($composeMessage, $imap_stream);
1264 sqimap_append_done ($imap_stream);
1265 unset ($imap_deliver);
1267 global $passed_id, $mailbox, $action;
1268 ClearAttachments($composeMessage);
1269 if ($action == 'reply' ||
$action == 'reply_all') {
1270 sqimap_mailbox_select ($imap_stream, $mailbox);
1271 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1273 sqimap_logout($imap_stream);