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) {
80 _("Subject") => strlen(_("Subject")),
81 _("From") => strlen(_("From")),
82 _("Date") => strlen(_("Date")),
83 _("To") => strlen(_("To")),
84 _("Cc") => strlen(_("Cc"))
86 $maxsize = max($display);
87 $indent = str_pad('',$maxsize+
2);
88 foreach($display as $key => $val) {
89 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
91 $bodyTop = str_pad(' '._("Original Message").' ',78, '-',STR_PAD_BOTH
);
92 $bodyTop .= "\n". $display[_("Subject")] . $orig_header->subject
. "\n" .
93 $display[_("From")] . $orig_header->getAddr_s('from',"\n$indent") . "\n" .
94 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
95 $display[_("To")] . $orig_header->getAddr_s('to',"\n$indent") ."\n";
96 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
97 $bodyTop .= $display[_("Cc")] . $orig_header->getAddr_s('cc',"\n$indent") . "\n";
99 $bodyTop .= str_pad('',78, '-');
103 /* ----------------------------------------------------------------------- */
106 * If the session is expired during a post this restores the compose session
109 //$session_expired = false;
110 if (session_is_registered('session_expired_post')) {
111 global $session_expired_post, $session_expired;
113 * extra check for username so we don't display previous post data from
114 * another user during this session.
116 if ($session_expired_post['username'] != $username) {
117 session_unregister('session_expired_post');
118 session_unregister('session_expired');
120 foreach ($session_expired_post as $postvar => $val) {
130 $session_expired = true;
132 session_unregister('session_expired_post');
133 session_unregister('session_expired');
134 if (!isset($mailbox)) {
137 if ($compose_new_win == '1') {
138 compose_Header($color, $mailbox);
140 displayPageHeader($color, $mailbox);
142 showInputForm($session, false);
146 if (!isset($attachments)) {
147 $attachments = array();
148 session_register('attachments');
151 if (!isset($composesession)) {
153 session_register('composesession');
156 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
157 $session = "$composesession" +
1;
158 $composesession = $session;
161 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
166 include_once ('../src/draft_actions.php');
167 if (! isset($passed_id)) {
173 if (! isset($mailprio)) {
176 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
177 showInputForm($session);
180 $draft_message = _("Draft Email Saved");
181 /* If this is a resumed draft, then delete the original */
182 if(isset($delete_draft)) {
183 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
184 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
188 if ($compose_new_win == '1') {
189 Header("Location: compose.php?saved_draft=yes&session=$composesession");
193 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
194 "&startMessage=1¬e=".urlencode($draft_message));
202 if (isset($HTTP_POST_FILES['attachfile']) &&
203 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
204 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
205 $AttachFailure = saveAttachedFiles($session);
207 if (checkInput(false) && !isset($AttachFailure)) {
208 $urlMailbox = urlencode (trim($mailbox));
209 if (! isset($passed_id)) {
213 * Set $default_charset to correspond with the user's selection
214 * of language interface.
219 * This is to change all newlines to \n
220 * We'll change them to \r\n later (in the sendMessage function)
222 $body = str_replace("\r\n", "\n", $body);
223 $body = str_replace("\r", "\n", $body);
226 * Rewrap $body so that no line is bigger than $editor_size
227 * This should only really kick in the sqWordWrap function
228 * if the browser doesn't support "VIRTUAL" as the wrap type.
230 $body = explode("\n", $body);
232 foreach ($body as $line) {
233 if( $line <> '-- ' ) {
234 $line = rtrim($line);
236 if (strlen($line) <= $editor_size +
1) {
237 $newBody .= $line . "\n";
239 sqWordWrap($line, $editor_size);
240 $newBody .= $line . "\n";
245 do_hook('compose_send');
247 $MDN = False; // we are not sending a mdn response
248 if (! isset($mailprio)) {
249 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
250 $subject, $body, $passed_id, $MDN, '', $session);
252 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
253 $subject, $body, $passed_id, $MDN, $mailprio, $session);
256 showInputForm($session);
259 if ( isset($delete_draft)) {
260 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
261 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
264 if ($compose_new_win == '1') {
265 Header("Location: compose.php?mail_sent=yes");
268 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
273 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
276 if ($compose_new_win == '1') {
277 compose_Header($color, $mailbox);
280 displayPageHeader($color, $mailbox);
282 if (isset($AttachFailure)) {
283 plain_error_message(_("Could not move/copy file. File not attached"),
287 showInputForm($session);
288 /* sqimap_logout($imapConnection); */
290 } elseif (isset($html_addr_search_done)) {
291 if ($compose_new_win == '1') {
292 compose_Header($color, $mailbox);
295 displayPageHeader($color, $mailbox);
298 if (isset($send_to_search) && is_array($send_to_search)) {
299 foreach ($send_to_search as $k => $v) {
300 if (substr($k, 0, 1) == 'T') {
306 elseif (substr($k, 0, 1) == 'C') {
312 elseif (substr($k, 0, 1) == 'B') {
314 $send_to_bcc .= ', ';
320 showInputForm($session);
321 } elseif (isset($html_addr_search)) {
322 if (isset($HTTP_POST_FILES['attachfile']) &&
323 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
324 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
325 if (saveAttachedFiles($session)) {
326 plain_error_message(_("Could not move/copy file. File not attached"), $color);
330 * I am using an include so as to elminiate an extra unnecessary
331 * click. If you can think of a better way, please implement it.
333 include_once('./addrbook_search_html.php');
334 } elseif (isset($attach)) {
335 if (saveAttachedFiles($session)) {
336 plain_error_message(_("Could not move/copy file. File not attached"), $color);
338 if ($compose_new_win == '1') {
339 compose_Header($color, $mailbox);
342 displayPageHeader($color, $mailbox);
344 showInputForm($session);
346 elseif (isset($sigappend)) {
347 $idents = getPref($data_dir, $username, 'identities', 0);
349 if ($identity == 'default') {
354 $signature = getSig($data_dir, $username, $no);
356 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
357 if ($compose_new_win == '1') {
358 compose_Header($color, $mailbox);
360 displayPageHeader($color, $mailbox);
362 showInputForm($session);
363 } elseif (isset($do_delete)) {
364 if ($compose_new_win == '1') {
365 compose_Header($color, $mailbox);
368 displayPageHeader($color, $mailbox);
371 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
372 if (isset($delete) && is_array($delete)) {
373 foreach($delete as $index) {
374 $attached_file = $hashed_attachment_dir . '/'
375 . $attachments[$index]['localfilename'];
376 unlink ($attached_file);
377 unset ($attachments[$index]);
379 setPref($data_dir, $username, 'attachments', serialize($attachments));
382 showInputForm($session);
385 * This handles the default case as well as the error case
386 * (they had the same code) --> if (isset($smtpErrors))
389 if ($compose_new_win == '1') {
390 compose_Header($color, $mailbox);
392 displayPageHeader($color, $mailbox);
397 if (!isset($passed_ent_id)) $passed_ent_id = '';
398 if (!isset($passed_id)) $passed_id = '';
399 if (!isset($mailbox)) $mailbox = '';
400 if (!isset($action)) $action = '';
402 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
404 /* in case the origin is not read_body.php */
405 if (isset($send_to)) {
406 $values['send_to'] = $send_to;
408 if (isset($send_to_cc)) {
409 $values['send_to_cc'] = $send_to_cc;
411 if (isset($send_to_bcc)) {
412 $values['send_to_bcc'] = $send_to_bcc;
414 showInputForm($session, $values);
419 /**************** Only function definitions go below *************/
422 /* This function is used when not sending or adding attachments */
423 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
424 global $editor_size, $default_use_priority,
425 $use_signature, $composesession, $data_dir, $username,
426 $username, $key, $imapServerAddress, $imapPort;
428 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
432 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
435 sqimap_mailbox_select($imapConnection, $mailbox);
436 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
438 if ($passed_ent_id) {
439 /* redefine the messsage in case of message/rfc822 */
440 $message = $message->getEntity($passed_ent_id);
441 /* message is an entity which contains the envelope and type0=message
442 * and type1=rfc822. The actual entities are childs from
443 * $message->entities[0]. That's where the encoding and is located
446 $entities = $message->entities
[0]->findDisplayEntity
447 (array(), $alt_order = array('text/plain'));
448 if (!count($entities)) {
449 $entities = $message->entities
[0]->findDisplayEntity
450 (array(), $alt_order = array('text/plain','html/plain'));
452 $orig_header = $message->rfc822_header
; /* here is the envelope located */
453 /* redefine the message for picking up the attachments */
454 $message = $message->entities
[0];
457 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
458 if (!count($entities)) {
459 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
461 $orig_header = $message->rfc822_header
;
463 $encoding = $message->header
->encoding
;
464 $type0 = $message->type0
;
465 $type1 = $message->type1
;
467 foreach ($entities as $ent) {
468 $bodypart = decodeBody(
469 mime_fetch_body($imapConnection, $passed_id, $ent),
471 if ($type1 == 'html') {
472 $bodypart = strip_tags($bodypart);
476 if ($default_use_priority) {
477 $mailprio = substr($orig_header->priority
,0,1);
484 ClearAttachments($session);
487 $idents = getPref($data_dir, $username, 'identities');
488 $from_o = $orig_header->from
;
489 if (is_object($from_o)) {
490 $orig_from = $from_o->getAddress();
494 if (!empty($idents) && $idents > 1) {
495 for ($i = 1; $i < $idents; $i++
) {
496 $enc_from_name = '"'.
500 '" <' . getPref($data_dir, $username,
501 'email_address' . $i) . '>';
502 if ($enc_from_name == $orig_from) {
511 $use_signature = FALSE;
512 $send_to = $orig_header->getAddr_s('to');
513 $send_to_cc = $orig_header->getAddr_s('cc');
514 $send_to_bcc = $orig_header->getAddr_s('bcc');
515 $subject = $orig_header->subject
;
517 $body_ary = explode("\n", $body);
518 $cnt = count($body_ary) ;
520 for ($i=0; $i < $cnt; $i++
) {
521 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
522 sqWordWrap($body_ary[$i], $editor_size );
523 $body .= $body_ary[$i] . "\n";
525 unset($body_ary[$i]);
528 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
530 case ('edit_as_new'):
531 $send_to = $orig_header->getAddr_s('to');
532 $send_to_cc = $orig_header->getAddr_s('cc');
533 $send_to_bcc = $orig_header->getAddr_s('bcc');
534 $subject = $orig_header->subject
;
535 $mailprio = $orig_header->priority
;
537 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
542 $subject = $orig_header->subject
;
543 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
544 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
545 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
546 $subject = '[Fwd: ' . $subject . ']';
548 $body = getforwardHeader($orig_header) . $body;
550 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
553 $send_to_cc = replyAllString($orig_header);
555 $send_to = $orig_header->reply_to
;
556 if (is_object($send_to)) {
557 $send_to = $send_to->getAddr_s('reply_to');
559 $send_to = $orig_header->getAddr_s('from');
561 $subject = $orig_header->subject
;
562 $subject = str_replace('"', "'", $subject);
563 $subject = trim($subject);
564 if (substr(strtolower($subject), 0, 3) != 're:') {
565 $subject = 'Re: ' . $subject;
567 /* this corrects some wrapping/quoting problems on replies */
568 $rewrap_body = explode("\n", $body);
569 $body = getReplyCitation($orig_header->from
->personal
);
570 $cnt = count($rewrap_body);
571 for ($i=0;$i<$cnt;$i++
) {
572 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
573 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
575 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
577 $body .= '> ' . $rewrap_body[$i] . "\n";
579 unset($rewrap_body[$i]);
585 sqimap_logout($imapConnection);
588 'send_to' => $send_to,
589 'send_to_cc' => $send_to_cc,
590 'send_to_bcc' => $send_to_bcc,
591 'subject' => $subject,
592 'mailprio' => $mailprio,
594 'identity' => $identity
598 } /* function newMail() */
601 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
602 global $attachments, $attachment_dir, $username, $data_dir;
604 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
605 if (!count($message->entities
) ||
606 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
607 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
608 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
609 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
610 if ($filename == "") {
611 $filename = "untitled-".$message->entity_id
.'.eml';
614 $filename = decodeHeader($message->header
->filename
);
615 if ($filename == "") {
616 $filename = "untitled-".$message->entity_id
;
619 $localfilename = GenerateRandomString(32, '', 7);
620 $full_localfilename = "$hashed_attachment_dir/$localfilename";
621 while (file_exists($full_localfilename)) {
622 $localfilename = GenerateRandomString(32, '', 7);
623 $full_localfilename = "$hashed_attachment_dir/$localfilename";
626 $newAttachment = array();
627 $newAttachment['localfilename'] = $localfilename;
628 $newAttachment['remotefilename'] = $filename;
629 $newAttachment['type'] = strtolower($message->type0
.
630 '/' . $message->type1
);
631 $newAttachment['id'] = strtolower($message->header
->id
);
632 $newAttachment['session'] = $session;
634 /* Write Attachment to file */
635 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
636 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
637 $passed_id, $message->entity_id
),
638 $message->header
->encoding
));
641 $attachments[] = $newAttachment;
642 setPref($data_dir, $username, 'attachments', $attachments);
645 for ($i = 0; $i < count($message->entities
); $i++
) {
646 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
652 function showInputForm ($session, $values=false) {
653 global $send_to, $send_to_cc, $body,
654 $passed_body, $color, $use_signature, $signature, $prefix_sig,
655 $editor_size, $attachments, $subject, $newmail,
656 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
657 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
658 $username, $data_dir, $identity, $draft_id, $delete_draft,
659 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
660 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
663 $subject = decodeHeader($subject, false);
665 $send_to = $values['send_to'];
666 $send_to_cc = $values['send_to_cc'];
667 $send_to_bcc = $values['send_to_bcc'];
668 $subject = $values['subject'];
669 $mailprio = $values['mailprio'];
670 $body = $values['body'];
671 $identity = $values['identity'];
674 if ($use_javascript_addr_book) {
675 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
676 'function open_abook() { ' . "\n" .
677 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
678 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
679 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
680 ' nwin.opener = document.windows;' . "\n" .
682 '// --></SCRIPT>' . "\n\n";
685 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
686 'ENCTYPE="multipart/form-data"';
687 do_hook("compose_form");
692 if ($action == 'draft') {
693 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
695 if (isset($delete_draft)) {
696 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
698 if (isset($session)) {
699 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
703 if ($saved_draft == 'yes') {
704 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
706 if ($mail_sent == 'yes') {
707 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
709 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
710 if ($compose_new_win == '1') {
711 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
712 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
714 if ($location_of_buttons == 'top') {
715 showComposeButtonRow();
718 $idents = getPref($data_dir, $username, 'identities', 0);
720 echo ' <TR>' . "\n" .
721 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
724 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
725 '<select name=identity>' . "\n" .
726 '<option value=default>' .
727 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
728 $em = getPref($data_dir, $username, 'email_address');
730 echo htmlspecialchars(' <' . $em . '>') . "\n";
732 for ($i = 1; $i < $idents; $i ++
) {
733 echo '<option value="' . $i . '"';
734 if (isset($identity) && $identity == $i) {
737 echo '>' . htmlspecialchars(getPref($data_dir, $username,
739 $em = getPref($data_dir, $username, 'email_address' . $i);
741 echo htmlspecialchars(' <' . $em . '>') . "\n";
745 echo '</select>' . "\n" .
749 echo ' <TR>' . "\n" .
750 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
752 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
753 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
754 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
758 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
760 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
761 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
762 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
766 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
768 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
769 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
770 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
771 '</TD></TR>' . "\n" .
773 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
775 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
776 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
777 htmlspecialchars($subject) . '">';
778 echo '</td></tr>' . "\n\n";
780 if ($location_of_buttons == 'between') {
781 showComposeButtonRow();
783 if ($compose_new_win == '1') {
784 echo ' <TR>' . "\n" .
785 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
786 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
787 $editor_size . '" WRAP="VIRTUAL">';
790 echo ' <TR>' . "\n" .
791 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
792 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
793 $editor_size . '" WRAP="VIRTUAL">';
795 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
796 if ($sig_first == '1') {
797 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
798 echo "\n\n".htmlspecialchars($body);
801 echo "\n\n".htmlspecialchars($body);
802 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
806 echo htmlspecialchars($body);
808 echo '</TEXTAREA><BR>' . "\n" .
812 if ($location_of_buttons == 'bottom') {
813 showComposeButtonRow();
815 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
816 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
819 /* This code is for attachments */
820 echo ' <TR>' . "\n" .
821 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
824 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
825 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
826 ' <input type="submit" name="attach"' .
827 ' value="' . _("Add") .'">' . "\n" .
831 if (count($attachments)) {
832 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
833 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
835 '</td><td align=left bgcolor="' . $color[0] . '">';
836 foreach ($attachments as $key => $info) {
837 if ($info['session'] == $session) {
838 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
839 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
840 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
841 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
845 echo '<input type="submit" name="do_delete" value="' .
846 _("Delete selected attachments") . "\">\n" .
849 /* End of attachment code */
850 if ($compose_new_win == '1') {
851 echo '</TABLE>'."\n";
853 echo '</TABLE>' . "\n";
855 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
856 echo '<input type=hidden name=action value=' . $action . ">\n";
857 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
860 do_hook('compose_bottom');
861 echo '</BODY></HTML>' . "\n";
865 function showComposeButtonRow() {
866 global $use_javascript_addr_book, $save_as_draft,
867 $default_use_priority, $mailprio, $default_use_mdn,
868 $request_mdn, $request_dr,
869 $data_dir, $username;
871 echo " <TR><TD>\n</TD><TD>\n";
872 if ($default_use_priority) {
873 if(!isset($mailprio)) {
876 echo _("Priority") .': <select name="mailprio">'.
877 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
878 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
879 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
882 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
883 if ($default_use_mdn) {
884 if ($mdn_user_support) {
885 echo "\n\t". _("Receipt") .': '.
886 '<input type="checkbox" name="request_mdn" value=1'.
887 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
888 ' <input type="checkbox" name="request_dr" value=1'.
889 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
893 echo " </td></tr>\n <TR><td>\n </td><td>\n";
894 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
895 if ($use_javascript_addr_book) {
896 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
897 " <input type=button value=\\\""._("Addresses").
898 "\\\" onclick='javascript:open_abook();'>\");".
899 " // --></SCRIPT><NOSCRIPT>\n".
900 " <input type=submit name=\"html_addr_search\" value=\"".
901 _("Addresses")."\">".
904 echo " <input type=submit name=\"html_addr_search\" value=\"".
905 _("Addresses")."\">";
907 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
909 if ($save_as_draft) {
910 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
913 do_hook('compose_button_row');
915 echo " </TD></TR>\n\n";
918 function checkInput ($show) {
920 * I implemented the $show variable because the error messages
921 * were getting sent before the page header. So, I check once
922 * using $show=false, and then when i'm ready to display the error
925 global $body, $send_to, $subject, $color;
927 if ($send_to == "") {
929 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
934 } /* function checkInput() */
937 /* True if FAILURE */
938 function saveAttachedFiles($session) {
939 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
942 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
943 $localfilename = GenerateRandomString(32, '', 7);
944 $full_localfilename = "$hashed_attachment_dir/$localfilename";
945 while (file_exists($full_localfilename)) {
946 $localfilename = GenerateRandomString(32, '', 7);
947 $full_localfilename = "$hashed_attachment_dir/$localfilename";
950 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
951 if (function_exists("move_uploaded_file")) {
952 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
956 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
962 $newAttachment['localfilename'] = $localfilename;
963 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
964 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
965 $newAttachment['session'] = $session;
967 if ($newAttachment['type'] == "") {
968 $newAttachment['type'] = 'application/octet-stream';
970 $attachments[] = $newAttachment;
971 setPref($data_dir, $username, 'attachments', serialize($attachments));
975 function ClearAttachments($session)
977 global $username, $attachments, $attachment_dir, $data_dir;
978 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
980 $rem_attachments = array();
981 if (is_array($attachments)) {
982 foreach ($attachments as $info) {
983 if ($info['session'] == $session) {
984 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
985 if (file_exists($attached_file)) {
986 unlink($attached_file);
990 $rem_attachments[] = $info;
994 $attachments = $rem_attachments;
995 setPref($data_dir, $username, 'attachments', serialize($attachments));
999 function getReplyCitation($orig_from)
1001 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1003 /* First, return an empty string when no citation style selected. */
1004 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1008 /* Make sure our final value isn't an empty string. */
1009 if ($orig_from == '') {
1013 /* Otherwise, try to select the desired citation style. */
1014 switch ($reply_citation_style) {
1017 $end = ' ' . _("said") . ':';
1020 $start = '<' . _("quote") . ' ' . _("who") . '="';
1023 case 'user-defined':
1024 $start = $reply_citation_start . ' ';
1025 $end = $reply_citation_end;
1031 /* Build and return the citation string. */
1032 return ($start . $orig_from . $end . "\n");