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')) {
185 include_once ('../src/draft_actions.php');
186 if (! isset($passed_id)) {
192 if (! isset($mailprio)) {
195 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
196 showInputForm($session);
199 $draft_message = _("Draft Email Saved");
200 /* If this is a resumed draft, then delete the original */
201 if(isset($delete_draft)) {
202 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
203 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
207 if ($compose_new_win == '1') {
208 Header("Location: compose.php?saved_draft=yes&session=$composesession");
212 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
213 "&startMessage=1¬e=".urlencode($draft_message));
221 if (isset($HTTP_POST_FILES['attachfile']) &&
222 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
223 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
224 $AttachFailure = saveAttachedFiles($session);
226 if (checkInput(false) && !isset($AttachFailure)) {
227 $urlMailbox = urlencode (trim($mailbox));
228 if (! isset($passed_id)) {
232 * Set $default_charset to correspond with the user's selection
233 * of language interface.
238 * This is to change all newlines to \n
239 * We'll change them to \r\n later (in the sendMessage function)
241 $body = str_replace("\r\n", "\n", $body);
242 $body = str_replace("\r", "\n", $body);
245 * Rewrap $body so that no line is bigger than $editor_size
246 * This should only really kick in the sqWordWrap function
247 * if the browser doesn't support "VIRTUAL" as the wrap type.
249 $body = explode("\n", $body);
251 foreach ($body as $line) {
252 if( $line <> '-- ' ) {
253 $line = rtrim($line);
255 if (strlen($line) <= $editor_size +
1) {
256 $newBody .= $line . "\n";
258 sqWordWrap($line, $editor_size);
259 $newBody .= $line . "\n";
263 do_hook('compose_send');
264 $composeMessage=$compose_messages[$session];
265 $Result = sendMessage($composeMessage);
267 showInputForm($session);
270 if ( isset($delete_draft)) {
271 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
272 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
275 if ($compose_new_win == '1') {
276 Header("Location: compose.php?mail_sent=yes");
279 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
284 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
287 if ($compose_new_win == '1') {
288 compose_Header($color, $mailbox);
291 displayPageHeader($color, $mailbox);
293 if (isset($AttachFailure)) {
294 plain_error_message(_("Could not move/copy file. File not attached"),
298 showInputForm($session);
299 /* sqimap_logout($imapConnection); */
301 } elseif (isset($html_addr_search_done)) {
302 if ($compose_new_win == '1') {
303 compose_Header($color, $mailbox);
306 displayPageHeader($color, $mailbox);
309 if (isset($send_to_search) && is_array($send_to_search)) {
310 foreach ($send_to_search as $k => $v) {
311 if (substr($k, 0, 1) == 'T') {
317 elseif (substr($k, 0, 1) == 'C') {
323 elseif (substr($k, 0, 1) == 'B') {
325 $send_to_bcc .= ', ';
331 showInputForm($session);
332 } elseif (isset($html_addr_search)) {
333 if (isset($HTTP_POST_FILES['attachfile']) &&
334 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
335 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
336 if (saveAttachedFiles($session)) {
337 plain_error_message(_("Could not move/copy file. File not attached"), $color);
341 * I am using an include so as to elminiate an extra unnecessary
342 * click. If you can think of a better way, please implement it.
344 include_once('./addrbook_search_html.php');
345 } elseif (isset($attach)) {
346 if (saveAttachedFiles($session)) {
347 plain_error_message(_("Could not move/copy file. File not attached"), $color);
349 if ($compose_new_win == '1') {
350 compose_Header($color, $mailbox);
353 displayPageHeader($color, $mailbox);
355 showInputForm($session);
357 elseif (isset($sigappend)) {
358 $idents = getPref($data_dir, $username, 'identities', 0);
360 if ($identity == 'default') {
365 $signature = getSig($data_dir, $username, $no);
367 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
368 if ($compose_new_win == '1') {
369 compose_Header($color, $mailbox);
371 displayPageHeader($color, $mailbox);
373 showInputForm($session);
374 } elseif (isset($do_delete)) {
375 if ($compose_new_win == '1') {
376 compose_Header($color, $mailbox);
379 displayPageHeader($color, $mailbox);
382 if (isset($delete) && is_array($delete)) {
383 $composeMessage = $compose_messages[$session];
384 foreach($delete as $index) {
385 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
386 unlink ($attached_file);
387 unset ($composeMessage->entities
[$index]);
389 $new_entities = array();
390 foreach ($composeMessage->entities
as $entity) {
391 $new_entities[] = $entity;
393 $composeMessage->entities
= $new_entities;
394 $compose_messages[$session] = $composeMessage;
395 sqsession_register($compose_messages, 'compose_messages');
396 // setPref($data_dir, $username, 'attachments', serialize($attachments));
398 showInputForm($session);
401 * This handles the default case as well as the error case
402 * (they had the same code) --> if (isset($smtpErrors))
405 if ($compose_new_win == '1') {
406 compose_Header($color, $mailbox);
408 displayPageHeader($color, $mailbox);
413 if (!isset($passed_ent_id)) {
416 if (!isset($passed_id)) {
419 if (!isset($mailbox)) {
422 if (!isset($action)) {
426 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
428 /* in case the origin is not read_body.php */
429 if (isset($send_to)) {
430 $values['send_to'] = $send_to;
432 if (isset($send_to_cc)) {
433 $values['send_to_cc'] = $send_to_cc;
435 if (isset($send_to_bcc)) {
436 $values['send_to_bcc'] = $send_to_bcc;
438 showInputForm($session, $values);
443 /**************** Only function definitions go below *************/
446 /* This function is used when not sending or adding attachments */
447 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
448 global $editor_size, $default_use_priority, $body,
449 $use_signature, $composesession, $data_dir, $username,
450 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
453 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
457 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
460 sqimap_mailbox_select($imapConnection, $mailbox);
461 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
464 if ($passed_ent_id) {
465 /* redefine the messsage in case of message/rfc822 */
466 $message = $message->getEntity($passed_ent_id);
467 /* message is an entity which contains the envelope and type0=message
468 * and type1=rfc822. The actual entities are childs from
469 * $message->entities[0]. That's where the encoding and is located
472 $entities = $message->entities
[0]->findDisplayEntity
473 (array(), $alt_order = array('text/plain'));
474 if (!count($entities)) {
475 $entities = $message->entities
[0]->findDisplayEntity
476 (array(), $alt_order = array('text/plain','html/plain'));
478 $orig_header = $message->rfc822_header
; /* here is the envelope located */
479 /* redefine the message for picking up the attachments */
480 $message = $message->entities
[0];
483 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
484 if (!count($entities)) {
485 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
487 $orig_header = $message->rfc822_header
;
490 $encoding = $message->header
->encoding
;
491 $type0 = $message->type0
;
492 $type1 = $message->type1
;
493 foreach ($entities as $ent) {
494 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
495 $body_part_entity = $message->getEntity($ent);
496 $bodypart = decodeBody($unencoded_bodypart,
497 $body_part_entity->header
->encoding
);
498 if ($type1 == 'html') {
499 $bodypart = strip_tags($bodypart);
503 if ($default_use_priority) {
504 $mailprio = substr($orig_header->priority
,0,1);
511 //ClearAttachments($session);
514 $idents = getPref($data_dir, $username, 'identities');
515 $from_o = $orig_header->from
;
516 if (is_object($from_o)) {
517 $orig_from = $from_o->getAddress();
521 if (!empty($idents) && $idents > 1) {
522 for ($i = 1; $i < $idents; $i++
) {
523 $enc_from_name = '"'.
527 '" <' . getPref($data_dir, $username,
528 'email_address' . $i) . '>';
529 if ($enc_from_name == $orig_from) {
538 $use_signature = FALSE;
539 $send_to = $orig_header->getAddr_s('to');
540 $send_to_cc = $orig_header->getAddr_s('cc');
541 $send_to_bcc = $orig_header->getAddr_s('bcc');
542 $subject = decodeHeader($orig_header->subject
);
544 $body_ary = explode("\n", $body);
545 $cnt = count($body_ary) ;
547 for ($i=0; $i < $cnt; $i++
) {
548 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
549 sqWordWrap($body_ary[$i], $editor_size );
550 $body .= $body_ary[$i] . "\n";
552 unset($body_ary[$i]);
555 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
557 case ('edit_as_new'):
558 $send_to = $orig_header->getAddr_s('to');
559 $send_to_cc = $orig_header->getAddr_s('cc');
560 $send_to_bcc = $orig_header->getAddr_s('bcc');
561 $subject = decodeHeader($orig_header->subject
);
562 $mailprio = $orig_header->priority
;
564 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
569 $subject = decodeHeader($orig_header->subject
);
570 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
571 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
572 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
573 $subject = '[Fwd: ' . $subject . ']';
575 $body = getforwardHeader($orig_header) . $body;
577 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
579 case ('forward_as_attachment'):
580 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
584 $send_to_cc = replyAllString($orig_header);
586 $send_to = $orig_header->reply_to
;
587 if (is_object($send_to)) {
588 $send_to = $send_to->getAddr_s('reply_to');
590 $send_to = $orig_header->getAddr_s('from');
592 $subject = decodeHeader($orig_header->subject
);
593 $subject = str_replace('"', "'", $subject);
594 $subject = trim($subject);
595 if (substr(strtolower($subject), 0, 3) != 're:') {
596 $subject = 'Re: ' . $subject;
598 /* this corrects some wrapping/quoting problems on replies */
599 $rewrap_body = explode("\n", $body);
601 $body = getReplyCitation($orig_header->from
->personal
);
602 $cnt = count($rewrap_body);
603 for ($i=0;$i<$cnt;$i++
) {
604 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
605 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
607 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
609 $body .= '> ' . $rewrap_body[$i] . "\n";
611 unset($rewrap_body[$i]);
613 $composeMessage->reply_rfc822_header
= $orig_header;
618 $compose_messages[$session] = $composeMessage;
619 sqsession_register($compose_messages, 'compose_messages');
621 sqimap_logout($imapConnection);
623 $ret = array( 'send_to' => $send_to,
624 'send_to_cc' => $send_to_cc,
625 'send_to_bcc' => $send_to_bcc,
626 'subject' => $subject,
627 'mailprio' => $mailprio,
629 'identity' => $identity );
632 } /* function newMail() */
634 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
635 global $attachment_dir, $username, $data_dir;
636 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
637 if (!count($message->entities
) ||
638 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
639 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
640 switch ($message->type0
) {
642 if ($message->type1
== 'rfc822') {
643 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
644 if ($filename == "") {
645 $filename = "untitled-".$message->entity_id
.'.eml';
648 $filename = decodeHeader($message->getFilename());
652 $filename = decodeHeader($message->getFilename());
655 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
656 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
657 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
660 $localfilename = GenerateRandomString(32, '', 7);
661 $full_localfilename = "$hashed_attachment_dir/$localfilename";
662 while (file_exists($full_localfilename)) {
663 $localfilename = GenerateRandomString(32, '', 7);
664 $full_localfilename = "$hashed_attachment_dir/$localfilename";
666 $message->att_local_name
= $full_localfilename;
667 if (!$message->mime_header
) { /* temporary hack */
668 $message->mime_header
= $message->header
;
671 $composeMessage->addEntity($message);
673 /* Write Attachment to file */
674 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
675 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
676 $passed_id, $message->entity_id
),
677 $message->header
->encoding
));
681 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
682 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
685 // setPref($data_dir, $username, 'attachments', serialize($attachments));
686 return $composeMessage;
689 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
690 $passed_ent_id='', $imapConnection) {
691 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
692 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
693 if (!$passed_ent_id) {
694 $body_a = sqimap_run_command($imapConnection,
695 'FETCH '.$passed_id.' RFC822',
696 TRUE, $response, $readmessage,
699 $body_a = sqimap_run_command($imapConnection,
700 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
701 TRUE, $response, $readmessage, $uid_support);
702 $message = $message->parent
;
704 if ($response = 'OK') {
705 $subject = encodeHeader($message->rfc822_header
->subject
);
706 array_shift($body_a);
707 $body = implode('', $body_a) . "\r\n";
709 $localfilename = GenerateRandomString(32, 'FILE', 7);
710 $full_localfilename = "$hashed_attachment_dir/$localfilename";
712 $fp = fopen( $full_localfilename, 'w');
715 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
716 $full_localfilename);
718 return $composeMessage;
721 function showInputForm ($session, $values=false) {
722 global $send_to, $send_to_cc, $body,
723 $passed_body, $color, $use_signature, $signature, $prefix_sig,
724 $editor_size, $attachments, $subject, $newmail,
725 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
726 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
727 $username, $data_dir, $identity, $draft_id, $delete_draft,
728 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
729 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
730 $username, $compose_messages;
732 $composeMessage = $compose_messages[$session];
734 $subject = decodeHeader($subject, false);
736 $send_to = $values['send_to'];
737 $send_to_cc = $values['send_to_cc'];
738 $send_to_bcc = $values['send_to_bcc'];
739 $subject = $values['subject'];
740 $mailprio = $values['mailprio'];
741 $body = $values['body'];
742 $identity = $values['identity'];
745 if ($use_javascript_addr_book) {
746 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
747 'function open_abook() { ' . "\n" .
748 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
749 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
750 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
751 ' nwin.opener = document.windows;' . "\n" .
753 '// --></SCRIPT>' . "\n\n";
756 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
757 'ENCTYPE="multipart/form-data"';
758 do_hook("compose_form");
763 if ($action == 'draft') {
764 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
766 if (isset($delete_draft)) {
767 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
769 if (isset($session)) {
770 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
773 if (isset($passed_id)) {
774 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
777 if ($saved_draft == 'yes') {
778 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
780 if ($mail_sent == 'yes') {
781 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
783 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
784 if ($compose_new_win == '1') {
785 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
786 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
788 if ($location_of_buttons == 'top') {
789 showComposeButtonRow();
792 $idents = getPref($data_dir, $username, 'identities', 0);
794 echo ' <TR>' . "\n" .
795 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
798 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
799 '<select name=identity>' . "\n" .
800 '<option value=default>' .
801 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
802 $em = getPref($data_dir, $username, 'email_address');
804 echo htmlspecialchars(' <' . $em . '>') . "\n";
806 for ($i = 1; $i < $idents; $i ++
) {
807 echo '<option value="' . $i . '"';
808 if (isset($identity) && $identity == $i) {
811 echo '>' . htmlspecialchars(getPref($data_dir, $username,
813 $em = getPref($data_dir, $username, 'email_address' . $i);
815 echo htmlspecialchars(' <' . $em . '>') . "\n";
819 echo '</select>' . "\n" .
823 echo ' <TR>' . "\n" .
824 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
826 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
827 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
828 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
832 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
834 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
835 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
836 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
840 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
842 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
843 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
844 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
845 '</TD></TR>' . "\n" .
847 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
849 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
850 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
851 htmlspecialchars($subject) . '">';
852 echo '</td></tr>' . "\n\n";
854 if ($location_of_buttons == 'between') {
855 showComposeButtonRow();
857 if ($compose_new_win == '1') {
858 echo ' <TR>' . "\n" .
859 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
860 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
861 $editor_size . '" WRAP="VIRTUAL">';
864 echo ' <TR>' . "\n" .
865 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
866 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
867 $editor_size . '" WRAP="VIRTUAL">';
869 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
870 if ($sig_first == '1') {
871 if ($charset == 'iso-2022-jp') {
872 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
874 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
876 echo "\n\n".htmlspecialchars($body);
879 echo "\n\n".htmlspecialchars($body);
880 if ($charset == 'iso-2022-jp') {
881 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
883 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
888 echo htmlspecialchars($body);
890 echo '</TEXTAREA><BR>' . "\n" .
894 if ($location_of_buttons == 'bottom') {
895 showComposeButtonRow();
897 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
898 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
899 ' <BR><BR>' .
900 ' </TD></TR>' . "\n";
903 /* This code is for attachments */
904 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
906 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
908 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
910 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
913 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
914 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
915 ' <input type="submit" name="attach"' .
916 ' value="' . _("Add") .'">' . "\n" .
922 foreach ($composeMessage->entities
as $key => $attachment) {
923 $attached_file = $attachment->att_local_name
;
924 if ($attachment->att_local_name ||
$attachment->body_part
) {
925 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
926 $type = $attachment->mime_header
->type0
.'/'.
927 $attachment->mime_header
->type1
;
928 $s_a[] = '<input type="checkbox" name="delete[]" value="' .
929 $key . "\">\n" . $attached_filename . ' - ' . $type .
930 ' ('.show_readable_size( filesize( $attached_file ) )
935 foreach ($s_a as $s) {
936 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
938 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
939 _("Delete selected attachments") . "\">\n" .
942 echo ' </table></td></tr>' .
946 /* End of attachment code */
947 if ($compose_new_win == '1') {
948 echo '</TABLE>'."\n";
950 echo '</TABLE>' . "\n" .
951 '<input type="hidden" name="username" value="'. $username . "\">\n" .
952 '<input type=hidden name=action value=' . $action . ">\n" .
953 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
956 do_hook('compose_bottom');
957 echo '</BODY></HTML>' . "\n";
961 function showComposeButtonRow() {
962 global $use_javascript_addr_book, $save_as_draft,
963 $default_use_priority, $mailprio, $default_use_mdn,
964 $request_mdn, $request_dr,
965 $data_dir, $username;
967 echo " <TR><TD>\n</TD><TD>\n";
968 if ($default_use_priority) {
969 if(!isset($mailprio)) {
972 echo _("Priority") .': <select name="mailprio">'.
973 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
974 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
975 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
978 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
979 if ($default_use_mdn) {
980 if ($mdn_user_support) {
981 echo "\n\t". _("Receipt") .': '.
982 '<input type="checkbox" name="request_mdn" value=1'.
983 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
984 ' <input type="checkbox" name="request_dr" value=1'.
985 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
989 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
990 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
991 if ($use_javascript_addr_book) {
992 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
993 " <input type=button value=\\\""._("Addresses").
994 "\\\" onclick='javascript:open_abook();'>\");".
995 " // --></SCRIPT><NOSCRIPT>\n".
996 " <input type=submit name=\"html_addr_search\" value=\"".
997 _("Addresses")."\">".
1000 echo " <input type=submit name=\"html_addr_search\" value=\"".
1001 _("Addresses")."\">";
1004 if ($save_as_draft) {
1005 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1008 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
1009 do_hook('compose_button_row');
1011 echo " </TD></TR>\n\n";
1014 function checkInput ($show) {
1016 * I implemented the $show variable because the error messages
1017 * were getting sent before the page header. So, I check once
1018 * using $show=false, and then when i'm ready to display the error
1019 * message, show=true
1021 global $body, $send_to, $send_to_bcc, $subject, $color;
1023 if ($send_to == '' && $send_to_bcc == '') {
1025 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1030 } /* function checkInput() */
1033 /* True if FAILURE */
1034 function saveAttachedFiles($session) {
1035 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1036 $data_dir, $compose_messages;
1038 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1039 $localfilename = GenerateRandomString(32, '', 7);
1040 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1041 while (file_exists($full_localfilename)) {
1042 $localfilename = GenerateRandomString(32, '', 7);
1043 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1046 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1047 if (function_exists("move_uploaded_file")) {
1048 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1052 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1057 $message = $compose_messages[$session];
1058 $type = strtolower($HTTP_POST_FILES['attachfile']['type']);
1059 $name = $HTTP_POST_FILES['attachfile']['name'];
1060 $message->initAttachment($type, $name, $full_localfilename);
1061 $compose_messages[$session] = $message;
1064 function ClearAttachments($composeMessage) {
1065 if ($message->att_local_name
) {
1066 $attached_file = $message->att_local_name
;
1067 if (file_exists($attached_file)) {
1068 unlink($attached_file);
1071 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1072 ClearAttachments($composeMessage->entities
[$i]);
1078 function getReplyCitation($orig_from) {
1079 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1081 /* First, return an empty string when no citation style selected. */
1082 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1086 /* Make sure our final value isn't an empty string. */
1087 if ($orig_from == '') {
1091 /* Otherwise, try to select the desired citation style. */
1092 switch ($reply_citation_style) {
1095 $end = ' ' . _("said") . ':';
1098 $start = '<' . _("quote") . ' ' . _("who") . '="';
1101 case 'user-defined':
1102 $start = $reply_citation_start .
1103 ($reply_citation_start == '' ?
'' : ' ');
1104 $end = $reply_citation_end;
1110 /* Build and return the citation string. */
1111 return ($start . $orig_from . $end . "\n");
1114 /* temporary function to make use of the deliver class.
1115 In the future the responsable backend should be automaticly loaded
1116 and conf.pl should show a list of available backends.
1117 The message also should be constructed by the message class.
1120 function sendMessage($composeMessage) {
1121 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1122 $username, $popuser, $usernamedata, $identity, $data_dir,
1123 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1125 global $imapServerAddress, $imapPort, $sent_folder, $key;
1127 $rfc822_header = $composeMessage->rfc822_header
;
1128 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
1129 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
1130 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
1131 $rfc822_header->priority
= $mailprio;
1132 $rfc822_header->subject
= $subject;
1133 $special_encoding='';
1134 if (strtolower($default_charset) == 'iso-2022-jp') {
1135 if (mb_detect_encoding($body) == 'ASCII') {
1136 $special_encoding = '8bit';
1138 $body = mb_convert_encoding($body, 'JIS');
1139 $special_encoding = '7bit';
1142 $composeMessage->setBody($body);
1144 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1145 $popuser = $usernamedata[1];
1146 $domain = $usernamedata[2];
1147 unset($usernamedata);
1149 $popuser = $username;
1152 if (isset($identity) && $identity != 'default') {
1153 $from_mail = getPref($data_dir, $username,
1154 'email_address' . $identity);
1155 $full_name = getPref($data_dir, $username,
1156 'full_name' . $identity);
1157 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
1158 $reply_to = getPref($data_dir, $username,
1159 'reply_to' . $identity);
1161 $from_mail = getPref($data_dir, $username, 'email_address');
1162 $full_name = getPref($data_dir, $username, 'full_name');
1163 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
1164 $reply_to = getPref($data_dir, $username,'reply_to');
1167 $from_addr = "$popuser@$domain";
1168 $from_mail = $from_addr;
1170 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1172 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1174 /* Receipt: On Read */
1175 if (isset($request_mdn) && $request_mdn) {
1176 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1178 /* Receipt: On Delivery */
1179 if (isset($request_dr) && $request_dr) {
1180 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1182 /* multipart messages */
1183 if (count($composeMessage->entities
)) {
1184 $message_body = new Message();
1185 $message_body->body_part
= $composeMessage->body_part
;
1186 $composeMessage->body_part
= '';
1187 $mime_header = new MessageHeader
;
1188 $mime_header->type0
= 'text';
1189 $mime_header->type1
= 'plain';
1190 if ($special_encoding) {
1191 $mime_header->encoding
= $special_encoding;
1193 $mime_header->encoding
= 'us-ascii';
1195 if ($default_charset) {
1196 $mime_header->parameters
['charset'] = $default_charset;
1198 $message_body->mime_header
= $mime_header;
1199 array_unshift($composeMessage->entities
, $message_body);
1200 $content_type = new ContentType('multipart/mixed');
1202 $content_type = new ContentType('text/plain');
1204 if ($default_charset) {
1205 $content_type->properties
['charset']=$default_charset;
1208 $rfc822_header->content_type
= $content_type;
1209 $composeMessage->rfc822_header
= $rfc822_header;
1211 if (!$useSendmail) {
1212 require_once('../class/deliver/Deliver_SMTP.class.php');
1213 $deliver = new Deliver_SMTP();
1214 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
1215 if ($use_authenticated_smtp) {
1216 global $key, $onetimepad;
1218 $pass = OneTimePadDecrypt($key, $onetimepad);
1223 $authpop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1224 $stream = $deliver->initStream($composeMessage,$domain,0,
1225 $smtpServerAddress, $smtpPort, $authPop);
1227 require_once('../class/deliver/Deliver_SentMail.class.php');
1228 global $sendmail_path;
1229 $deliver = new Deliver_SendMail();
1230 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1234 $length = $deliver->mail($composeMessage, $stream);
1235 $succes = $deliver->finalizeStream($stream);
1238 $msg = $deliver->dlv_msg
. '<br>Server replied: '.$deliver->dlv_ret_nr
;
1239 plain_error_message($msg, $color);
1242 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1244 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1245 sqimap_append ($imap_stream, $sent_folder, $length);
1246 require_once('../class/deliver/Deliver_IMAP.class.php');
1247 $imap_deliver = new Deliver_IMAP();
1248 $imap_deliver->mail($composeMessage, $imap_stream);
1249 sqimap_append_done ($imap_stream);
1250 sqimap_logout($imap_stream);
1251 unset ($imap_deliver);
1253 ClearAttachments($composeMessage);