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)) {
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 (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN, $session)) {
91 showInputForm($session);
94 $draft_message = _("Draft Email Saved");
95 /* If this is a resumed draft, then delete the original */
96 if(isset($delete_draft)) {
97 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
98 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
102 if ($compose_new_win == '1') {
103 Header("Location: compose.php?saved_draft=yes&session=$composesession");
107 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
108 "&startMessage=1¬e=$draft_message");
116 if (isset($HTTP_POST_FILES['attachfile']) &&
117 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
118 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
119 $AttachFailure = saveAttachedFiles($session);
121 if (checkInput(false) && !isset($AttachFailure)) {
122 $urlMailbox = urlencode (trim($mailbox));
123 if (! isset($reply_id)) {
127 * Set $default_charset to correspond with the user's selection
128 * of language interface.
133 * This is to change all newlines to \n
134 * We'll change them to \r\n later (in the sendMessage function)
136 $body = str_replace("\r\n", "\n", $body);
137 $body = str_replace("\r", "\n", $body);
140 * Rewrap $body so that no line is bigger than $editor_size
141 * This should only really kick in the sqWordWrap function
142 * if the browser doesn't support "HARD" as the wrap type
143 * Or, in Opera's case, something goes wrong.
145 $body = explode("\n", $body);
147 foreach ($body as $line) {
148 if( $line <> '-- ' ) {
149 $line = rtrim($line);
151 if (strlen($line) <= $editor_size +
1) {
152 $newBody .= $line . "\n";
154 sqWordWrap($line, $editor_size) . "\n";
160 do_hook('compose_send');
162 $MDN = False; // we are not sending a mdn response
163 if (! isset($mailprio)) {
164 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
165 $subject, $body, $reply_id, $MDN, '', $session);
167 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
168 $subject, $body, $reply_id, $MDN, $mailprio, $session);
171 showInputForm($session);
174 if ( isset($delete_draft)) {
175 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
176 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
179 if ($compose_new_win == '1') {
180 Header("Location: compose.php?mail_sent=yes&session=$composesession");
183 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
188 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
191 if ($compose_new_win == '1') {
192 compose_Header($color, $mailbox);
195 displayPageHeader($color, $mailbox);
197 if (isset($AttachFailure)) {
198 plain_error_message(_("Could not move/copy file. File not attached"),
203 showInputForm($session);
204 /* sqimap_logout($imapConnection); */
206 } elseif (isset($html_addr_search_done)) {
207 if ($compose_new_win == '1') {
208 compose_Header($color, $mailbox);
211 displayPageHeader($color, $mailbox);
214 if (isset($send_to_search) && is_array($send_to_search)) {
215 foreach ($send_to_search as $k => $v) {
216 if (substr($k, 0, 1) == 'T') {
222 elseif (substr($k, 0, 1) == 'C') {
228 elseif (substr($k, 0, 1) == 'B') {
230 $send_to_bcc .= ', ';
236 showInputForm($session);
237 } elseif (isset($html_addr_search)) {
238 if (isset($HTTP_POST_FILES['attachfile']) &&
239 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
240 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
241 if (saveAttachedFiles($session)) {
242 plain_error_message(_("Could not move/copy file. File not attached"), $color);
246 * I am using an include so as to elminiate an extra unnecessary
247 * click. If you can think of a better way, please implement it.
249 include_once('./addrbook_search_html.php');
250 } elseif (isset($attach)) {
251 if (saveAttachedFiles($session)) {
252 plain_error_message(_("Could not move/copy file. File not attached"), $color);
254 if ($compose_new_win == '1') {
255 compose_Header($color, $mailbox);
258 displayPageHeader($color, $mailbox);
260 showInputForm($session);
262 elseif (isset($sigappend)) {
263 $idents = getPref($data_dir, $username, 'identities', 0);
265 if ($identity == 'default') {
270 $signature = getSig($data_dir, $username, $no);
272 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
273 if ($compose_new_win == '1') {
274 compose_Header($color, $mailbox);
276 displayPageHeader($color, $mailbox);
278 showInputForm($session);
279 } elseif (isset($do_delete)) {
280 if ($compose_new_win == '1') {
281 compose_Header($color, $mailbox);
284 displayPageHeader($color, $mailbox);
287 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
288 if (isset($delete) && is_array($delete)) {
289 foreach($delete as $index) {
290 $attached_file = $hashed_attachment_dir . '/'
291 . $attachments[$index]['localfilename'];
292 unlink ($attached_file);
293 unset ($attachments[$index]);
297 showInputForm($session);
299 } elseif (isset($attachedmessages)) {
302 * This handles the case if we attache message
304 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
306 if ($compose_new_win == '1') {
307 compose_Header($color, $mailbox);
310 displayPageHeader($color, $mailbox);
316 showInputForm($session);
317 sqimap_logout($imapConnection);
321 * This handles the default case as well as the error case
322 * (they had the same code) --> if (isset($smtpErrors))
324 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
326 if ($compose_new_win == '1') {
327 compose_Header($color, $mailbox);
330 displayPageHeader($color, $mailbox);
335 ClearAttachments($session);
337 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) {
338 getAttachments(0, $session);
341 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) {
342 getAttachments(0, $session);
346 showInputForm($session);
347 sqimap_logout($imapConnection);
353 /**************** Only function definitions go below *************/
356 /* This function is used when not sending or adding attachments */
357 function newMail () {
358 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
359 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
360 $draft_id, $use_signature, $composesession, $forward_cc;
362 $send_to = decodeHeader($send_to, false);
363 $send_to_cc = decodeHeader($send_to_cc, false);
364 $send_to_bcc = decodeHeader($send_to_bcc, false);
368 } elseif ($reply_id) {
374 $use_signature = FALSE;
378 sqimap_mailbox_select($imapConnection, $mailbox);
379 $message = sqimap_get_message($imapConnection, $id, $mailbox);
380 $orig_header = $message->header
;
382 $message = getEntity($message, $ent_num);
384 if ($message->header
->type0
== 'text' ||
385 $message->header
->type1
== 'message') {
388 mime_fetch_body($imapConnection, $id, $ent_num),
389 $message->header
->encoding
);
392 mime_fetch_body($imapConnection, $id, 1),
393 $message->header
->encoding
);
399 if ($message->header
->type1
== 'html') {
400 $body = strip_tags($body);
404 $body_ary = explode("\n", $body);
405 $i = count($body_ary) - 1;
406 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
407 unset($body_ary[$i]);
411 for ($i=0; isset($body_ary[$i]); $i++
) {
413 if (ereg('^[ >]+', $body_ary[$i])) {
414 $body_ary[$i] = '>' . $body_ary[$i];
416 $body_ary[$i] = '> ' . $body_ary[$i];
420 sqWordWrap($body_ary[$i], $editor_size - 1);
422 $body .= $body_ary[$i] . "\n";
423 unset($body_ary[$i]);
426 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
427 _("Subject") . ': ' . $orig_header->subject
. "\n" .
428 _("From") . ': ' . $orig_header->from
. "\n" .
430 getLongDateString( $orig_header->date
). "\n" .
431 _("To") . ': ' . $orig_header->to
[0] . "\n";
432 if (count($orig_header->to
) > 1) {
433 for ($x=1; $x < count($orig_header->to
); $x++
) {
434 $bodyTop .= ' ' . $orig_header->to
[$x] . "\n";
437 if (isset($forward_cc) && $forward_cc) {
438 $bodyTop .= _("Cc") . ': ' . $orig_header->cc
[0] . "\n";
439 if (count($orig_header->cc
) > 1) {
440 for ($x = 1; $x < count($orig_header->cc
); $x++
) {
441 $bodyTop .= ' ' . $orig_header->cc
[$x] . "\n";
446 $body = $bodyTop . $body;
449 $orig_from = decodeHeader($orig_header->from
, false);
450 $body = getReplyCitation($orig_from) . $body;
457 $send_to = sqimap_find_email($send_to);
460 /* This formats a CC string if they hit "reply all" */
461 if ($send_to_cc != '') {
462 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
463 $send_to_cc = str_replace(';', ',', $send_to_cc);
464 $sendcc = explode(',', $send_to_cc);
467 for ($i = 0; $i < count($sendcc); $i++
) {
468 $sendcc[$i] = trim($sendcc[$i]);
469 if ($sendcc[$i] == '') {
473 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
474 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
475 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
477 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
478 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
479 (trim($sendcc[$i]) != '')) {
480 $send_to_cc .= trim($sendcc[$i]) . ', ';
483 $send_to_cc = trim($send_to_cc);
484 if (substr($send_to_cc, -1) == ',') {
485 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
488 } /* function newMail() */
491 function getAttachments($message, $session) {
492 global $mailbox, $attachments, $attachment_dir, $imapConnection,
493 $ent_num, $forward_id, $draft_id, $username;
495 if (isset($draft_id)) {
502 sqimap_mailbox_select($imapConnection, $mailbox);
503 $message = sqimap_get_message($imapConnection, $id, $mailbox);
506 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
507 if (count($message->entities
) == 0) {
508 if ($message->header
->entity_id
!= $ent_num) {
509 $filename = decodeHeader($message->header
->filename
);
511 if ($filename == "") {
512 $filename = "untitled-".$message->header
->entity_id
;
515 $localfilename = GenerateRandomString(32, '', 7);
516 $full_localfilename = "$hashed_attachment_dir/$localfilename";
517 while (file_exists($full_localfilename)) {
518 $localfilename = GenerateRandomString(32, '', 7);
519 $full_localfilename = "$hashed_attachment_dir/$localfilename";
522 $newAttachment = array();
523 $newAttachment['localfilename'] = $localfilename;
524 $newAttachment['remotefilename'] = $filename;
525 $newAttachment['type'] = strtolower($message->header
->type0
.
526 '/' . $message->header
->type1
);
527 $newAttachment['id'] = strtolower($message->header
->id
);
528 $newAttachment['session'] = $session;
530 /* Write Attachment to file */
531 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
532 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
533 $id, $message->header
->entity_id
),
534 $message->header
->encoding
));
537 $attachments[] = $newAttachment;
540 for ($i = 0; $i < count($message->entities
); $i++
) {
541 getAttachments($message->entities
[$i], $session);
547 function showInputForm ($session) {
548 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
549 $passed_body, $color, $use_signature, $signature, $prefix_sig,
550 $editor_size, $attachments, $subject, $newmail,
551 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
552 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
553 $username, $data_dir, $identity, $draft_id, $delete_draft,
554 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
555 $saved_draft, $mail_sent, $sig_first;
557 $subject = decodeHeader($subject, false);
558 $reply_subj = decodeHeader($reply_subj, false);
559 $forward_subj = decodeHeader($forward_subj, false);
561 if ($use_javascript_addr_book) {
562 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
563 'function open_abook() { ' . "\n" .
564 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
565 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
566 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
567 ' nwin.opener = document.windows;' . "\n" .
569 '// --></SCRIPT>' . "\n\n";
572 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
573 'ENCTYPE="multipart/form-data"';
574 do_hook("compose_form");
579 if (isset($draft_id)) {
580 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
582 if (isset($delete_draft)) {
583 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
585 if (isset($session)) {
586 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
589 if ($saved_draft == 'yes') {
590 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
592 if ($mail_sent == 'yes') {
593 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
595 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
596 if ($compose_new_win == '1') {
597 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
599 if ($location_of_buttons == 'top') {
600 showComposeButtonRow();
603 $idents = getPref($data_dir, $username, 'identities', 0);
605 echo ' <TR>' . "\n" .
606 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
609 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
610 '<select name=identity>' . "\n" .
611 '<option value=default>' .
612 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
613 $em = getPref($data_dir, $username, 'email_address');
615 echo htmlspecialchars(' <' . $em . '>') . "\n";
617 for ($i = 1; $i < $idents; $i ++
) {
618 echo '<option value="' . $i . '"';
619 if (isset($identity) && $identity == $i) {
622 echo '>' . htmlspecialchars(getPref($data_dir, $username,
624 $em = getPref($data_dir, $username, 'email_address' . $i);
626 echo htmlspecialchars(' <' . $em . '>') . "\n";
630 echo '</select>' . "\n" .
634 echo ' <TR>' . "\n" .
635 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
637 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
638 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
639 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
643 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
645 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
646 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
647 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
651 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
653 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
654 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
655 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
656 '</TD></TR>' . "\n" .
658 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
660 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
662 $reply_subj = str_replace('"', "'", $reply_subj);
663 $reply_subj = trim($reply_subj);
664 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
665 $reply_subj = 'Re: ' . $reply_subj;
667 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
668 htmlspecialchars($reply_subj) . '">';
670 elseif ($forward_subj) {
671 $forward_subj = trim($forward_subj);
672 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
673 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
674 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
675 $forward_subj = '[Fwd: ' . $forward_subj . ']';
677 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
678 htmlspecialchars($forward_subj) . '">';
680 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
681 htmlspecialchars($subject) . '">';
683 echo '</td></tr>' . "\n\n";
685 if ($location_of_buttons == 'between') {
686 showComposeButtonRow();
689 echo ' <TR>' . "\n" .
690 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
691 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
692 $editor_size . '" WRAP=HARD>';
693 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
694 if ($sig_first == '1') {
695 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
696 echo "\n\n".htmlspecialchars($body);
699 echo "\n\n".htmlspecialchars($body);
700 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
704 echo htmlspecialchars($body);
706 echo '</TEXTAREA><BR>' . "\n" .
710 if ($location_of_buttons == 'bottom') {
711 showComposeButtonRow();
713 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
714 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
717 /* This code is for attachments */
718 echo ' <TR>' . "\n" .
719 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
722 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
723 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
724 ' <input type="submit" name="attach"' .
725 ' value="' . _("Add") .'">' . "\n" .
729 if (count($attachments)) {
730 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
731 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
733 '</td><td align=left bgcolor="' . $color[0] . '">';
734 foreach ($attachments as $key => $info) {
735 if ($info['session'] == $session) {
736 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
737 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
738 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
739 show_readable_size(filesize($attached_file)) . ")<br>\n";
743 echo '<input type="submit" name="do_delete" value="' .
744 _("Delete selected attachments") . "\">\n" .
747 /* End of attachment code */
749 echo '</TABLE>' . "\n";
751 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
753 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
756 do_hook('compose_bottom');
757 echo '</BODY></HTML>' . "\n";
761 function showComposeButtonRow() {
762 global $use_javascript_addr_book, $save_as_draft,
763 $default_use_priority, $mailprio, $default_use_mdn,
764 $data_dir, $username;
766 echo " <TR><TD>\n</TD><TD>\n";
767 if ($default_use_priority) {
768 if(!isset($mailprio)) {
771 echo _("Priority") .': <select name="mailprio">'.
772 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
773 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
774 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
777 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
778 if ($default_use_mdn) {
779 if ($mdn_user_support) {
780 echo "\n\t". _("Receipt") .': '.
781 '<input type="checkbox" name="request_mdn" value=1>'. _("On read").
782 ' <input type="checkbox" name="request_dr" value=1>'. _("On Delivery");
786 echo " <TR><td>\n </td><td>\n";
787 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
788 if ($use_javascript_addr_book) {
789 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
790 " <input type=button value=\\\""._("Addresses").
791 "\\\" onclick='javascript:open_abook();'>\");".
792 " // --></SCRIPT><NOSCRIPT>\n".
793 " <input type=submit name=\"html_addr_search\" value=\"".
794 _("Addresses")."\">".
797 echo " <input type=submit name=\"html_addr_search\" value=\"".
798 _("Addresses")."\">";
800 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
802 if ($save_as_draft) {
803 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
806 do_hook('compose_button_row');
808 echo " </TD></TR>\n\n";
811 function checkInput ($show) {
813 * I implemented the $show variable because the error messages
814 * were getting sent before the page header. So, I check once
815 * using $show=false, and then when i'm ready to display the error
818 global $body, $send_to, $subject, $color;
820 if ($send_to == "") {
822 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
827 } /* function checkInput() */
830 /* True if FAILURE */
831 function saveAttachedFiles($session) {
832 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
834 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
835 $localfilename = GenerateRandomString(32, '', 7);
836 $full_localfilename = "$hashed_attachment_dir/$localfilename";
837 while (file_exists($full_localfilename)) {
838 $localfilename = GenerateRandomString(32, '', 7);
839 $full_localfilename = "$hashed_attachment_dir/$localfilename";
842 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
843 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
848 $newAttachment['localfilename'] = $localfilename;
849 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
850 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
851 $newAttachment['session'] = $session;
853 if ($newAttachment['type'] == "") {
854 $newAttachment['type'] = 'application/octet-stream';
857 $attachments[] = $newAttachment;
861 function ClearAttachments($session)
863 global $username, $attachments, $attachment_dir;
864 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
866 $rem_attachments = array();
867 foreach ($attachments as $info) {
868 if ($info['session'] == $session) {
869 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
870 if (file_exists($attached_file)) {
871 unlink($attached_file);
874 $rem_attachments[] = $info;
877 $attachments = $rem_attachments;
881 function getReplyCitation($orig_from)
883 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
885 /* First, return an empty string when no citation style selected. */
886 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
890 /* Decode the users name. */
891 $parpos = strpos($orig_from, '(');
892 if ($parpos === false) {
893 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
894 $orig_from = str_replace('"', '', $orig_from);
895 $orig_from = str_replace("'", '', $orig_from);
897 $end_parpos = strrpos($orig_from, ')');
898 $end_parpos -= ($end_parpos === false ?
$end_parpos : $parpos +
1);
899 $orig_from = trim(substr($orig_from, $parpos +
1, $end_parpos));
902 /* Make sure our final value isn't an empty string. */
903 if ($orig_from == '') {
907 /* Otherwise, try to select the desired citation style. */
908 switch ($reply_citation_style) {
911 $end = ' ' . _("said") . ':';
914 $start = '<' . _("quote") . ' ' . _("who") . '="';
918 $start = $reply_citation_start . ' ';
919 $end = $reply_citation_end;
925 /* Build and return the citation string. */
926 return ($start . $orig_from . $end . "\n");