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/display_messages.php');
26 require_once('../functions/plugin.php');
28 /* --------------------- Specific Functions ------------------------------ */
33 * Does the opposite of sqWordWrap()
35 function sqUnWordWrap(&$body) {
36 $lines = explode("\n", $body);
39 for ($i = 0; $i < count($lines); $i ++
) {
40 ereg("^([\t >]*)([^\t >].*)?$", $lines[$i], $regs);
41 $CurrentSpaces = $regs[1];
42 if (isset($regs[2])) {
43 $CurrentRest = $regs[2];
47 $PreviousSpaces = $CurrentSpaces;
49 } else if (($PreviousSpaces == $CurrentSpaces) /* Do the beginnings match */
50 && (strlen($lines[$i - 1]) > 65) /* Over 65 characters long */
51 && strlen($CurrentRest)) { /* and there's a line to continue with */
52 $body .= ' ' . $CurrentRest;
54 $body .= "\n" . $lines[$i];
55 $PreviousSpaces = $CurrentSpaces;
61 /* ----------------------------------------------------------------------- */
63 if (!isset($attachments)) {
64 $attachments = array();
65 session_register('attachments');
68 if (!isset($composesession)) {
70 session_register('composesession');
73 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
74 $session = "$composesession" +
1;
75 $composesession = $session;
78 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
83 include_once ('../src/draft_actions.php');
84 if (! isset($reply_id)) {
90 if (! isset($mailprio)) {
93 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $mailprio, $session)) {
94 showInputForm($session);
97 $draft_message = _("Draft Email Saved");
98 /* If this is a resumed draft, then delete the original */
99 if(isset($delete_draft)) {
100 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
101 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
105 if ($compose_new_win == '1') {
106 Header("Location: compose.php?saved_draft=yes&session=$composesession");
110 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
111 "&startMessage=1¬e=$draft_message");
119 if (isset($HTTP_POST_FILES['attachfile']) &&
120 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
121 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
122 $AttachFailure = saveAttachedFiles($session);
124 if (checkInput(false) && !isset($AttachFailure)) {
125 $urlMailbox = urlencode (trim($mailbox));
126 if (! isset($reply_id)) {
130 * Set $default_charset to correspond with the user's selection
131 * of language interface.
136 * This is to change all newlines to \n
137 * We'll change them to \r\n later (in the sendMessage function)
139 $body = str_replace("\r\n", "\n", $body);
140 $body = str_replace("\r", "\n", $body);
143 * Rewrap $body so that no line is bigger than $editor_size
144 * This should only really kick in the sqWordWrap function
145 * if the browser doesn't support "VIRTUAL" as the wrap type.
147 $body = explode("\n", $body);
149 foreach ($body as $line) {
150 if( $line <> '-- ' ) {
151 $line = rtrim($line);
153 if (strlen($line) <= $editor_size +
1) {
154 $newBody .= $line . "\n";
156 sqWordWrap($line, $editor_size);
157 $newBody .= $line . "\n";
162 do_hook('compose_send');
164 $MDN = False; // we are not sending a mdn response
165 if (! isset($mailprio)) {
166 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
167 $subject, $body, $reply_id, $MDN, '', $session);
169 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
170 $subject, $body, $reply_id, $MDN, $mailprio, $session);
173 showInputForm($session);
176 if ( isset($delete_draft)) {
177 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
178 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
181 if ($compose_new_win == '1') {
182 Header("Location: compose.php?mail_sent=yes");
185 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
190 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
193 if ($compose_new_win == '1') {
194 compose_Header($color, $mailbox);
197 displayPageHeader($color, $mailbox);
199 if (isset($AttachFailure)) {
200 plain_error_message(_("Could not move/copy file. File not attached"),
205 showInputForm($session);
206 /* sqimap_logout($imapConnection); */
208 } elseif (isset($html_addr_search_done)) {
209 if ($compose_new_win == '1') {
210 compose_Header($color, $mailbox);
213 displayPageHeader($color, $mailbox);
216 if (isset($send_to_search) && is_array($send_to_search)) {
217 foreach ($send_to_search as $k => $v) {
218 if (substr($k, 0, 1) == 'T') {
224 elseif (substr($k, 0, 1) == 'C') {
230 elseif (substr($k, 0, 1) == 'B') {
232 $send_to_bcc .= ', ';
238 showInputForm($session);
239 } elseif (isset($html_addr_search)) {
240 if (isset($HTTP_POST_FILES['attachfile']) &&
241 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
242 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
243 if (saveAttachedFiles($session)) {
244 plain_error_message(_("Could not move/copy file. File not attached"), $color);
248 * I am using an include so as to elminiate an extra unnecessary
249 * click. If you can think of a better way, please implement it.
251 include_once('./addrbook_search_html.php');
252 } elseif (isset($attach)) {
253 if (saveAttachedFiles($session)) {
254 plain_error_message(_("Could not move/copy file. File not attached"), $color);
256 if ($compose_new_win == '1') {
257 compose_Header($color, $mailbox);
260 displayPageHeader($color, $mailbox);
262 showInputForm($session);
264 elseif (isset($sigappend)) {
265 $idents = getPref($data_dir, $username, 'identities', 0);
267 if ($identity == 'default') {
272 $signature = getSig($data_dir, $username, $no);
274 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
275 if ($compose_new_win == '1') {
276 compose_Header($color, $mailbox);
278 displayPageHeader($color, $mailbox);
280 showInputForm($session);
281 } elseif (isset($do_delete)) {
282 if ($compose_new_win == '1') {
283 compose_Header($color, $mailbox);
286 displayPageHeader($color, $mailbox);
289 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
290 if (isset($delete) && is_array($delete)) {
291 foreach($delete as $index) {
292 $attached_file = $hashed_attachment_dir . '/'
293 . $attachments[$index]['localfilename'];
294 unlink ($attached_file);
295 unset ($attachments[$index]);
299 showInputForm($session);
301 } elseif (isset($attachedmessages)) {
304 * This handles the case if we attache message
306 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
308 if ($compose_new_win == '1') {
309 compose_Header($color, $mailbox);
312 displayPageHeader($color, $mailbox);
318 showInputForm($session);
319 sqimap_logout($imapConnection);
323 * This handles the default case as well as the error case
324 * (they had the same code) --> if (isset($smtpErrors))
326 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
328 if ($compose_new_win == '1') {
329 compose_Header($color, $mailbox);
332 displayPageHeader($color, $mailbox);
337 ClearAttachments($session);
339 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) {
340 getAttachments(0, $session);
343 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) {
344 getAttachments(0, $session);
347 if (isset($passed_id) && $passed_id && isset($ent_num) && $ent_num) {
348 getAttachments(0, $session);
352 showInputForm($session);
353 sqimap_logout($imapConnection);
359 /**************** Only function definitions go below *************/
362 /* This function is used when not sending or adding attachments */
363 function newMail () {
364 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
365 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
366 $draft_id, $use_signature, $composesession, $forward_cc, $passed_id;
368 $send_to = decodeHeader($send_to, false);
369 $send_to_cc = decodeHeader($send_to_cc, false);
370 $send_to_bcc = decodeHeader($send_to_bcc, false);
371 $send_to = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to))));
372 $send_to_cc = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to_cc))));
373 $send_to_bcc = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to_bcc))));
377 } elseif ($reply_id) {
379 } elseif ($passed_id) {
386 $use_signature = FALSE;
390 sqimap_mailbox_select($imapConnection, $mailbox);
391 $message = sqimap_get_message($imapConnection, $id, $mailbox);
392 $orig_header = $message->header
;
395 $ent_ar = preg_split('/_/',$ent_num);
396 foreach($ent_ar as $ent_num) {
397 $message = getEntity($message, $ent_num);
398 if ($message->header
->type0
== 'text' ||
399 $message->header
->type1
== 'message') {
400 $bodypart = decodeBody(
401 mime_fetch_body($imapConnection, $id, $ent_num),
402 $message->header
->encoding
);
403 if ($message->header
->type1
== 'html') {
404 $bodypart = strip_tags($bodypart);
409 } else if ($message->header
->type0
== 'text' ||
410 $message->header
->type1
== 'message') {
412 mime_fetch_body($imapConnection, $id, 1),
413 $message->header
->encoding
);
414 if ($message->header
->type1
== 'html') {
415 $body = strip_tags($body);
422 /* this corrects some wrapping/quoting problems on replies */
424 $rewrap_body = explode("\n", $body);
425 for ($i=0;$i<count($rewrap_body);$i++
) {
426 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
427 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
429 $rewrap_body[$i] = str_replace("\n", "\n$gt ", $rewrap_body[$i]);
431 $rewrap_body[$i] .= "\n";
433 $body = implode("", $rewrap_body);
436 $body_ary = explode("\n", $body);
437 $i = count($body_ary) - 1;
438 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
439 unset($body_ary[$i]);
443 for ($i=0; isset($body_ary[$i]); $i++
) {
445 if (preg_match("/^(>){1,}/", $body_ary[$i])) {
446 $body_ary[$i] = '>' . $body_ary[$i];
448 $body_ary[$i] = '> ' . $body_ary[$i];
452 sqWordWrap($body_ary[$i], $editor_size );
454 $body .= $body_ary[$i] . "\n";
455 unset($body_ary[$i]);
458 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
459 _("Subject") . ': ' . $orig_header->subject
. "\n" .
460 _("From") . ': ' . $orig_header->from
. "\n" .
462 getLongDateString( $orig_header->date
). "\n" .
463 _("To") . ': ' . $orig_header->to
[0] . "\n";
464 if (count($orig_header->to
) > 1) {
465 for ($x=1; $x < count($orig_header->to
); $x++
) {
466 $bodyTop .= ' ' . $orig_header->to
[$x] . "\n";
469 if (isset($forward_cc) && $forward_cc) {
470 $bodyTop .= _("Cc") . ': ' . $orig_header->cc
[0] . "\n";
471 if (count($orig_header->cc
) > 1) {
472 for ($x = 1; $x < count($orig_header->cc
); $x++
) {
473 $bodyTop .= ' ' . $orig_header->cc
[$x] . "\n";
478 $body = $bodyTop . $body;
481 $orig_from = decodeHeader($orig_header->from
, false);
482 $body = getReplyCitation($orig_from) . $body;
489 $send_to = sqimap_find_email($send_to);
492 /* This formats a CC string if they hit "reply all" */
493 if ($send_to_cc != '') {
494 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
495 $send_to_cc = str_replace(';', ',', $send_to_cc);
496 $sendcc = explode(',', $send_to_cc);
499 for ($i = 0; $i < count($sendcc); $i++
) {
500 $sendcc[$i] = trim($sendcc[$i]);
501 if ($sendcc[$i] == '') {
505 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
506 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
507 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
509 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
510 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
511 (trim($sendcc[$i]) != '')) {
512 $send_to_cc .= trim($sendcc[$i]) . ', ';
515 $send_to_cc = trim($send_to_cc);
516 if (substr($send_to_cc, -1) == ',') {
517 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
520 } /* function newMail() */
523 function getAttachments($message, $session) {
524 global $mailbox, $attachments, $attachment_dir, $imapConnection,
525 $ent_num, $forward_id, $draft_id, $username, $passed_id;
527 if (isset($draft_id)) {
529 } else if (isset($forward_id)) {
536 sqimap_mailbox_select($imapConnection, $mailbox);
537 $message = sqimap_get_message($imapConnection, $id, $mailbox);
540 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
541 if (count($message->entities
) == 0) {
542 if ($message->header
->entity_id
!= $ent_num) {
543 $filename = decodeHeader($message->header
->filename
);
545 if ($filename == "") {
546 $filename = "untitled-".$message->header
->entity_id
;
549 $localfilename = GenerateRandomString(32, '', 7);
550 $full_localfilename = "$hashed_attachment_dir/$localfilename";
551 while (file_exists($full_localfilename)) {
552 $localfilename = GenerateRandomString(32, '', 7);
553 $full_localfilename = "$hashed_attachment_dir/$localfilename";
556 $newAttachment = array();
557 $newAttachment['localfilename'] = $localfilename;
558 $newAttachment['remotefilename'] = $filename;
559 $newAttachment['type'] = strtolower($message->header
->type0
.
560 '/' . $message->header
->type1
);
561 $newAttachment['id'] = strtolower($message->header
->id
);
562 $newAttachment['session'] = $session;
564 /* Write Attachment to file */
565 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
566 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
567 $id, $message->header
->entity_id
),
568 $message->header
->encoding
));
571 $attachments[] = $newAttachment;
574 for ($i = 0; $i < count($message->entities
); $i++
) {
575 getAttachments($message->entities
[$i], $session);
581 function showInputForm ($session) {
582 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
583 $passed_body, $color, $use_signature, $signature, $prefix_sig,
584 $editor_size, $attachments, $subject, $newmail,
585 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
586 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
587 $username, $data_dir, $identity, $draft_id, $delete_draft,
588 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
589 $saved_draft, $mail_sent, $sig_first, $edit_as_new;
591 $file_uploads = ini_get('file_uploads');
592 $subject = decodeHeader($subject, false);
593 $reply_subj = decodeHeader($reply_subj, false);
594 $forward_subj = decodeHeader($forward_subj, false);
596 if ($use_javascript_addr_book) {
597 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
598 'function open_abook() { ' . "\n" .
599 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
600 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
601 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
602 ' nwin.opener = document.windows;' . "\n" .
604 '// --></SCRIPT>' . "\n\n";
607 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ';
609 echo 'ENCTYPE="multipart/form-data"';
611 do_hook("compose_form");
616 if (isset($draft_id) && !$edit_as_new) {
617 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
619 if (isset($delete_draft)) {
620 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
622 if (isset($session)) {
623 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
626 if ($saved_draft == 'yes') {
627 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
629 if ($mail_sent == 'yes') {
630 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
632 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
633 if ($compose_new_win == '1') {
634 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
635 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
637 if ($location_of_buttons == 'top') {
638 showComposeButtonRow();
641 $idents = getPref($data_dir, $username, 'identities', 0);
643 echo ' <TR>' . "\n" .
644 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
647 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
648 '<select name=identity>' . "\n" .
649 '<option value=default>' .
650 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
651 $em = getPref($data_dir, $username, 'email_address');
653 echo htmlspecialchars(' <' . $em . '>') . "\n";
655 for ($i = 1; $i < $idents; $i ++
) {
656 echo '<option value="' . $i . '"';
657 if (isset($identity) && $identity == $i) {
660 echo '>' . htmlspecialchars(getPref($data_dir, $username,
662 $em = getPref($data_dir, $username, 'email_address' . $i);
664 echo htmlspecialchars(' <' . $em . '>') . "\n";
668 echo '</select>' . "\n" .
672 echo ' <TR>' . "\n" .
673 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
675 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
676 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
677 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
681 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
683 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
684 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
685 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
689 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
691 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
692 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
693 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
694 '</TD></TR>' . "\n" .
696 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
698 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
700 $reply_subj = str_replace('"', "'", $reply_subj);
701 $reply_subj = trim($reply_subj);
702 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
703 $reply_subj = 'Re: ' . $reply_subj;
705 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
706 htmlspecialchars($reply_subj) . '">';
708 elseif ($forward_subj) {
709 $forward_subj = trim($forward_subj);
710 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
711 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
712 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
713 $forward_subj = '[Fwd: ' . $forward_subj . ']';
715 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
716 htmlspecialchars($forward_subj) . '">';
718 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
719 htmlspecialchars($subject) . '">';
721 echo '</td></tr>' . "\n\n";
723 if ($location_of_buttons == 'between') {
724 showComposeButtonRow();
726 if ($compose_new_win == '1') {
727 echo ' <TR>' . "\n" .
728 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
729 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
730 $editor_size . '" WRAP="VIRTUAL">';
733 echo ' <TR>' . "\n" .
734 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
735 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
736 $editor_size . '" WRAP="VIRTUAL">';
738 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
739 if ($sig_first == '1') {
740 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
741 echo "\n\n".htmlspecialchars($body);
744 echo "\n\n".htmlspecialchars($body);
745 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
749 echo htmlspecialchars($body);
751 echo '</TEXTAREA><BR>' . "\n" .
755 if ($location_of_buttons == 'bottom') {
756 showComposeButtonRow();
758 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
759 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
762 /* This code is for attachments */
764 echo ' <TR>' . "\n" .
765 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
768 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
769 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
770 ' <input type="submit" name="attach"' .
771 ' value="' . _("Add") .'">' . "\n" .
775 if (count($attachments)) {
776 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
777 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
779 '</td><td align=left bgcolor="' . $color[0] . '">';
780 foreach ($attachments as $key => $info) {
781 if ($info['session'] == $session) {
782 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
783 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
784 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
785 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
789 echo '<input type="submit" name="do_delete" value="' .
790 _("Delete selected attachments") . "\">\n" .
793 /* End of attachment code */
795 if ($compose_new_win == '1') {
796 echo '</TABLE>'."\n";
798 echo '</TABLE>' . "\n";
800 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
802 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
805 do_hook('compose_bottom');
806 echo '</BODY></HTML>' . "\n";
810 function showComposeButtonRow() {
811 global $use_javascript_addr_book, $save_as_draft,
812 $default_use_priority, $mailprio, $default_use_mdn,
813 $request_mdn, $request_dr,
814 $data_dir, $username;
816 echo " <TR><TD>\n</TD><TD>\n";
817 if ($default_use_priority) {
818 if(!isset($mailprio)) {
821 echo _("Priority") .': <select name="mailprio">'.
822 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
823 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
824 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
827 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
828 if ($default_use_mdn) {
829 if ($mdn_user_support) {
830 echo "\n\t". _("Receipt") .': '.
831 '<input type="checkbox" name="request_mdn" value=1'.
832 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
833 ' <input type="checkbox" name="request_dr" value=1'.
834 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
838 echo " </td></tr>\n <TR><td>\n </td><td>\n";
839 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
840 if ($use_javascript_addr_book) {
841 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
842 " <input type=button value=\\\""._("Addresses").
843 "\\\" onclick='javascript:open_abook();'>\");".
844 " // --></SCRIPT><NOSCRIPT>\n".
845 " <input type=submit name=\"html_addr_search\" value=\"".
846 _("Addresses")."\">".
849 echo " <input type=submit name=\"html_addr_search\" value=\"".
850 _("Addresses")."\">";
852 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
854 if ($save_as_draft) {
855 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
858 do_hook('compose_button_row');
860 echo " </TD></TR>\n\n";
863 function checkInput ($show) {
865 * I implemented the $show variable because the error messages
866 * were getting sent before the page header. So, I check once
867 * using $show=false, and then when i'm ready to display the error
870 global $body, $send_to, $subject, $color;
872 if ($send_to == "") {
874 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
879 } /* function checkInput() */
882 /* True if FAILURE */
883 function saveAttachedFiles($session) {
884 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
886 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
887 $localfilename = GenerateRandomString(32, '', 7);
888 $full_localfilename = "$hashed_attachment_dir/$localfilename";
889 while (file_exists($full_localfilename)) {
890 $localfilename = GenerateRandomString(32, '', 7);
891 $full_localfilename = "$hashed_attachment_dir/$localfilename";
894 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
895 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
900 $newAttachment['localfilename'] = $localfilename;
901 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
902 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
903 $newAttachment['session'] = $session;
905 if ($newAttachment['type'] == "") {
906 $newAttachment['type'] = 'application/octet-stream';
909 $attachments[] = $newAttachment;
913 function ClearAttachments($session)
915 global $username, $attachments, $attachment_dir;
916 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
918 $rem_attachments = array();
919 if (is_array($attachments)) {
920 foreach ($attachments as $info) {
921 if ($info['session'] == $session) {
922 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
923 if (file_exists($attached_file)) {
924 unlink($attached_file);
928 $rem_attachments[] = $info;
932 $attachments = $rem_attachments;
936 function getReplyCitation($orig_from)
938 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
940 /* First, return an empty string when no citation style selected. */
941 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
945 /* Decode the users name. */
946 $parpos = strpos($orig_from, '(');
947 if ($parpos === false) {
948 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
949 $orig_from = str_replace('"', '', $orig_from);
950 $orig_from = str_replace("'", '', $orig_from);
952 $end_parpos = strrpos($orig_from, ')');
953 $end_parpos -= ($end_parpos === false ?
$end_parpos : $parpos +
1);
954 $orig_from = trim(substr($orig_from, $parpos +
1, $end_parpos));
957 /* Make sure our final value isn't an empty string. */
958 if ($orig_from == '') {
962 /* Otherwise, try to select the desired citation style. */
963 switch ($reply_citation_style) {
966 $end = ' ' . _("said") . ':';
969 $start = '<' . _("quote") . ' ' . _("who") . '="';
973 $start = $reply_citation_start . ' ';
974 $end = $reply_citation_end;
980 /* Build and return the citation string. */
981 return ($start . $orig_from . $end . "\n");