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');
28 /* --------------------- Specific Functions ------------------------------ */
30 function replyAllString($header) {
31 global $include_self_reply_all, $username, $data_dir;
34 * 1) Remove the addresses we'll be sending the message 'to'
36 $url_replytoall_avoid_addrs = '';
37 if (isset($header->replyto
)) {
38 $excl_ar = $header->getAddr_a('replyto');
41 * 2) Remove our identities from the CC list (they still can be in the
42 * TO list) only if $include_self_reply_all is turned off
44 if (!$include_self_reply_all) {
45 $email_address = trim(getPref($data_dir, $username, 'email_address'));
46 $excl_ar[$email_address] = '';
48 $idents = getPref($data_dir, $username, 'identities');
49 if ($idents != '' && $idents > 1) {
50 for ($i = 1; $i < $idents; $i ++
) {
51 $cur_email_address = getPref($data_dir, $username,
52 'email_address' . $i);
53 $cur_email_address = strtolower($cur_email_address);
54 $excl_ar[$cur_email_address] = '';
60 * 3) get the addresses.
62 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
65 * 4) generate the string.
67 $url_replytoallcc = '';
68 foreach( $url_replytoall_ar as $email => $personal) {
70 $url_replytoallcc .= ", \"$personal\" <$email>";
72 $url_replytoallcc .= ', '. $email;
75 $url_replytoallcc = substr($url_replytoallcc,2);
76 return $url_replytoallcc;
79 function getforwardHeader($orig_header) {
83 _("Subject") => strlen(_("Subject")),
84 _("From") => strlen(_("From")),
85 _("Date") => strlen(_("Date")),
86 _("To") => strlen(_("To")),
87 _("Cc") => strlen(_("Cc"))
89 $maxsize = max($display);
90 $indent = str_pad('',$maxsize+
2);
91 foreach($display as $key => $val) {
92 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
94 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
);
95 $bodyTop .= "\n". $display[_("Subject")] . decodeHeader($orig_header->subject
) . "\n" .
96 $display[_("From")] . decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
97 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
98 $display[_("To")] . decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
99 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
100 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
102 $bodyTop .= str_pad('', $editor_size -2 , '-');
106 /* ----------------------------------------------------------------------- */
109 * If the session is expired during a post this restores the compose session
112 //$session_expired = false;
113 if (session_is_registered('session_expired_post')) {
114 global $session_expired_post, $session_expired;
116 * extra check for username so we don't display previous post data from
117 * another user during this session.
119 if ($session_expired_post['username'] != $username) {
120 session_unregister('session_expired_post');
121 session_unregister('session_expired');
123 foreach ($session_expired_post as $postvar => $val) {
133 $session_expired = true;
135 session_unregister('session_expired_post');
136 session_unregister('session_expired');
137 if (!isset($mailbox)) {
140 if ($compose_new_win == '1') {
141 compose_Header($color, $mailbox);
143 displayPageHeader($color, $mailbox);
145 showInputForm($session, false);
149 if (!isset($attachments)) {
150 $attachments = array();
151 session_register('attachments');
154 if (!isset($composesession)) {
156 session_register('composesession');
159 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
160 $session = "$composesession" +
1;
161 $composesession = $session;
162 session_register('composesession');
165 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
170 include_once ('../src/draft_actions.php');
171 if (! isset($passed_id)) {
177 if (! isset($mailprio)) {
180 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
181 showInputForm($session);
184 $draft_message = _("Draft Email Saved");
185 /* If this is a resumed draft, then delete the original */
186 if(isset($delete_draft)) {
187 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
188 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
192 if ($compose_new_win == '1') {
193 Header("Location: compose.php?saved_draft=yes&session=$composesession");
197 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
198 "&startMessage=1¬e=".urlencode($draft_message));
206 if (isset($HTTP_POST_FILES['attachfile']) &&
207 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
208 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
209 $AttachFailure = saveAttachedFiles($session);
211 if (checkInput(false) && !isset($AttachFailure)) {
212 $urlMailbox = urlencode (trim($mailbox));
213 if (! isset($passed_id)) {
217 * Set $default_charset to correspond with the user's selection
218 * of language interface.
223 * This is to change all newlines to \n
224 * We'll change them to \r\n later (in the sendMessage function)
226 $body = str_replace("\r\n", "\n", $body);
227 $body = str_replace("\r", "\n", $body);
230 * Rewrap $body so that no line is bigger than $editor_size
231 * This should only really kick in the sqWordWrap function
232 * if the browser doesn't support "VIRTUAL" as the wrap type.
234 $body = explode("\n", $body);
236 foreach ($body as $line) {
237 if( $line <> '-- ' ) {
238 $line = rtrim($line);
240 if (strlen($line) <= $editor_size +
1) {
241 $newBody .= $line . "\n";
243 sqWordWrap($line, $editor_size);
244 $newBody .= $line . "\n";
249 do_hook('compose_send');
251 $MDN = False; // we are not sending a mdn response
252 if (! isset($mailprio)) {
253 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
254 $subject, $body, $passed_id, $MDN, '', $session);
256 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
257 $subject, $body, $passed_id, $MDN, $mailprio, $session);
260 showInputForm($session);
263 if ( isset($delete_draft)) {
264 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
265 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
268 if ($compose_new_win == '1') {
269 Header("Location: compose.php?mail_sent=yes");
272 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
277 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
280 if ($compose_new_win == '1') {
281 compose_Header($color, $mailbox);
284 displayPageHeader($color, $mailbox);
286 if (isset($AttachFailure)) {
287 plain_error_message(_("Could not move/copy file. File not attached"),
291 showInputForm($session);
292 /* sqimap_logout($imapConnection); */
294 } elseif (isset($html_addr_search_done)) {
295 if ($compose_new_win == '1') {
296 compose_Header($color, $mailbox);
299 displayPageHeader($color, $mailbox);
302 if (isset($send_to_search) && is_array($send_to_search)) {
303 foreach ($send_to_search as $k => $v) {
304 if (substr($k, 0, 1) == 'T') {
310 elseif (substr($k, 0, 1) == 'C') {
316 elseif (substr($k, 0, 1) == 'B') {
318 $send_to_bcc .= ', ';
324 showInputForm($session);
325 } elseif (isset($html_addr_search)) {
326 if (isset($HTTP_POST_FILES['attachfile']) &&
327 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
328 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
329 if (saveAttachedFiles($session)) {
330 plain_error_message(_("Could not move/copy file. File not attached"), $color);
334 * I am using an include so as to elminiate an extra unnecessary
335 * click. If you can think of a better way, please implement it.
337 include_once('./addrbook_search_html.php');
338 } elseif (isset($attach)) {
339 if (saveAttachedFiles($session)) {
340 plain_error_message(_("Could not move/copy file. File not attached"), $color);
342 if ($compose_new_win == '1') {
343 compose_Header($color, $mailbox);
346 displayPageHeader($color, $mailbox);
348 showInputForm($session);
350 elseif (isset($sigappend)) {
351 $idents = getPref($data_dir, $username, 'identities', 0);
353 if ($identity == 'default') {
358 $signature = getSig($data_dir, $username, $no);
360 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
361 if ($compose_new_win == '1') {
362 compose_Header($color, $mailbox);
364 displayPageHeader($color, $mailbox);
366 showInputForm($session);
367 } elseif (isset($do_delete)) {
368 if ($compose_new_win == '1') {
369 compose_Header($color, $mailbox);
372 displayPageHeader($color, $mailbox);
375 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
376 if (isset($delete) && is_array($delete)) {
377 foreach($delete as $index) {
378 $attached_file = $hashed_attachment_dir . '/'
379 . $attachments[$index]['localfilename'];
380 unlink ($attached_file);
381 unset ($attachments[$index]);
383 setPref($data_dir, $username, 'attachments', serialize($attachments));
386 showInputForm($session);
389 * This handles the default case as well as the error case
390 * (they had the same code) --> if (isset($smtpErrors))
393 if ($compose_new_win == '1') {
394 compose_Header($color, $mailbox);
396 displayPageHeader($color, $mailbox);
401 if (!isset($passed_ent_id)) $passed_ent_id = '';
402 if (!isset($passed_id)) $passed_id = '';
403 if (!isset($mailbox)) $mailbox = '';
404 if (!isset($action)) $action = '';
406 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
408 /* in case the origin is not read_body.php */
409 if (isset($send_to)) {
410 $values['send_to'] = $send_to;
412 if (isset($send_to_cc)) {
413 $values['send_to_cc'] = $send_to_cc;
415 if (isset($send_to_bcc)) {
416 $values['send_to_bcc'] = $send_to_bcc;
418 showInputForm($session, $values);
423 /**************** Only function definitions go below *************/
426 /* This function is used when not sending or adding attachments */
427 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
428 global $editor_size, $default_use_priority, $body,
429 $use_signature, $composesession, $data_dir, $username,
430 $username, $key, $imapServerAddress, $imapPort;
432 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
436 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
439 sqimap_mailbox_select($imapConnection, $mailbox);
440 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
442 if ($passed_ent_id) {
443 /* redefine the messsage in case of message/rfc822 */
444 $message = $message->getEntity($passed_ent_id);
445 /* message is an entity which contains the envelope and type0=message
446 * and type1=rfc822. The actual entities are childs from
447 * $message->entities[0]. That's where the encoding and is located
450 $entities = $message->entities
[0]->findDisplayEntity
451 (array(), $alt_order = array('text/plain'));
452 if (!count($entities)) {
453 $entities = $message->entities
[0]->findDisplayEntity
454 (array(), $alt_order = array('text/plain','html/plain'));
456 $orig_header = $message->rfc822_header
; /* here is the envelope located */
457 /* redefine the message for picking up the attachments */
458 $message = $message->entities
[0];
461 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
462 if (!count($entities)) {
463 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
465 $orig_header = $message->rfc822_header
;
467 $encoding = $message->header
->encoding
;
468 $type0 = $message->type0
;
469 $type1 = $message->type1
;
470 foreach ($entities as $ent) {
471 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
472 $body_part_entity = $message->getEntity($ent);
473 $bodypart = decodeBody($unencoded_bodypart,
474 $body_part_entity->header
->encoding
);
475 if ($type1 == 'html') {
476 $bodypart = strip_tags($bodypart);
480 if ($default_use_priority) {
481 $mailprio = substr($orig_header->priority
,0,1);
488 ClearAttachments($session);
491 $idents = getPref($data_dir, $username, 'identities');
492 $from_o = $orig_header->from
;
493 if (is_object($from_o)) {
494 $orig_from = $from_o->getAddress();
498 if (!empty($idents) && $idents > 1) {
499 for ($i = 1; $i < $idents; $i++
) {
500 $enc_from_name = '"'.
504 '" <' . getPref($data_dir, $username,
505 'email_address' . $i) . '>';
506 if ($enc_from_name == $orig_from) {
515 $use_signature = FALSE;
516 $send_to = $orig_header->getAddr_s('to');
517 $send_to_cc = $orig_header->getAddr_s('cc');
518 $send_to_bcc = $orig_header->getAddr_s('bcc');
519 $subject = decodeHeader($orig_header->subject
);
521 $body_ary = explode("\n", $body);
522 $cnt = count($body_ary) ;
524 for ($i=0; $i < $cnt; $i++
) {
525 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
526 sqWordWrap($body_ary[$i], $editor_size );
527 $body .= $body_ary[$i] . "\n";
529 unset($body_ary[$i]);
532 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
534 case ('edit_as_new'):
535 $send_to = $orig_header->getAddr_s('to');
536 $send_to_cc = $orig_header->getAddr_s('cc');
537 $send_to_bcc = $orig_header->getAddr_s('bcc');
538 $subject = decodeHeader($orig_header->subject
);
539 $mailprio = $orig_header->priority
;
541 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
546 $subject = decodeHeader($orig_header->subject
);
547 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
548 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
549 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
550 $subject = '[Fwd: ' . $subject . ']';
552 $body = getforwardHeader($orig_header) . $body;
554 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
556 case ('forward_as_attachment'):
557 getMessage_RFC822_Attachment($message, $session, $passed_id, $passed_ent_id, $imapConnection);
561 $send_to_cc = replyAllString($orig_header);
563 $send_to = $orig_header->reply_to
;
564 if (is_object($send_to)) {
565 $send_to = $send_to->getAddr_s('reply_to');
567 $send_to = $orig_header->getAddr_s('from');
569 $subject = $orig_header->subject
;
570 $subject = str_replace('"', "'", $subject);
571 $subject = trim($subject);
572 if (substr(strtolower($subject), 0, 3) != 're:') {
573 $subject = 'Re: ' . $subject;
575 /* this corrects some wrapping/quoting problems on replies */
576 $rewrap_body = explode("\n", charset_decode_japanese($body));
578 $body = getReplyCitation($orig_header->from
->personal
);
579 $cnt = count($rewrap_body);
580 for ($i=0;$i<$cnt;$i++
) {
581 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
582 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
584 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
586 $body .= '> ' . $rewrap_body[$i] . "\n";
588 unset($rewrap_body[$i]);
594 sqimap_logout($imapConnection);
597 'send_to' => $send_to,
598 'send_to_cc' => $send_to_cc,
599 'send_to_bcc' => $send_to_bcc,
600 'subject' => $subject,
601 'mailprio' => $mailprio,
603 'identity' => $identity
607 } /* function newMail() */
610 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
611 global $attachments, $attachment_dir, $username, $data_dir;
613 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
614 if (!count($message->entities
) ||
615 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
616 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
617 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
618 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
619 if ($filename == "") {
620 $filename = "untitled-".$message->entity_id
.'.eml';
623 $filename = decodeHeader($message->getFilename());
625 $localfilename = GenerateRandomString(32, '', 7);
626 $full_localfilename = "$hashed_attachment_dir/$localfilename";
627 while (file_exists($full_localfilename)) {
628 $localfilename = GenerateRandomString(32, '', 7);
629 $full_localfilename = "$hashed_attachment_dir/$localfilename";
632 $newAttachment = array();
633 $newAttachment['localfilename'] = $localfilename;
634 $newAttachment['remotefilename'] = $filename;
635 $newAttachment['type'] = strtolower($message->type0
.
636 '/' . $message->type1
);
637 $newAttachment['id'] = strtolower($message->header
->id
);
638 $newAttachment['session'] = $session;
640 /* Write Attachment to file */
641 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
642 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
643 $passed_id, $message->entity_id
),
644 $message->header
->encoding
));
646 $attachments[] = $newAttachment;
649 for ($i = 0; $i < count($message->entities
); $i++
) {
650 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
653 setPref($data_dir, $username, 'attachments', serialize($attachments));
657 function getMessage_RFC822_Attachment($message, $session, $passed_id,
658 $passed_ent_id='', $imapConnection) {
659 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
660 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
661 if (!$passed_ent_id) {
662 $body_a = sqimap_run_command($imapConnection,
663 'FETCH '.$passed_id.' RFC822',
664 true, $response, $readmessage, $uid_support);
666 $body_a = sqimap_run_command($imapConnection,
667 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
668 true, $response, $readmessage, $uid_support);
669 $message = $message->parent
;
671 if ($response = 'OK') {
672 $subject = encodeHeader($message->rfc822_header
->subject
);
673 array_shift($body_a);
674 $body = implode('', $body_a);
677 $localfilename = GenerateRandomString(32, 'FILE', 7);
678 $full_localfilename = "$hashed_attachment_dir/$localfilename";
680 $fp = fopen( $full_localfilename, 'w');
683 $newAttachment = array();
684 $newAttachment['localfilename'] = $localfilename;
685 $newAttachment['type'] = "message/rfc822";
686 $newAttachment['remotefilename'] = $subject.'.eml';
687 $newAttachment['session'] = $session;
688 $attachments[] = $newAttachment;
690 setPref($data_dir, $username, 'attachments', serialize($attachments));
694 function showInputForm ($session, $values=false) {
695 global $send_to, $send_to_cc, $body,
696 $passed_body, $color, $use_signature, $signature, $prefix_sig,
697 $editor_size, $attachments, $subject, $newmail,
698 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
699 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
700 $username, $data_dir, $identity, $draft_id, $delete_draft,
701 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
702 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
705 $subject = decodeHeader($subject, false);
707 $send_to = $values['send_to'];
708 $send_to_cc = $values['send_to_cc'];
709 $send_to_bcc = $values['send_to_bcc'];
710 $subject = $values['subject'];
711 $mailprio = $values['mailprio'];
712 $body = $values['body'];
713 $identity = $values['identity'];
716 if ($use_javascript_addr_book) {
717 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
718 'function open_abook() { ' . "\n" .
719 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
720 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
721 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
722 ' nwin.opener = document.windows;' . "\n" .
724 '// --></SCRIPT>' . "\n\n";
727 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
728 'ENCTYPE="multipart/form-data"';
729 do_hook("compose_form");
734 if ($action == 'draft') {
735 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
737 if (isset($delete_draft)) {
738 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
740 if (isset($session)) {
741 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
744 if (isset($passed_id)) {
745 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
748 if ($saved_draft == 'yes') {
749 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
751 if ($mail_sent == 'yes') {
752 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
754 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
755 if ($compose_new_win == '1') {
756 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
757 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
759 if ($location_of_buttons == 'top') {
760 showComposeButtonRow();
763 $idents = getPref($data_dir, $username, 'identities', 0);
765 echo ' <TR>' . "\n" .
766 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
769 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
770 '<select name=identity>' . "\n" .
771 '<option value=default>' .
772 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
773 $em = getPref($data_dir, $username, 'email_address');
775 echo htmlspecialchars(' <' . $em . '>') . "\n";
777 for ($i = 1; $i < $idents; $i ++
) {
778 echo '<option value="' . $i . '"';
779 if (isset($identity) && $identity == $i) {
782 echo '>' . htmlspecialchars(getPref($data_dir, $username,
784 $em = getPref($data_dir, $username, 'email_address' . $i);
786 echo htmlspecialchars(' <' . $em . '>') . "\n";
790 echo '</select>' . "\n" .
794 echo ' <TR>' . "\n" .
795 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
797 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
798 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
799 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
803 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
805 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
806 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
807 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
811 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
813 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
814 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
815 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
816 '</TD></TR>' . "\n" .
818 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
820 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
821 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
822 htmlspecialchars($subject) . '">';
823 echo '</td></tr>' . "\n\n";
825 if ($location_of_buttons == 'between') {
826 showComposeButtonRow();
828 if ($compose_new_win == '1') {
829 echo ' <TR>' . "\n" .
830 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
831 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
832 $editor_size . '" WRAP="VIRTUAL">';
835 echo ' <TR>' . "\n" .
836 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
837 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
838 $editor_size . '" WRAP="VIRTUAL">';
840 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
841 if ($sig_first == '1') {
842 if ($charset == 'iso-2022-jp') {
843 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
845 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
847 echo "\n\n".htmlspecialchars($body);
850 echo "\n\n".htmlspecialchars($body);
851 if ($charset == 'iso-2022-jp') {
852 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
854 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
859 echo htmlspecialchars($body);
861 echo '</TEXTAREA><BR>' . "\n" .
865 if ($location_of_buttons == 'bottom') {
866 showComposeButtonRow();
868 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>';
869 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">';
870 echo ' <BR><BR>';
871 echo ' </TD></TR>' . "\n";
874 /* This code is for attachments */
875 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">';
877 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
879 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
882 echo ' <TR>' . "\n" .
883 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
886 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
887 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
888 ' <input type="submit" name="attach"' .
889 ' value="' . _("Add") .'">' . "\n" .
895 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
896 foreach ($attachments as $key => $info) {
897 if ($info['session'] == $session) {
898 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
899 $s_a[] = '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
900 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
901 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
905 foreach ($s_a as $s) {
906 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
908 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
909 _("Delete selected attachments") . "\">\n" .
912 echo ' </table></td></tr>';
916 /* End of attachment code */
917 if ($compose_new_win == '1') {
918 echo '</TABLE>'."\n";
920 echo '</TABLE>' . "\n";
922 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
923 echo '<input type=hidden name=action value=' . $action . ">\n";
924 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
927 do_hook('compose_bottom');
928 echo '</BODY></HTML>' . "\n";
932 function showComposeButtonRow() {
933 global $use_javascript_addr_book, $save_as_draft,
934 $default_use_priority, $mailprio, $default_use_mdn,
935 $request_mdn, $request_dr,
936 $data_dir, $username;
938 echo " <TR><TD>\n</TD><TD>\n";
939 if ($default_use_priority) {
940 if(!isset($mailprio)) {
943 echo _("Priority") .': <select name="mailprio">'.
944 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
945 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
946 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
949 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
950 if ($default_use_mdn) {
951 if ($mdn_user_support) {
952 echo "\n\t". _("Receipt") .': '.
953 '<input type="checkbox" name="request_mdn" value=1'.
954 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
955 ' <input type="checkbox" name="request_dr" value=1'.
956 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
960 echo " </td></tr>\n <TR><td>\n </td><td>\n";
961 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
962 if ($use_javascript_addr_book) {
963 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
964 " <input type=button value=\\\""._("Addresses").
965 "\\\" onclick='javascript:open_abook();'>\");".
966 " // --></SCRIPT><NOSCRIPT>\n".
967 " <input type=submit name=\"html_addr_search\" value=\"".
968 _("Addresses")."\">".
971 echo " <input type=submit name=\"html_addr_search\" value=\"".
972 _("Addresses")."\">";
975 if ($save_as_draft) {
976 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
979 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
980 do_hook('compose_button_row');
982 echo " </TD></TR>\n\n";
985 function checkInput ($show) {
987 * I implemented the $show variable because the error messages
988 * were getting sent before the page header. So, I check once
989 * using $show=false, and then when i'm ready to display the error
992 global $body, $send_to, $subject, $color;
994 if ($send_to == "") {
996 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1001 } /* function checkInput() */
1004 /* True if FAILURE */
1005 function saveAttachedFiles($session) {
1006 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1009 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1010 $localfilename = GenerateRandomString(32, '', 7);
1011 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1012 while (file_exists($full_localfilename)) {
1013 $localfilename = GenerateRandomString(32, '', 7);
1014 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1017 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1018 if (function_exists("move_uploaded_file")) {
1019 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1023 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1029 $newAttachment['localfilename'] = $localfilename;
1030 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
1031 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
1032 $newAttachment['session'] = $session;
1034 if ($newAttachment['type'] == "") {
1035 $newAttachment['type'] = 'application/octet-stream';
1037 $attachments[] = $newAttachment;
1038 setPref($data_dir, $username, 'attachments', serialize($attachments));
1042 function ClearAttachments($session)
1044 global $username, $attachments, $attachment_dir, $data_dir;
1045 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1047 $rem_attachments = array();
1048 if (is_array($attachments)) {
1049 foreach ($attachments as $info) {
1050 if ($info['session'] == $session) {
1051 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
1052 if (file_exists($attached_file)) {
1053 unlink($attached_file);
1057 $rem_attachments[] = $info;
1061 $attachments = $rem_attachments;
1062 setPref($data_dir, $username, 'attachments', serialize($attachments));
1066 function getReplyCitation($orig_from)
1068 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1070 /* First, return an empty string when no citation style selected. */
1071 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1075 /* Make sure our final value isn't an empty string. */
1076 if ($orig_from == '') {
1080 /* Otherwise, try to select the desired citation style. */
1081 switch ($reply_citation_style) {
1084 $end = ' ' . _("said") . ':';
1087 $start = '<' . _("quote") . ' ' . _("who") . '="';
1090 case 'user-defined':
1091 $start = $reply_citation_start .
1092 ($reply_citation_start == '' ?
'' : ' ');
1093 $end = $reply_citation_end;
1099 /* Build and return the citation string. */
1100 return ($start . $orig_from . $end . "\n");