a1f835f89193c54eaff5f5b41a4e37112c105627
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 /* --------------------- Specific Functions ------------------------------ */
29 function replyAllString($header) {
30 global $include_self_reply_all, $username, $data_dir;
33 * 1) Remove the addresses we'll be sending the message 'to'
35 $url_replytoall_avoid_addrs = '';
36 if (isset($header->replyto
)) {
37 $excl_ar = $header->getAddr_a('replyto');
40 * 2) Remove our identities from the CC list (they still can be in the
41 * TO list) only if $include_self_reply_all is turned off
43 if (!$include_self_reply_all) {
44 $email_address = trim(getPref($data_dir, $username, 'email_address'));
45 $excl_ar[$email_address] = '';
47 $idents = getPref($data_dir, $username, 'identities');
48 if ($idents != '' && $idents > 1) {
49 for ($i = 1; $i < $idents; $i ++
) {
50 $cur_email_address = getPref($data_dir, $username,
51 'email_address' . $i);
52 $cur_email_address = strtolower($cur_email_address);
53 $excl_ar[$cur_email_address] = '';
59 * 3) get the addresses.
61 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
64 * 4) generate the string.
66 $url_replytoallcc = '';
67 foreach( $url_replytoall_ar as $email => $personal) {
69 $url_replytoallcc .= ", \"$personal\" <$email>";
71 $url_replytoallcc .= ', '. $email;
74 $url_replytoallcc = substr($url_replytoallcc,2);
75 return $url_replytoallcc;
78 function getforwardHeader($orig_header) {
79 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
80 _("Subject") . ': ' . $orig_header->subject
. "\n" .
81 _("From") . ': ' . $orig_header->from
->getAddress() . "\n" .
83 getLongDateString( $orig_header->date
). "\n" .
84 _("To") . ': ' . $orig_header->to
[0]->getAddress() . "\n";
85 if (count($orig_header->to
) > 1) {
86 for ($x=1; $x < count($orig_header->to
); $x++
) {
87 $bodyTop .= ' ' . $orig_header->to
[$x]->getAddress() . "\n";
90 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
91 $bodyTop .= _("Cc") . ': ' . $orig_header->cc
[0]->getAddress() . "\n";
92 if (count($orig_header->cc
) > 1) {
93 for ($x = 1; $x < count($orig_header->cc
); $x++
) {
94 $bodyTop .= ' ' . $orig_header->cc
[$x]->getAddress() . "\n";
101 /* ----------------------------------------------------------------------- */
104 * If the session is expired during a post this restores the compose session
107 //$session_expired = false;
108 if (session_is_registered('session_expired_post')) {
109 global $session_expired_post, $session_expired;
111 * extra check for username so we don't display previous post data from
112 * another user during this session.
114 if ($session_expired_post['username'] != $username) {
115 session_unregister('session_expired_post');
116 session_unregister('session_expired');
118 foreach ($session_expired_post as $postvar => $val) {
128 $session_expired = true;
130 session_unregister('session_expired_post');
131 session_unregister('session_expired');
132 if ($compose_new_win == '1') {
133 compose_Header($color, $mailbox);
135 displayPageHeader($color, $mailbox);
137 showInputForm($session, false);
141 if (!isset($attachments)) {
142 $attachments = array();
143 session_register('attachments');
146 if (!isset($composesession)) {
148 session_register('composesession');
151 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
152 $session = "$composesession" +
1;
153 $composesession = $session;
156 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
161 include_once ('../src/draft_actions.php');
162 if (! isset($reply_id)) {
168 if (! isset($mailprio)) {
171 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $mailprio, $session)) {
172 showInputForm($session);
175 $draft_message = _("Draft Email Saved");
176 /* If this is a resumed draft, then delete the original */
177 if(isset($delete_draft)) {
178 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
179 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
183 if ($compose_new_win == '1') {
184 Header("Location: compose.php?saved_draft=yes&session=$composesession");
188 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
189 "&startMessage=1¬e=".urlencode($draft_message));
197 if (isset($HTTP_POST_FILES['attachfile']) &&
198 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
199 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
200 $AttachFailure = saveAttachedFiles($session);
202 if (checkInput(false) && !isset($AttachFailure)) {
203 $urlMailbox = urlencode (trim($mailbox));
204 if (! isset($reply_id)) {
208 * Set $default_charset to correspond with the user's selection
209 * of language interface.
214 * This is to change all newlines to \n
215 * We'll change them to \r\n later (in the sendMessage function)
217 $body = str_replace("\r\n", "\n", $body);
218 $body = str_replace("\r", "\n", $body);
221 * Rewrap $body so that no line is bigger than $editor_size
222 * This should only really kick in the sqWordWrap function
223 * if the browser doesn't support "VIRTUAL" as the wrap type.
225 $body = explode("\n", $body);
227 foreach ($body as $line) {
228 if( $line <> '-- ' ) {
229 $line = rtrim($line);
231 if (strlen($line) <= $editor_size +
1) {
232 $newBody .= $line . "\n";
234 sqWordWrap($line, $editor_size);
235 $newBody .= $line . "\n";
240 do_hook('compose_send');
242 $MDN = False; // we are not sending a mdn response
243 if (! isset($mailprio)) {
244 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
245 $subject, $body, $reply_id, $MDN, '', $session);
247 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
248 $subject, $body, $reply_id, $MDN, $mailprio, $session);
251 showInputForm($session);
254 if ( isset($delete_draft)) {
255 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
256 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
259 if ($compose_new_win == '1') {
260 Header("Location: compose.php?mail_sent=yes");
263 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
268 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
271 if ($compose_new_win == '1') {
272 compose_Header($color, $mailbox);
275 displayPageHeader($color, $mailbox);
277 if (isset($AttachFailure)) {
278 plain_error_message(_("Could not move/copy file. File not attached"),
282 showInputForm($session);
283 /* sqimap_logout($imapConnection); */
285 } elseif (isset($html_addr_search_done)) {
286 if ($compose_new_win == '1') {
287 compose_Header($color, $mailbox);
290 displayPageHeader($color, $mailbox);
293 if (isset($send_to_search) && is_array($send_to_search)) {
294 foreach ($send_to_search as $k => $v) {
295 if (substr($k, 0, 1) == 'T') {
301 elseif (substr($k, 0, 1) == 'C') {
307 elseif (substr($k, 0, 1) == 'B') {
309 $send_to_bcc .= ', ';
315 showInputForm($session);
316 } elseif (isset($html_addr_search)) {
317 if (isset($HTTP_POST_FILES['attachfile']) &&
318 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
319 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
320 if (saveAttachedFiles($session)) {
321 plain_error_message(_("Could not move/copy file. File not attached"), $color);
325 * I am using an include so as to elminiate an extra unnecessary
326 * click. If you can think of a better way, please implement it.
328 include_once('./addrbook_search_html.php');
329 } elseif (isset($attach)) {
330 if (saveAttachedFiles($session)) {
331 plain_error_message(_("Could not move/copy file. File not attached"), $color);
333 if ($compose_new_win == '1') {
334 compose_Header($color, $mailbox);
337 displayPageHeader($color, $mailbox);
339 showInputForm($session);
341 elseif (isset($sigappend)) {
342 $idents = getPref($data_dir, $username, 'identities', 0);
344 if ($identity == 'default') {
349 $signature = getSig($data_dir, $username, $no);
351 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
352 if ($compose_new_win == '1') {
353 compose_Header($color, $mailbox);
355 displayPageHeader($color, $mailbox);
357 showInputForm($session);
358 } elseif (isset($do_delete)) {
359 if ($compose_new_win == '1') {
360 compose_Header($color, $mailbox);
363 displayPageHeader($color, $mailbox);
366 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
367 if (isset($delete) && is_array($delete)) {
368 foreach($delete as $index) {
369 $attached_file = $hashed_attachment_dir . '/'
370 . $attachments[$index]['localfilename'];
371 unlink ($attached_file);
372 unset ($attachments[$index]);
376 showInputForm($session);
378 } elseif (isset($attachedmessages)) {
381 * This handles the case if we attache message
383 if ($compose_new_win == '1') {
384 compose_Header($color, $mailbox);
386 displayPageHeader($color, $mailbox);
391 if (!isset($passed_ent_id)) $passed_ent_id = '';
392 if (!isset($passed_id)) $passed_id = '';
393 if (!isset($mailbox)) $mailbox = '';
394 if (!isset($action)) $action = '';
396 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
397 /* in case the origin is not read_body.php */
398 if (isset($send_to)) {
399 $values['send_to'] = $send_to;
401 if (isset($send_to_cc)) {
402 $values['send_to_cc'] = $send_cc;
404 if (isset($send_to_bcc)) {
405 $values['send_to_bcc'] = $send_bcc;
408 showInputForm($session, $values);
411 * This handles the default case as well as the error case
412 * (they had the same code) --> if (isset($smtpErrors))
415 if ($compose_new_win == '1') {
416 compose_Header($color, $mailbox);
418 displayPageHeader($color, $mailbox);
423 if (!isset($passed_ent_id)) $passed_ent_id = '';
424 if (!isset($passed_id)) $passed_id = '';
425 if (!isset($mailbox)) $mailbox = '';
426 if (!isset($action)) $action = '';
428 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
430 /* in case the origin is not read_body.php */
431 if (isset($send_to)) {
432 $values['send_to'] = $send_to;
434 if (isset($send_to_cc)) {
435 $values['send_to_cc'] = $send_to_cc;
437 if (isset($send_to_bcc)) {
438 $values['send_to_bcc'] = $send_to_bcc;
440 showInputForm($session, $values);
445 /**************** Only function definitions go below *************/
448 /* This function is used when not sending or adding attachments */
449 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
450 global $editor_size, $default_use_priority,
451 $use_signature, $composesession, $data_dir, $username,
452 $username, $key, $imapServerAddress, $imapPort;
454 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
458 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
461 sqimap_mailbox_select($imapConnection, $mailbox);
462 $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->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->header
;
489 $encoding = $message->header
->encoding
;
490 $type0 = $message->type0
;
491 $type1 = $message->type1
;
493 foreach ($entities as $ent) {
494 $bodypart = decodeBody(
495 mime_fetch_body($imapConnection, $passed_id, $ent),
497 if ($type1 == 'html') {
498 $bodypart = strip_tags($bodypart);
502 if ($default_use_priority) {
503 $mailprio = substr($orig_header->priority
,0,1);
507 ClearAttachments($session);
510 $idents = getPref($data_dir, $username, 'identities');
511 $from_o = $message->header
->from
;
512 if (is_object($from_o)) {
513 $orig_from = $from_o->getAddress();
517 if (!empty($idents) && $idents > 1) {
518 for ($i = 1; $i < $idents; $i++
) {
519 $enc_from_name = '"'.
523 '" <' . getPref($data_dir, $username,
524 'email_address' . $i) . '>';
525 if ($enc_from_name == $orig_from) {
534 $use_signature = FALSE;
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 = $orig_header->subject
;
540 $body_ary = explode("\n", $body);
541 $cnt = count($body_ary) ;
543 for ($i=0; $i < $cnt; $i++
) {
544 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
545 sqWordWrap($body_ary[$i], $editor_size );
546 $body .= $body_ary[$i] . "\n";
548 unset($body_ary[$i]);
551 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
553 case ('edit_as_new'):
554 $send_to = $orig_header->getAddr_s('to');
555 $send_to_cc = $orig_header->getAddr_s('cc');
556 $send_to_bcc = $orig_header->getAddr_s('bcc');
557 $subject = $orig_header->subject
;
558 $mailprio = $orig_header->priority
;
560 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
565 $subject = $orig_header->subject
;
566 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
567 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
568 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
569 $subject = '[Fwd: ' . $subject . ']';
571 $body = getforwardHeader($orig_header) . $body;
573 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
575 case ('reply' ||
'reply_all'):
576 $send_to = $orig_header->reply_to
;
578 $send_to = $send_to->getAddress();
580 $send_to = $orig_header->from
->getAddress();
582 $subject = $orig_header->subject
;
583 $subject = str_replace('"', "'", $subject);
584 $subject = trim($subject);
585 if (substr(strtolower($subject), 0, 3) != 're:') {
586 $subject = 'Re: ' . $subject;
588 if ($action == 'reply_all') {
589 $send_to_cc = replyAllString($orig_header);
591 /* this corrects some wrapping/quoting problems on replies */
592 $rewrap_body = explode("\n", $body);
593 $body = getReplyCitation($orig_header->from
->personal
);
594 $cnt = count($rewrap_body);
595 for ($i=0;$i<$cnt;$i++
) {
596 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
597 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
599 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
601 $body .= '> ' . $rewrap_body[$i] . "\n";
603 unset($rewrap_body[$i]);
609 sqimap_logout($imapConnection);
612 'send_to' => $send_to,
613 'send_to_cc' => $send_to_cc,
614 'send_to_bcc' => $send_to_bcc,
615 'subject' => $subject,
616 'mailprio' => $mailprio,
618 'identity' => $identity
622 } /* function newMail() */
625 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
626 global $attachments, $attachment_dir, $username;
628 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
629 if (!count($message->entities
) ||
630 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
631 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
632 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
633 $filename = decodeHeader($message->header
->subject
.'.eml');
634 if ($filename == "") {
635 $filename = "untitled-".$message->entity_id
.'.eml';
638 $filename = decodeHeader($message->header
->filename
);
639 if ($filename == "") {
640 $filename = "untitled-".$message->entity_id
;
643 $localfilename = GenerateRandomString(32, '', 7);
644 $full_localfilename = "$hashed_attachment_dir/$localfilename";
645 while (file_exists($full_localfilename)) {
646 $localfilename = GenerateRandomString(32, '', 7);
647 $full_localfilename = "$hashed_attachment_dir/$localfilename";
650 $newAttachment = array();
651 $newAttachment['localfilename'] = $localfilename;
652 $newAttachment['remotefilename'] = $filename;
653 $newAttachment['type'] = strtolower($message->type0
.
654 '/' . $message->type1
);
655 $newAttachment['id'] = strtolower($message->header
->id
);
656 $newAttachment['session'] = $session;
658 /* Write Attachment to file */
659 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
660 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
661 $passed_id, $message->entity_id
),
662 $message->header
->encoding
));
665 $attachments[] = $newAttachment;
668 for ($i = 0; $i < count($message->entities
); $i++
) {
669 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
675 function showInputForm ($session, $values=false) {
676 global $send_to, $send_to_cc, $body,
677 $passed_body, $color, $use_signature, $signature, $prefix_sig,
678 $editor_size, $attachments, $subject, $newmail,
679 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
680 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
681 $username, $data_dir, $identity, $draft_id, $delete_draft,
682 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
683 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
686 $subject = decodeHeader($subject, false);
688 $send_to = $values['send_to'];
689 $send_to_cc = $values['send_to_cc'];
690 $send_to_bcc = $values['send_to_bcc'];
691 $subject = $values['subject'];
692 $mailprio = $values['mailprio'];
693 $body = $values['body'];
694 $identity = $values['identity'];
697 if ($use_javascript_addr_book) {
698 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
699 'function open_abook() { ' . "\n" .
700 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
701 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
702 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
703 ' nwin.opener = document.windows;' . "\n" .
705 '// --></SCRIPT>' . "\n\n";
708 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
709 'ENCTYPE="multipart/form-data"';
710 do_hook("compose_form");
715 if ($action == 'draft') {
716 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
718 if (isset($delete_draft)) {
719 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
721 if (isset($session)) {
722 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
726 if ($saved_draft == 'yes') {
727 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
729 if ($mail_sent == 'yes') {
730 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
732 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
733 if ($compose_new_win == '1') {
734 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
735 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
737 if ($location_of_buttons == 'top') {
738 showComposeButtonRow();
741 $idents = getPref($data_dir, $username, 'identities', 0);
743 echo ' <TR>' . "\n" .
744 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
747 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
748 '<select name=identity>' . "\n" .
749 '<option value=default>' .
750 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
751 $em = getPref($data_dir, $username, 'email_address');
753 echo htmlspecialchars(' <' . $em . '>') . "\n";
755 for ($i = 1; $i < $idents; $i ++
) {
756 echo '<option value="' . $i . '"';
757 if (isset($identity) && $identity == $i) {
760 echo '>' . htmlspecialchars(getPref($data_dir, $username,
762 $em = getPref($data_dir, $username, 'email_address' . $i);
764 echo htmlspecialchars(' <' . $em . '>') . "\n";
768 echo '</select>' . "\n" .
772 echo ' <TR>' . "\n" .
773 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
775 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
776 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
777 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
781 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
783 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
784 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
785 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
789 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
791 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
792 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
793 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
794 '</TD></TR>' . "\n" .
796 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
798 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
799 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
800 htmlspecialchars($subject) . '">';
801 echo '</td></tr>' . "\n\n";
803 if ($location_of_buttons == 'between') {
804 showComposeButtonRow();
806 if ($compose_new_win == '1') {
807 echo ' <TR>' . "\n" .
808 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
809 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
810 $editor_size . '" WRAP="VIRTUAL">';
813 echo ' <TR>' . "\n" .
814 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
815 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
816 $editor_size . '" WRAP="VIRTUAL">';
818 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
819 if ($sig_first == '1') {
820 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
821 echo "\n\n".htmlspecialchars($body);
824 echo "\n\n".htmlspecialchars($body);
825 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
829 echo htmlspecialchars($body);
831 echo '</TEXTAREA><BR>' . "\n" .
835 if ($location_of_buttons == 'bottom') {
836 showComposeButtonRow();
838 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
839 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
842 /* This code is for attachments */
843 echo ' <TR>' . "\n" .
844 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
847 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
848 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
849 ' <input type="submit" name="attach"' .
850 ' value="' . _("Add") .'">' . "\n" .
854 if (count($attachments)) {
855 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
856 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
858 '</td><td align=left bgcolor="' . $color[0] . '">';
859 foreach ($attachments as $key => $info) {
860 if ($info['session'] == $session) {
861 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
862 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
863 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
864 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
868 echo '<input type="submit" name="do_delete" value="' .
869 _("Delete selected attachments") . "\">\n" .
872 /* End of attachment code */
873 if ($compose_new_win == '1') {
874 echo '</TABLE>'."\n";
876 echo '</TABLE>' . "\n";
878 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
879 echo '<input type=hidden name=action value=' . $action . ">\n";
880 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
883 do_hook('compose_bottom');
884 echo '</BODY></HTML>' . "\n";
888 function showComposeButtonRow() {
889 global $use_javascript_addr_book, $save_as_draft,
890 $default_use_priority, $mailprio, $default_use_mdn,
891 $request_mdn, $request_dr,
892 $data_dir, $username;
894 echo " <TR><TD>\n</TD><TD>\n";
895 if ($default_use_priority) {
896 if(!isset($mailprio)) {
899 echo _("Priority") .': <select name="mailprio">'.
900 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
901 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
902 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
905 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
906 if ($default_use_mdn) {
907 if ($mdn_user_support) {
908 echo "\n\t". _("Receipt") .': '.
909 '<input type="checkbox" name="request_mdn" value=1'.
910 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
911 ' <input type="checkbox" name="request_dr" value=1'.
912 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
916 echo " </td></tr>\n <TR><td>\n </td><td>\n";
917 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
918 if ($use_javascript_addr_book) {
919 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
920 " <input type=button value=\\\""._("Addresses").
921 "\\\" onclick='javascript:open_abook();'>\");".
922 " // --></SCRIPT><NOSCRIPT>\n".
923 " <input type=submit name=\"html_addr_search\" value=\"".
924 _("Addresses")."\">".
927 echo " <input type=submit name=\"html_addr_search\" value=\"".
928 _("Addresses")."\">";
930 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
932 if ($save_as_draft) {
933 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
936 do_hook('compose_button_row');
938 echo " </TD></TR>\n\n";
941 function checkInput ($show) {
943 * I implemented the $show variable because the error messages
944 * were getting sent before the page header. So, I check once
945 * using $show=false, and then when i'm ready to display the error
948 global $body, $send_to, $subject, $color;
950 if ($send_to == "") {
952 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
957 } /* function checkInput() */
960 /* True if FAILURE */
961 function saveAttachedFiles($session) {
962 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
964 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
965 $localfilename = GenerateRandomString(32, '', 7);
966 $full_localfilename = "$hashed_attachment_dir/$localfilename";
967 while (file_exists($full_localfilename)) {
968 $localfilename = GenerateRandomString(32, '', 7);
969 $full_localfilename = "$hashed_attachment_dir/$localfilename";
972 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
973 if (function_exists("move_uploaded_file")) {
974 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
979 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
985 $newAttachment['localfilename'] = $localfilename;
986 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
987 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
988 $newAttachment['session'] = $session;
990 if ($newAttachment['type'] == "") {
991 $newAttachment['type'] = 'application/octet-stream';
994 $attachments[] = $newAttachment;
998 function ClearAttachments($session)
1000 global $username, $attachments, $attachment_dir;
1001 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1003 $rem_attachments = array();
1004 if (is_array($attachments)) {
1005 foreach ($attachments as $info) {
1006 if ($info['session'] == $session) {
1007 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
1008 if (file_exists($attached_file)) {
1009 unlink($attached_file);
1013 $rem_attachments[] = $info;
1017 $attachments = $rem_attachments;
1021 function getReplyCitation($orig_from)
1023 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1025 /* First, return an empty string when no citation style selected. */
1026 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1030 /* Make sure our final value isn't an empty string. */
1031 if ($orig_from == '') {
1035 /* Otherwise, try to select the desired citation style. */
1036 switch ($reply_citation_style) {
1039 $end = ' ' . _("said") . ':';
1042 $start = '<' . _("quote") . ' ' . _("who") . '="';
1045 case 'user-defined':
1046 $start = $reply_citation_start . ' ';
1047 $end = $reply_citation_end;
1053 /* Build and return the citation string. */
1054 return ($start . $orig_from . $end . "\n");