35cbc53da803ea2c7eda8b86cab9c82f76ae64fe
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 (!isset($mailbox)) {
135 if ($compose_new_win == '1') {
136 compose_Header($color, $mailbox);
138 displayPageHeader($color, $mailbox);
140 showInputForm($session, false);
144 if (!isset($attachments)) {
145 $attachments = array();
146 session_register('attachments');
149 if (!isset($composesession)) {
151 session_register('composesession');
154 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
155 $session = "$composesession" +
1;
156 $composesession = $session;
159 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
164 include_once ('../src/draft_actions.php');
165 if (! isset($passed_id)) {
171 if (! isset($mailprio)) {
174 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
175 showInputForm($session);
178 $draft_message = _("Draft Email Saved");
179 /* If this is a resumed draft, then delete the original */
180 if(isset($delete_draft)) {
181 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
182 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
186 if ($compose_new_win == '1') {
187 Header("Location: compose.php?saved_draft=yes&session=$composesession");
191 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
192 "&startMessage=1¬e=".urlencode($draft_message));
200 if (isset($HTTP_POST_FILES['attachfile']) &&
201 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
202 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
203 $AttachFailure = saveAttachedFiles($session);
205 if (checkInput(false) && !isset($AttachFailure)) {
206 $urlMailbox = urlencode (trim($mailbox));
207 if (! isset($passed_id)) {
211 * Set $default_charset to correspond with the user's selection
212 * of language interface.
217 * This is to change all newlines to \n
218 * We'll change them to \r\n later (in the sendMessage function)
220 $body = str_replace("\r\n", "\n", $body);
221 $body = str_replace("\r", "\n", $body);
224 * Rewrap $body so that no line is bigger than $editor_size
225 * This should only really kick in the sqWordWrap function
226 * if the browser doesn't support "VIRTUAL" as the wrap type.
228 $body = explode("\n", $body);
230 foreach ($body as $line) {
231 if( $line <> '-- ' ) {
232 $line = rtrim($line);
234 if (strlen($line) <= $editor_size +
1) {
235 $newBody .= $line . "\n";
237 sqWordWrap($line, $editor_size);
238 $newBody .= $line . "\n";
243 do_hook('compose_send');
245 $MDN = False; // we are not sending a mdn response
246 if (! isset($mailprio)) {
247 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
248 $subject, $body, $passed_id, $MDN, '', $session);
250 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
251 $subject, $body, $passed_id, $MDN, $mailprio, $session);
254 showInputForm($session);
257 if ( isset($delete_draft)) {
258 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
259 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
262 if ($compose_new_win == '1') {
263 Header("Location: compose.php?mail_sent=yes");
266 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
271 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
274 if ($compose_new_win == '1') {
275 compose_Header($color, $mailbox);
278 displayPageHeader($color, $mailbox);
280 if (isset($AttachFailure)) {
281 plain_error_message(_("Could not move/copy file. File not attached"),
285 showInputForm($session);
286 /* sqimap_logout($imapConnection); */
288 } elseif (isset($html_addr_search_done)) {
289 if ($compose_new_win == '1') {
290 compose_Header($color, $mailbox);
293 displayPageHeader($color, $mailbox);
296 if (isset($send_to_search) && is_array($send_to_search)) {
297 foreach ($send_to_search as $k => $v) {
298 if (substr($k, 0, 1) == 'T') {
304 elseif (substr($k, 0, 1) == 'C') {
310 elseif (substr($k, 0, 1) == 'B') {
312 $send_to_bcc .= ', ';
318 showInputForm($session);
319 } elseif (isset($html_addr_search)) {
320 if (isset($HTTP_POST_FILES['attachfile']) &&
321 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
322 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
323 if (saveAttachedFiles($session)) {
324 plain_error_message(_("Could not move/copy file. File not attached"), $color);
328 * I am using an include so as to elminiate an extra unnecessary
329 * click. If you can think of a better way, please implement it.
331 include_once('./addrbook_search_html.php');
332 } elseif (isset($attach)) {
333 if (saveAttachedFiles($session)) {
334 plain_error_message(_("Could not move/copy file. File not attached"), $color);
336 if ($compose_new_win == '1') {
337 compose_Header($color, $mailbox);
340 displayPageHeader($color, $mailbox);
342 showInputForm($session);
344 elseif (isset($sigappend)) {
345 $idents = getPref($data_dir, $username, 'identities', 0);
347 if ($identity == 'default') {
352 $signature = getSig($data_dir, $username, $no);
354 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
355 if ($compose_new_win == '1') {
356 compose_Header($color, $mailbox);
358 displayPageHeader($color, $mailbox);
360 showInputForm($session);
361 } elseif (isset($do_delete)) {
362 if ($compose_new_win == '1') {
363 compose_Header($color, $mailbox);
366 displayPageHeader($color, $mailbox);
369 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
370 if (isset($delete) && is_array($delete)) {
371 foreach($delete as $index) {
372 $attached_file = $hashed_attachment_dir . '/'
373 . $attachments[$index]['localfilename'];
374 unlink ($attached_file);
375 unset ($attachments[$index]);
377 setPref($data_dir, $username, 'attachments', serialize($attachments));
380 showInputForm($session);
383 * This handles the default case as well as the error case
384 * (they had the same code) --> if (isset($smtpErrors))
387 if ($compose_new_win == '1') {
388 compose_Header($color, $mailbox);
390 displayPageHeader($color, $mailbox);
395 if (!isset($passed_ent_id)) $passed_ent_id = '';
396 if (!isset($passed_id)) $passed_id = '';
397 if (!isset($mailbox)) $mailbox = '';
398 if (!isset($action)) $action = '';
400 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
402 /* in case the origin is not read_body.php */
403 if (isset($send_to)) {
404 $values['send_to'] = $send_to;
406 if (isset($send_to_cc)) {
407 $values['send_to_cc'] = $send_to_cc;
409 if (isset($send_to_bcc)) {
410 $values['send_to_bcc'] = $send_to_bcc;
412 showInputForm($session, $values);
417 /**************** Only function definitions go below *************/
420 /* This function is used when not sending or adding attachments */
421 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
422 global $editor_size, $default_use_priority,
423 $use_signature, $composesession, $data_dir, $username,
424 $username, $key, $imapServerAddress, $imapPort;
426 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
430 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
433 sqimap_mailbox_select($imapConnection, $mailbox);
434 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
436 if ($passed_ent_id) {
437 /* redefine the messsage in case of message/rfc822 */
438 $message = $message->getEntity($passed_ent_id);
439 /* message is an entity which contains the envelope and type0=message
440 * and type1=rfc822. The actual entities are childs from
441 * $message->entities[0]. That's where the encoding and is located
444 $entities = $message->entities
[0]->findDisplayEntity
445 (array(), $alt_order = array('text/plain'));
446 if (!count($entities)) {
447 $entities = $message->entities
[0]->findDisplayEntity
448 (array(), $alt_order = array('text/plain','html/plain'));
450 $orig_header = $message->header
; /* here is the envelope located */
451 /* redefine the message for picking up the attachments */
452 $message = $message->entities
[0];
455 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
456 if (!count($entities)) {
457 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
459 $orig_header = $message->header
;
461 $encoding = $message->header
->encoding
;
462 $type0 = $message->type0
;
463 $type1 = $message->type1
;
465 foreach ($entities as $ent) {
466 $bodypart = decodeBody(
467 mime_fetch_body($imapConnection, $passed_id, $ent),
469 if ($type1 == 'html') {
470 $bodypart = strip_tags($bodypart);
474 if ($default_use_priority) {
475 $mailprio = substr($orig_header->priority
,0,1);
479 ClearAttachments($session);
482 $idents = getPref($data_dir, $username, 'identities');
483 $from_o = $message->header
->from
;
484 if (is_object($from_o)) {
485 $orig_from = $from_o->getAddress();
489 if (!empty($idents) && $idents > 1) {
490 for ($i = 1; $i < $idents; $i++
) {
491 $enc_from_name = '"'.
495 '" <' . getPref($data_dir, $username,
496 'email_address' . $i) . '>';
497 if ($enc_from_name == $orig_from) {
506 $use_signature = FALSE;
507 $send_to = $orig_header->getAddr_s('to');
508 $send_to_cc = $orig_header->getAddr_s('cc');
509 $send_to_bcc = $orig_header->getAddr_s('bcc');
510 $subject = $orig_header->subject
;
512 $body_ary = explode("\n", $body);
513 $cnt = count($body_ary) ;
515 for ($i=0; $i < $cnt; $i++
) {
516 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
517 sqWordWrap($body_ary[$i], $editor_size );
518 $body .= $body_ary[$i] . "\n";
520 unset($body_ary[$i]);
523 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
525 case ('edit_as_new'):
526 $send_to = $orig_header->getAddr_s('to');
527 $send_to_cc = $orig_header->getAddr_s('cc');
528 $send_to_bcc = $orig_header->getAddr_s('bcc');
529 $subject = $orig_header->subject
;
530 $mailprio = $orig_header->priority
;
532 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
537 $subject = $orig_header->subject
;
538 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
539 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
540 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
541 $subject = '[Fwd: ' . $subject . ']';
543 $body = getforwardHeader($orig_header) . $body;
545 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
547 case ('reply' ||
'reply_all'):
548 $send_to = $orig_header->reply_to
;
550 $send_to = $send_to->getAddress();
552 $send_to = $orig_header->from
->getAddress();
554 $subject = $orig_header->subject
;
555 $subject = str_replace('"', "'", $subject);
556 $subject = trim($subject);
557 if (substr(strtolower($subject), 0, 3) != 're:') {
558 $subject = 'Re: ' . $subject;
560 if ($action == 'reply_all') {
561 $send_to_cc = replyAllString($orig_header);
563 /* this corrects some wrapping/quoting problems on replies */
564 $rewrap_body = explode("\n", $body);
565 $body = getReplyCitation($orig_header->from
->personal
);
566 $cnt = count($rewrap_body);
567 for ($i=0;$i<$cnt;$i++
) {
568 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
569 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
571 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
573 $body .= '> ' . $rewrap_body[$i] . "\n";
575 unset($rewrap_body[$i]);
581 sqimap_logout($imapConnection);
584 'send_to' => $send_to,
585 'send_to_cc' => $send_to_cc,
586 'send_to_bcc' => $send_to_bcc,
587 'subject' => $subject,
588 'mailprio' => $mailprio,
590 'identity' => $identity
594 } /* function newMail() */
597 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
598 global $attachments, $attachment_dir, $username, $data_dir;
600 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
601 if (!count($message->entities
) ||
602 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
603 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
604 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
605 $filename = decodeHeader($message->header
->subject
.'.eml');
606 if ($filename == "") {
607 $filename = "untitled-".$message->entity_id
.'.eml';
610 $filename = decodeHeader($message->header
->filename
);
611 if ($filename == "") {
612 $filename = "untitled-".$message->entity_id
;
615 $localfilename = GenerateRandomString(32, '', 7);
616 $full_localfilename = "$hashed_attachment_dir/$localfilename";
617 while (file_exists($full_localfilename)) {
618 $localfilename = GenerateRandomString(32, '', 7);
619 $full_localfilename = "$hashed_attachment_dir/$localfilename";
622 $newAttachment = array();
623 $newAttachment['localfilename'] = $localfilename;
624 $newAttachment['remotefilename'] = $filename;
625 $newAttachment['type'] = strtolower($message->type0
.
626 '/' . $message->type1
);
627 $newAttachment['id'] = strtolower($message->header
->id
);
628 $newAttachment['session'] = $session;
630 /* Write Attachment to file */
631 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
632 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
633 $passed_id, $message->entity_id
),
634 $message->header
->encoding
));
637 $attachments[] = $newAttachment;
638 setPref($data_dir, $username, 'javascript_on', $js_pref);
641 for ($i = 0; $i < count($message->entities
); $i++
) {
642 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
648 function showInputForm ($session, $values=false) {
649 global $send_to, $send_to_cc, $body,
650 $passed_body, $color, $use_signature, $signature, $prefix_sig,
651 $editor_size, $attachments, $subject, $newmail,
652 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
653 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
654 $username, $data_dir, $identity, $draft_id, $delete_draft,
655 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
656 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
659 $subject = decodeHeader($subject, false);
661 $send_to = $values['send_to'];
662 $send_to_cc = $values['send_to_cc'];
663 $send_to_bcc = $values['send_to_bcc'];
664 $subject = $values['subject'];
665 $mailprio = $values['mailprio'];
666 $body = $values['body'];
667 $identity = $values['identity'];
670 if ($use_javascript_addr_book) {
671 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
672 'function open_abook() { ' . "\n" .
673 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
674 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
675 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
676 ' nwin.opener = document.windows;' . "\n" .
678 '// --></SCRIPT>' . "\n\n";
681 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
682 'ENCTYPE="multipart/form-data"';
683 do_hook("compose_form");
688 if ($action == 'draft') {
689 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
691 if (isset($delete_draft)) {
692 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
694 if (isset($session)) {
695 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
699 if ($saved_draft == 'yes') {
700 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
702 if ($mail_sent == 'yes') {
703 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
705 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
706 if ($compose_new_win == '1') {
707 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
708 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
710 if ($location_of_buttons == 'top') {
711 showComposeButtonRow();
714 $idents = getPref($data_dir, $username, 'identities', 0);
716 echo ' <TR>' . "\n" .
717 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
720 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
721 '<select name=identity>' . "\n" .
722 '<option value=default>' .
723 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
724 $em = getPref($data_dir, $username, 'email_address');
726 echo htmlspecialchars(' <' . $em . '>') . "\n";
728 for ($i = 1; $i < $idents; $i ++
) {
729 echo '<option value="' . $i . '"';
730 if (isset($identity) && $identity == $i) {
733 echo '>' . htmlspecialchars(getPref($data_dir, $username,
735 $em = getPref($data_dir, $username, 'email_address' . $i);
737 echo htmlspecialchars(' <' . $em . '>') . "\n";
741 echo '</select>' . "\n" .
745 echo ' <TR>' . "\n" .
746 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
748 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
749 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
750 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
754 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
756 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
757 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
758 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
762 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
764 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
765 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
766 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
767 '</TD></TR>' . "\n" .
769 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
771 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
772 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
773 htmlspecialchars($subject) . '">';
774 echo '</td></tr>' . "\n\n";
776 if ($location_of_buttons == 'between') {
777 showComposeButtonRow();
779 if ($compose_new_win == '1') {
780 echo ' <TR>' . "\n" .
781 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
782 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
783 $editor_size . '" WRAP="VIRTUAL">';
786 echo ' <TR>' . "\n" .
787 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
788 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
789 $editor_size . '" WRAP="VIRTUAL">';
791 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
792 if ($sig_first == '1') {
793 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
794 echo "\n\n".htmlspecialchars($body);
797 echo "\n\n".htmlspecialchars($body);
798 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
802 echo htmlspecialchars($body);
804 echo '</TEXTAREA><BR>' . "\n" .
808 if ($location_of_buttons == 'bottom') {
809 showComposeButtonRow();
811 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
812 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
815 /* This code is for attachments */
816 echo ' <TR>' . "\n" .
817 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
820 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
821 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
822 ' <input type="submit" name="attach"' .
823 ' value="' . _("Add") .'">' . "\n" .
827 if (count($attachments)) {
828 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
829 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
831 '</td><td align=left bgcolor="' . $color[0] . '">';
832 foreach ($attachments as $key => $info) {
833 if ($info['session'] == $session) {
834 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
835 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
836 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
837 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
841 echo '<input type="submit" name="do_delete" value="' .
842 _("Delete selected attachments") . "\">\n" .
845 /* End of attachment code */
846 if ($compose_new_win == '1') {
847 echo '</TABLE>'."\n";
849 echo '</TABLE>' . "\n";
851 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
852 echo '<input type=hidden name=action value=' . $action . ">\n";
853 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
856 do_hook('compose_bottom');
857 echo '</BODY></HTML>' . "\n";
861 function showComposeButtonRow() {
862 global $use_javascript_addr_book, $save_as_draft,
863 $default_use_priority, $mailprio, $default_use_mdn,
864 $request_mdn, $request_dr,
865 $data_dir, $username;
867 echo " <TR><TD>\n</TD><TD>\n";
868 if ($default_use_priority) {
869 if(!isset($mailprio)) {
872 echo _("Priority") .': <select name="mailprio">'.
873 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
874 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
875 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
878 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
879 if ($default_use_mdn) {
880 if ($mdn_user_support) {
881 echo "\n\t". _("Receipt") .': '.
882 '<input type="checkbox" name="request_mdn" value=1'.
883 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
884 ' <input type="checkbox" name="request_dr" value=1'.
885 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
889 echo " </td></tr>\n <TR><td>\n </td><td>\n";
890 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
891 if ($use_javascript_addr_book) {
892 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
893 " <input type=button value=\\\""._("Addresses").
894 "\\\" onclick='javascript:open_abook();'>\");".
895 " // --></SCRIPT><NOSCRIPT>\n".
896 " <input type=submit name=\"html_addr_search\" value=\"".
897 _("Addresses")."\">".
900 echo " <input type=submit name=\"html_addr_search\" value=\"".
901 _("Addresses")."\">";
903 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
905 if ($save_as_draft) {
906 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
909 do_hook('compose_button_row');
911 echo " </TD></TR>\n\n";
914 function checkInput ($show) {
916 * I implemented the $show variable because the error messages
917 * were getting sent before the page header. So, I check once
918 * using $show=false, and then when i'm ready to display the error
921 global $body, $send_to, $subject, $color;
923 if ($send_to == "") {
925 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
930 } /* function checkInput() */
933 /* True if FAILURE */
934 function saveAttachedFiles($session) {
935 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
938 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
939 $localfilename = GenerateRandomString(32, '', 7);
940 $full_localfilename = "$hashed_attachment_dir/$localfilename";
941 while (file_exists($full_localfilename)) {
942 $localfilename = GenerateRandomString(32, '', 7);
943 $full_localfilename = "$hashed_attachment_dir/$localfilename";
946 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
947 if (function_exists("move_uploaded_file")) {
948 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
952 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
958 $newAttachment['localfilename'] = $localfilename;
959 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
960 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
961 $newAttachment['session'] = $session;
963 if ($newAttachment['type'] == "") {
964 $newAttachment['type'] = 'application/octet-stream';
966 $attachments[] = $newAttachment;
967 setPref($data_dir, $username, 'attachments', serialize($attachments));
971 function ClearAttachments($session)
973 global $username, $attachments, $attachment_dir, $data_dir;
974 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
976 $rem_attachments = array();
977 if (is_array($attachments)) {
978 foreach ($attachments as $info) {
979 if ($info['session'] == $session) {
980 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
981 if (file_exists($attached_file)) {
982 unlink($attached_file);
986 $rem_attachments[] = $info;
990 $attachments = $rem_attachments;
991 setPref($data_dir, $username, 'attachments', serialize($attachments));
995 function getReplyCitation($orig_from)
997 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
999 /* First, return an empty string when no citation style selected. */
1000 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1004 /* Make sure our final value isn't an empty string. */
1005 if ($orig_from == '') {
1009 /* Otherwise, try to select the desired citation style. */
1010 switch ($reply_citation_style) {
1013 $end = ' ' . _("said") . ':';
1016 $start = '<' . _("quote") . ' ' . _("who") . '="';
1019 case 'user-defined':
1020 $start = $reply_citation_start . ' ';
1021 $end = $reply_citation_end;
1027 /* Build and return the citation string. */
1028 return ($start . $orig_from . $end . "\n");