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 (!array_key_exists($session, $compose_messages)) {
176 $composeMessage = new message();
177 $rfc822_header = new Rfc822Header();
178 $composeMessage->rfc822_header
= $rfc822_header;
179 $composeMessage->reply_rfc822_header
= '';
180 $compose_messages[$session] = $composeMessage;
182 sqsession_register($compose_messages,'compose_messages');
184 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
190 * Set $default_charset to correspond with the user's selection
191 * of language interface.
194 $composeMessage=$compose_messages[$session];
195 $Result = sendMessage($composeMessage, true);
197 if (! sendMessage($composeMessage, true)) {
198 showInputForm($session);
201 $draft_message = _("Draft Email Saved");
202 /* If this is a resumed draft, then delete the original */
203 if(isset($delete_draft)) {
204 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
205 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
209 if ($compose_new_win == '1') {
210 Header("Location: compose.php?saved_draft=yes&session=$composesession");
214 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
215 "&startMessage=1¬e=".urlencode($draft_message));
223 if (isset($HTTP_POST_FILES['attachfile']) &&
224 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
225 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
226 $AttachFailure = saveAttachedFiles($session);
228 if (checkInput(false) && !isset($AttachFailure)) {
229 $urlMailbox = urlencode (trim($mailbox));
230 if (! isset($passed_id)) {
234 * Set $default_charset to correspond with the user's selection
235 * of language interface.
239 * This is to change all newlines to \n
240 * We'll change them to \r\n later (in the sendMessage function)
242 $body = str_replace("\r\n", "\n", $body);
243 $body = str_replace("\r", "\n", $body);
246 * Rewrap $body so that no line is bigger than $editor_size
247 * This should only really kick in the sqWordWrap function
248 * if the browser doesn't support "VIRTUAL" as the wrap type.
250 $body = explode("\n", $body);
252 foreach ($body as $line) {
253 if( $line <> '-- ' ) {
254 $line = rtrim($line);
256 if (strlen($line) <= $editor_size +
1) {
257 $newBody .= $line . "\n";
259 sqWordWrap($line, $editor_size);
260 $newBody .= $line . "\n";
264 do_hook('compose_send');
265 $composeMessage=$compose_messages[$session];
266 $Result = sendMessage($composeMessage);
268 showInputForm($session);
271 if ( isset($delete_draft)) {
272 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
273 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
276 if ($compose_new_win == '1') {
277 Header("Location: compose.php?mail_sent=yes");
280 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
285 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
288 if ($compose_new_win == '1') {
289 compose_Header($color, $mailbox);
292 displayPageHeader($color, $mailbox);
294 if (isset($AttachFailure)) {
295 plain_error_message(_("Could not move/copy file. File not attached"),
299 showInputForm($session);
300 /* sqimap_logout($imapConnection); */
302 } elseif (isset($html_addr_search_done)) {
303 if ($compose_new_win == '1') {
304 compose_Header($color, $mailbox);
307 displayPageHeader($color, $mailbox);
310 if (isset($send_to_search) && is_array($send_to_search)) {
311 foreach ($send_to_search as $k => $v) {
312 if (substr($k, 0, 1) == 'T') {
318 elseif (substr($k, 0, 1) == 'C') {
324 elseif (substr($k, 0, 1) == 'B') {
326 $send_to_bcc .= ', ';
332 showInputForm($session);
333 } elseif (isset($html_addr_search)) {
334 if (isset($HTTP_POST_FILES['attachfile']) &&
335 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
336 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
337 if (saveAttachedFiles($session)) {
338 plain_error_message(_("Could not move/copy file. File not attached"), $color);
342 * I am using an include so as to elminiate an extra unnecessary
343 * click. If you can think of a better way, please implement it.
345 include_once('./addrbook_search_html.php');
346 } elseif (isset($attach)) {
347 if (saveAttachedFiles($session)) {
348 plain_error_message(_("Could not move/copy file. File not attached"), $color);
350 if ($compose_new_win == '1') {
351 compose_Header($color, $mailbox);
354 displayPageHeader($color, $mailbox);
356 showInputForm($session);
358 elseif (isset($sigappend)) {
359 $idents = getPref($data_dir, $username, 'identities', 0);
361 if ($identity == 'default') {
366 $signature = getSig($data_dir, $username, $no);
368 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
369 if ($compose_new_win == '1') {
370 compose_Header($color, $mailbox);
372 displayPageHeader($color, $mailbox);
374 showInputForm($session);
375 } elseif (isset($do_delete)) {
376 if ($compose_new_win == '1') {
377 compose_Header($color, $mailbox);
380 displayPageHeader($color, $mailbox);
383 if (isset($delete) && is_array($delete)) {
384 $composeMessage = $compose_messages[$session];
385 foreach($delete as $index) {
386 $attached_file = $composeMessage->entities
[$index]->att_local_name
;
387 unlink ($attached_file);
388 unset ($composeMessage->entities
[$index]);
390 $new_entities = array();
391 foreach ($composeMessage->entities
as $entity) {
392 $new_entities[] = $entity;
394 $composeMessage->entities
= $new_entities;
395 $compose_messages[$session] = $composeMessage;
396 sqsession_register($compose_messages, 'compose_messages');
397 // setPref($data_dir, $username, 'attachments', serialize($attachments));
399 showInputForm($session);
402 * This handles the default case as well as the error case
403 * (they had the same code) --> if (isset($smtpErrors))
406 if ($compose_new_win == '1') {
407 compose_Header($color, $mailbox);
409 displayPageHeader($color, $mailbox);
414 if (!isset($passed_ent_id)) {
417 if (!isset($passed_id)) {
420 if (!isset($mailbox)) {
423 if (!isset($action)) {
427 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
429 /* in case the origin is not read_body.php */
430 if (isset($send_to)) {
431 $values['send_to'] = $send_to;
433 if (isset($send_to_cc)) {
434 $values['send_to_cc'] = $send_to_cc;
436 if (isset($send_to_bcc)) {
437 $values['send_to_bcc'] = $send_to_bcc;
439 showInputForm($session, $values);
444 /**************** Only function definitions go below *************/
447 /* This function is used when not sending or adding attachments */
448 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
449 global $editor_size, $default_use_priority, $body,
450 $use_signature, $composesession, $data_dir, $username,
451 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
454 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
458 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
461 sqimap_mailbox_select($imapConnection, $mailbox);
462 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
465 if ($passed_ent_id) {
466 /* redefine the messsage in case of message/rfc822 */
467 $message = $message->getEntity($passed_ent_id);
468 /* message is an entity which contains the envelope and type0=message
469 * and type1=rfc822. The actual entities are childs from
470 * $message->entities[0]. That's where the encoding and is located
473 $entities = $message->entities
[0]->findDisplayEntity
474 (array(), $alt_order = array('text/plain'));
475 if (!count($entities)) {
476 $entities = $message->entities
[0]->findDisplayEntity
477 (array(), $alt_order = array('text/plain','html/plain'));
479 $orig_header = $message->rfc822_header
; /* here is the envelope located */
480 /* redefine the message for picking up the attachments */
481 $message = $message->entities
[0];
484 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
485 if (!count($entities)) {
486 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
488 $orig_header = $message->rfc822_header
;
491 $encoding = $message->header
->encoding
;
492 $type0 = $message->type0
;
493 $type1 = $message->type1
;
494 foreach ($entities as $ent) {
495 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
496 $body_part_entity = $message->getEntity($ent);
497 $bodypart = decodeBody($unencoded_bodypart,
498 $body_part_entity->header
->encoding
);
499 if ($type1 == 'html') {
500 $bodypart = strip_tags($bodypart);
504 if ($default_use_priority) {
505 $mailprio = substr($orig_header->priority
,0,1);
512 //ClearAttachments($session);
515 $idents = getPref($data_dir, $username, 'identities');
516 $from_o = $orig_header->from
;
517 if (is_object($from_o)) {
518 $orig_from = $from_o->getAddress();
522 if (!empty($idents) && $idents > 1) {
523 for ($i = 1; $i < $idents; $i++
) {
524 $enc_from_name = '"'.
528 '" <' . getPref($data_dir, $username,
529 'email_address' . $i) . '>';
530 if ($enc_from_name == $orig_from) {
539 $use_signature = FALSE;
540 $send_to = $orig_header->getAddr_s('to');
541 $send_to_cc = $orig_header->getAddr_s('cc');
542 $send_to_bcc = $orig_header->getAddr_s('bcc');
543 $subject = decodeHeader($orig_header->subject
);
545 $body_ary = explode("\n", $body);
546 $cnt = count($body_ary) ;
548 for ($i=0; $i < $cnt; $i++
) {
549 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
550 sqWordWrap($body_ary[$i], $editor_size );
551 $body .= $body_ary[$i] . "\n";
553 unset($body_ary[$i]);
556 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
558 case ('edit_as_new'):
559 $send_to = $orig_header->getAddr_s('to');
560 $send_to_cc = $orig_header->getAddr_s('cc');
561 $send_to_bcc = $orig_header->getAddr_s('bcc');
562 $subject = decodeHeader($orig_header->subject
);
563 $mailprio = $orig_header->priority
;
565 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
570 $subject = decodeHeader($orig_header->subject
);
571 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
572 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
573 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
574 $subject = '[Fwd: ' . $subject . ']';
576 $body = getforwardHeader($orig_header) . $body;
578 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
580 case ('forward_as_attachment'):
581 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
585 $send_to_cc = replyAllString($orig_header);
587 $send_to = $orig_header->reply_to
;
588 if (is_object($send_to)) {
589 $send_to = $send_to->getAddr_s('reply_to');
591 $send_to = $orig_header->getAddr_s('from');
593 $subject = decodeHeader($orig_header->subject
);
594 $subject = str_replace('"', "'", $subject);
595 $subject = trim($subject);
596 if (substr(strtolower($subject), 0, 3) != 're:') {
597 $subject = 'Re: ' . $subject;
599 /* this corrects some wrapping/quoting problems on replies */
600 $rewrap_body = explode("\n", $body);
602 $body = getReplyCitation($orig_header->from
->personal
);
603 $cnt = count($rewrap_body);
604 for ($i=0;$i<$cnt;$i++
) {
605 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
606 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
608 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
610 $body .= '> ' . $rewrap_body[$i] . "\n";
612 unset($rewrap_body[$i]);
614 $composeMessage->reply_rfc822_header
= $orig_header;
619 $compose_messages[$session] = $composeMessage;
620 sqsession_register($compose_messages, 'compose_messages');
622 sqimap_logout($imapConnection);
624 $ret = array( 'send_to' => $send_to,
625 'send_to_cc' => $send_to_cc,
626 'send_to_bcc' => $send_to_bcc,
627 'subject' => $subject,
628 'mailprio' => $mailprio,
630 'identity' => $identity );
633 } /* function newMail() */
635 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
636 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
637 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
638 if (!count($message->entities
) ||
639 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
640 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
641 switch ($message->type0
) {
643 if ($message->type1
== 'rfc822') {
644 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
645 if ($filename == "") {
646 $filename = "untitled-".$message->entity_id
.'.eml';
649 $filename = decodeHeader($message->getFilename());
653 $filename = decodeHeader($message->getFilename());
656 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
657 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
658 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
661 $localfilename = GenerateRandomString(32, '', 7);
662 $full_localfilename = "$hashed_attachment_dir/$localfilename";
663 while (file_exists($full_localfilename)) {
664 $localfilename = GenerateRandomString(32, '', 7);
665 $full_localfilename = "$hashed_attachment_dir/$localfilename";
667 $message->att_local_name
= $full_localfilename;
668 if (!$message->mime_header
) { /* temporary hack */
669 $message->mime_header
= $message->header
;
672 $composeMessage->addEntity($message);
674 /* Write Attachment to file */
675 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
676 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
677 $passed_id, $message->entity_id
),
678 $message->header
->encoding
));
682 for ($i=0, $entCount=count($message->entities
); $i<$entCount;$i++
) {
683 $composeMessage=getAttachments($message->entities
[$i], $composeMessage, $passed_id, $entities, $imapConnection);
686 // setPref($data_dir, $username, 'attachments', serialize($attachments));
687 return $composeMessage;
690 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
691 $passed_ent_id='', $imapConnection) {
692 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
693 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
694 if (!$passed_ent_id) {
695 $body_a = sqimap_run_command($imapConnection,
696 'FETCH '.$passed_id.' RFC822',
697 TRUE, $response, $readmessage,
700 $body_a = sqimap_run_command($imapConnection,
701 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
702 TRUE, $response, $readmessage, $uid_support);
703 $message = $message->parent
;
705 if ($response = 'OK') {
706 $subject = encodeHeader($message->rfc822_header
->subject
);
707 array_shift($body_a);
708 $body = implode('', $body_a) . "\r\n";
710 $localfilename = GenerateRandomString(32, 'FILE', 7);
711 $full_localfilename = "$hashed_attachment_dir/$localfilename";
713 $fp = fopen( $full_localfilename, 'w');
716 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
717 $full_localfilename);
719 return $composeMessage;
722 function showInputForm ($session, $values=false) {
723 global $send_to, $send_to_cc, $body,
724 $passed_body, $color, $use_signature, $signature, $prefix_sig,
725 $editor_size, $attachments, $subject, $newmail,
726 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
727 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
728 $username, $data_dir, $identity, $draft_id, $delete_draft,
729 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
730 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
731 $username, $compose_messages;
733 $composeMessage = $compose_messages[$session];
735 $subject = decodeHeader($subject, false);
737 $send_to = $values['send_to'];
738 $send_to_cc = $values['send_to_cc'];
739 $send_to_bcc = $values['send_to_bcc'];
740 $subject = $values['subject'];
741 $mailprio = $values['mailprio'];
742 $body = $values['body'];
743 $identity = $values['identity'];
746 if ($use_javascript_addr_book) {
747 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
748 'function open_abook() { ' . "\n" .
749 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
750 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
751 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
752 ' nwin.opener = document.windows;' . "\n" .
754 '// --></SCRIPT>' . "\n\n";
757 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
758 'ENCTYPE="multipart/form-data"';
759 do_hook("compose_form");
764 if ($action == 'draft') {
765 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
767 if (isset($delete_draft)) {
768 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
770 if (isset($session)) {
771 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
774 if (isset($passed_id)) {
775 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
778 if ($saved_draft == 'yes') {
779 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
781 if ($mail_sent == 'yes') {
782 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
784 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
785 if ($compose_new_win == '1') {
786 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
787 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
789 if ($location_of_buttons == 'top') {
790 showComposeButtonRow();
793 $idents = getPref($data_dir, $username, 'identities', 0);
795 echo ' <TR>' . "\n" .
796 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
799 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
800 '<select name=identity>' . "\n" .
801 '<option value=default>' .
802 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
803 $em = getPref($data_dir, $username, 'email_address');
805 echo htmlspecialchars(' <' . $em . '>') . "\n";
807 for ($i = 1; $i < $idents; $i ++
) {
808 echo '<option value="' . $i . '"';
809 if (isset($identity) && $identity == $i) {
812 echo '>' . htmlspecialchars(getPref($data_dir, $username,
814 $em = getPref($data_dir, $username, 'email_address' . $i);
816 echo htmlspecialchars(' <' . $em . '>') . "\n";
820 echo '</select>' . "\n" .
824 echo ' <TR>' . "\n" .
825 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
827 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
828 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
829 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
833 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
835 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
836 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
837 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
841 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
843 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
844 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
845 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
846 '</TD></TR>' . "\n" .
848 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
850 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
851 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
852 htmlspecialchars($subject) . '">';
853 echo '</td></tr>' . "\n\n";
855 if ($location_of_buttons == 'between') {
856 showComposeButtonRow();
858 if ($compose_new_win == '1') {
859 echo ' <TR>' . "\n" .
860 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
861 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
862 $editor_size . '" WRAP="VIRTUAL">';
865 echo ' <TR>' . "\n" .
866 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
867 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
868 $editor_size . '" WRAP="VIRTUAL">';
870 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
871 if ($sig_first == '1') {
872 if ($charset == 'iso-2022-jp') {
873 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
875 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
877 echo "\n\n".htmlspecialchars($body);
880 echo "\n\n".htmlspecialchars($body);
881 if ($charset == 'iso-2022-jp') {
882 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
884 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
889 echo htmlspecialchars($body);
891 echo '</TEXTAREA><BR>' . "\n" .
895 if ($location_of_buttons == 'bottom') {
896 showComposeButtonRow();
898 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
899 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
900 ' <BR><BR>' .
901 ' </TD></TR>' . "\n";
904 /* This code is for attachments */
905 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
907 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
909 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
911 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
914 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
915 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
916 ' <input type="submit" name="attach"' .
917 ' value="' . _("Add") .'">' . "\n" .
923 foreach ($composeMessage->entities
as $key => $attachment) {
924 $attached_file = $attachment->att_local_name
;
925 if ($attachment->att_local_name ||
$attachment->body_part
) {
926 $attached_filename = decodeHeader($attachment->mime_header
->getParameter('name'));
927 $type = $attachment->mime_header
->type0
.'/'.
928 $attachment->mime_header
->type1
;
929 $s_a[] = '<input type="checkbox" name="delete[]" value="' .
930 $key . "\">\n" . $attached_filename . ' - ' . $type .
931 ' ('.show_readable_size( filesize( $attached_file ) )
936 foreach ($s_a as $s) {
937 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
939 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
940 _("Delete selected attachments") . "\">\n" .
943 echo ' </table></td></tr>' .
947 /* End of attachment code */
948 if ($compose_new_win == '1') {
949 echo '</TABLE>'."\n";
951 echo '</TABLE>' . "\n" .
952 '<input type="hidden" name="username" value="'. $username . "\">\n" .
953 '<input type=hidden name=action value=' . $action . ">\n" .
954 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
957 do_hook('compose_bottom');
958 echo '</BODY></HTML>' . "\n";
962 function showComposeButtonRow() {
963 global $use_javascript_addr_book, $save_as_draft,
964 $default_use_priority, $mailprio, $default_use_mdn,
965 $request_mdn, $request_dr,
966 $data_dir, $username;
968 echo " <TR><TD>\n</TD><TD>\n";
969 if ($default_use_priority) {
970 if(!isset($mailprio)) {
973 echo _("Priority") .': <select name="mailprio">'.
974 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
975 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
976 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
979 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
980 if ($default_use_mdn) {
981 if ($mdn_user_support) {
982 echo "\n\t". _("Receipt") .': '.
983 '<input type="checkbox" name="request_mdn" value=1'.
984 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
985 ' <input type="checkbox" name="request_dr" value=1'.
986 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
990 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
991 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
992 if ($use_javascript_addr_book) {
993 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
994 " <input type=button value=\\\""._("Addresses").
995 "\\\" onclick='javascript:open_abook();'>\");".
996 " // --></SCRIPT><NOSCRIPT>\n".
997 " <input type=submit name=\"html_addr_search\" value=\"".
998 _("Addresses")."\">".
1001 echo " <input type=submit name=\"html_addr_search\" value=\"".
1002 _("Addresses")."\">";
1005 if ($save_as_draft) {
1006 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1009 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
1010 do_hook('compose_button_row');
1012 echo " </TD></TR>\n\n";
1015 function checkInput ($show) {
1017 * I implemented the $show variable because the error messages
1018 * were getting sent before the page header. So, I check once
1019 * using $show=false, and then when i'm ready to display the error
1020 * message, show=true
1022 global $body, $send_to, $send_to_bcc, $subject, $color;
1024 if ($send_to == '' && $send_to_bcc == '') {
1026 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1031 } /* function checkInput() */
1034 /* True if FAILURE */
1035 function saveAttachedFiles($session) {
1036 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1037 $data_dir, $compose_messages;
1039 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1040 $localfilename = GenerateRandomString(32, '', 7);
1041 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1042 while (file_exists($full_localfilename)) {
1043 $localfilename = GenerateRandomString(32, '', 7);
1044 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1047 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1048 if (function_exists("move_uploaded_file")) {
1049 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1053 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1058 $message = $compose_messages[$session];
1059 $type = strtolower($HTTP_POST_FILES['attachfile']['type']);
1060 $name = $HTTP_POST_FILES['attachfile']['name'];
1061 $message->initAttachment($type, $name, $full_localfilename);
1062 $compose_messages[$session] = $message;
1065 function ClearAttachments($composeMessage) {
1066 if ($composeMessage->att_local_name
) {
1067 $attached_file = $composeMessage->att_local_name
;
1068 if (file_exists($attached_file)) {
1069 unlink($attached_file);
1072 for ($i=0, $entCount=count($composeMessage->entities
);$i< $entCount; ++
$i) {
1073 ClearAttachments($composeMessage->entities
[$i]);
1079 function getReplyCitation($orig_from) {
1080 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1082 /* First, return an empty string when no citation style selected. */
1083 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1087 /* Make sure our final value isn't an empty string. */
1088 if ($orig_from == '') {
1092 /* Otherwise, try to select the desired citation style. */
1093 switch ($reply_citation_style) {
1096 $end = ' ' . _("said") . ':';
1099 $start = '<' . _("quote") . ' ' . _("who") . '="';
1102 case 'user-defined':
1103 $start = $reply_citation_start .
1104 ($reply_citation_start == '' ?
'' : ' ');
1105 $end = $reply_citation_end;
1111 /* Build and return the citation string. */
1112 return ($start . $orig_from . $end . "\n");
1115 /* temporary function to make use of the deliver class.
1116 In the future the responsable backend should be automaticly loaded
1117 and conf.pl should show a list of available backends.
1118 The message also should be constructed by the message class.
1121 function sendMessage($composeMessage, $draft=false) {
1122 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1123 $username, $popuser, $usernamedata, $identity, $data_dir,
1124 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1126 global $imapServerAddress, $imapPort, $sent_folder, $key;
1128 $rfc822_header = $composeMessage->rfc822_header
;
1129 $rfc822_header->to
= $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
1130 $rfc822_header->cc
= $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
1131 $rfc822_header->bcc
= $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
1132 $rfc822_header->priority
= $mailprio;
1133 $rfc822_header->subject
= $subject;
1134 $special_encoding='';
1135 if (strtolower($default_charset) == 'iso-2022-jp') {
1136 if (mb_detect_encoding($body) == 'ASCII') {
1137 $special_encoding = '8bit';
1139 $body = mb_convert_encoding($body, 'JIS');
1140 $special_encoding = '7bit';
1143 $composeMessage->setBody($body);
1145 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1146 $popuser = $usernamedata[1];
1147 $domain = $usernamedata[2];
1148 unset($usernamedata);
1150 $popuser = $username;
1153 if (isset($identity) && $identity != 'default') {
1154 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1155 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1156 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1158 $from_mail = getPref($data_dir, $username, 'email_address');
1159 $full_name = getPref($data_dir, $username, 'full_name');
1160 $reply_to = getPref($data_dir, $username,'reply_to');
1163 $from_mail = "$popuser@$domain";
1166 $rfc822_header->from
= $rfc822_header->parseAddress($from_mail,true);
1168 $from = $rfc822_header->from
[0];
1169 if (!$from->host
) $from->host
= $domain;
1170 $from_addr = $full_name .' <'.$from->mailbox
.'@'.$from->host
.'>';
1171 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
1174 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
1176 /* Receipt: On Read */
1177 if (isset($request_mdn) && $request_mdn) {
1178 $rfc822_header->dnt
= $rfc822_header->parseAddress($from_mail,true);
1180 /* Receipt: On Delivery */
1181 if (isset($request_dr) && $request_dr) {
1182 $rfc822_header->more_headers
['Return-Receipt-To'] = $from_mail;
1184 /* multipart messages */
1185 if (count($composeMessage->entities
)) {
1186 $message_body = new Message();
1187 $message_body->body_part
= $composeMessage->body_part
;
1188 $composeMessage->body_part
= '';
1189 $mime_header = new MessageHeader
;
1190 $mime_header->type0
= 'text';
1191 $mime_header->type1
= 'plain';
1192 if ($special_encoding) {
1193 $mime_header->encoding
= $special_encoding;
1195 $mime_header->encoding
= 'us-ascii';
1197 if ($default_charset) {
1198 $mime_header->parameters
['charset'] = $default_charset;
1200 $message_body->mime_header
= $mime_header;
1201 array_unshift($composeMessage->entities
, $message_body);
1202 $content_type = new ContentType('multipart/mixed');
1204 $content_type = new ContentType('text/plain');
1206 if ($default_charset) {
1207 $content_type->properties
['charset']=$default_charset;
1210 $rfc822_header->content_type
= $content_type;
1211 $composeMessage->rfc822_header
= $rfc822_header;
1213 if (!$useSendmail && !$draft) {
1214 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
1215 $deliver = new Deliver_SMTP();
1216 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
1217 if ($use_authenticated_smtp) {
1218 global $key, $onetimepad;
1220 $pass = OneTimePadDecrypt($key, $onetimepad);
1225 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
1226 $stream = $deliver->initStream($composeMessage,$domain,0,
1227 $smtpServerAddress, $smtpPort, $authPop);
1228 } elseif (!$draft) {
1229 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
1230 global $sendmail_path;
1231 $deliver = new Deliver_SendMail();
1232 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1234 global $draft_folder;
1235 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1236 // $imap_deliver = new Deliver_IMAP();
1237 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1239 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1240 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1241 $imap_deliver = new Deliver_IMAP();
1242 $length = $imap_deliver->mail($composeMessage);
1243 sqimap_append ($imap_stream, $draft_folder, $length);
1244 $imap_deliver->mail($composeMessage, $imap_stream);
1245 sqimap_append_done ($imap_stream);
1246 sqimap_logout($imap_stream);
1247 unset ($imap_deliver);
1254 $length = $deliver->mail($composeMessage, $stream);
1255 $succes = $deliver->finalizeStream($stream);
1258 $msg = $deliver->dlv_msg
. '<br>Server replied: '.$deliver->dlv_ret_nr
;
1259 plain_error_message($msg, $color);
1262 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1264 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1265 sqimap_append ($imap_stream, $sent_folder, $length);
1266 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
1267 $imap_deliver = new Deliver_IMAP();
1268 $imap_deliver->mail($composeMessage, $imap_stream);
1269 sqimap_append_done ($imap_stream);
1270 unset ($imap_deliver);
1272 global $passed_id, $mailbox, $action;
1273 ClearAttachments($composeMessage);
1274 if ($action == 'reply' ||
$action == 'reply_all') {
1275 sqimap_mailbox_select ($imap_stream, $mailbox);
1276 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1278 sqimap_logout($imap_stream);