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');
27 require_once('../functions/html.php');
29 /* --------------------- Specific Functions ------------------------------ */
34 * Does the opposite of sqWordWrap()
36 function sqUnWordWrap(&$body) {
37 $lines = explode("\n", $body);
40 for ($i = 0; $i < count($lines); $i ++
) {
41 ereg("^([\t >]*)([^\t >].*)?$", $lines[$i], $regs);
42 $CurrentSpaces = $regs[1];
43 if (isset($regs[2])) {
44 $CurrentRest = $regs[2];
48 $PreviousSpaces = $CurrentSpaces;
50 } else if (($PreviousSpaces == $CurrentSpaces) /* Do the beginnings match */
51 && (strlen($lines[$i - 1]) > 65) /* Over 65 characters long */
52 && strlen($CurrentRest)) { /* and there's a line to continue with */
53 $body .= ' ' . $CurrentRest;
55 $body .= "\n" . $lines[$i];
56 $PreviousSpaces = $CurrentSpaces;
62 /* ----------------------------------------------------------------------- */
64 if (!isset($attachments)) {
65 $attachments = array();
66 session_register('attachments');
69 if (!isset($composesession)) {
71 session_register('composesession');
74 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
75 $session = "$composesession" +
1;
76 $composesession = $session;
79 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
84 include_once ('../src/draft_actions.php');
85 if (! isset($reply_id)) {
91 if (! isset($mailprio)) {
94 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $mailprio, $session)) {
95 showInputForm($session);
98 $draft_message = _("Draft Email Saved");
99 /* If this is a resumed draft, then delete the original */
100 if(isset($delete_draft)) {
101 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
102 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
106 if ($compose_new_win == '1') {
107 Header("Location: compose.php?saved_draft=yes&session=$composesession");
111 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
112 "&startMessage=1¬e=$draft_message");
120 if (isset($HTTP_POST_FILES['attachfile']) &&
121 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
122 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
123 $AttachFailure = saveAttachedFiles($session);
125 if (checkInput(false) && !isset($AttachFailure)) {
126 $urlMailbox = urlencode (trim($mailbox));
127 if (! isset($reply_id)) {
131 * Set $default_charset to correspond with the user's selection
132 * of language interface.
137 * This is to change all newlines to \n
138 * We'll change them to \r\n later (in the sendMessage function)
140 $body = str_replace("\r\n", "\n", $body);
141 $body = str_replace("\r", "\n", $body);
144 * Rewrap $body so that no line is bigger than $editor_size
145 * This should only really kick in the sqWordWrap function
146 * if the browser doesn't support "VIRTUAL" as the wrap type.
148 $body = explode("\n", $body);
150 foreach ($body as $line) {
151 if( $line <> '-- ' ) {
152 $line = rtrim($line);
154 if (strlen($line) <= $editor_size +
1) {
155 $newBody .= $line . "\n";
157 sqWordWrap($line, $editor_size);
158 $newBody .= $line . "\n";
163 do_hook('compose_send');
165 $MDN = False; // we are not sending a mdn response
166 if (! isset($mailprio)) {
167 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
168 $subject, $body, $reply_id, $MDN, '', $session);
170 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
171 $subject, $body, $reply_id, $MDN, $mailprio, $session);
174 showInputForm($session);
177 if ( isset($delete_draft)) {
178 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
179 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
182 if ($compose_new_win == '1') {
183 Header("Location: compose.php?mail_sent=yes");
186 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
191 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
194 if ($compose_new_win == '1') {
195 compose_Header($color, $mailbox);
198 displayPageHeader($color, $mailbox);
200 if (isset($AttachFailure)) {
201 plain_error_message(_("Could not move/copy file. File not attached"),
206 showInputForm($session);
207 /* sqimap_logout($imapConnection); */
209 } elseif (isset($html_addr_search_done)) {
210 if ($compose_new_win == '1') {
211 compose_Header($color, $mailbox);
214 displayPageHeader($color, $mailbox);
217 if (isset($send_to_search) && is_array($send_to_search)) {
218 foreach ($send_to_search as $k => $v) {
219 if (substr($k, 0, 1) == 'T') {
225 elseif (substr($k, 0, 1) == 'C') {
231 elseif (substr($k, 0, 1) == 'B') {
233 $send_to_bcc .= ', ';
239 showInputForm($session);
240 } elseif (isset($html_addr_search)) {
241 if (isset($HTTP_POST_FILES['attachfile']) &&
242 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
243 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
244 if (saveAttachedFiles($session)) {
245 plain_error_message(_("Could not move/copy file. File not attached"), $color);
249 * I am using an include so as to elminiate an extra unnecessary
250 * click. If you can think of a better way, please implement it.
252 include_once('./addrbook_search_html.php');
253 } elseif (isset($attach)) {
254 if (saveAttachedFiles($session)) {
255 plain_error_message(_("Could not move/copy file. File not attached"), $color);
257 if ($compose_new_win == '1') {
258 compose_Header($color, $mailbox);
261 displayPageHeader($color, $mailbox);
263 showInputForm($session);
265 elseif (isset($sigappend)) {
266 $idents = getPref($data_dir, $username, 'identities', 0);
268 if ($identity == 'default') {
273 $signature = getSig($data_dir, $username, $no);
275 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
276 if ($compose_new_win == '1') {
277 compose_Header($color, $mailbox);
279 displayPageHeader($color, $mailbox);
281 showInputForm($session);
282 } elseif (isset($do_delete)) {
283 if ($compose_new_win == '1') {
284 compose_Header($color, $mailbox);
287 displayPageHeader($color, $mailbox);
290 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
291 if (isset($delete) && is_array($delete)) {
292 foreach($delete as $index) {
293 $attached_file = $hashed_attachment_dir . '/'
294 . $attachments[$index]['localfilename'];
295 unlink ($attached_file);
296 unset ($attachments[$index]);
300 showInputForm($session);
302 } elseif (isset($attachedmessages)) {
305 * This handles the case if we attache message
307 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
309 if ($compose_new_win == '1') {
310 compose_Header($color, $mailbox);
313 displayPageHeader($color, $mailbox);
319 showInputForm($session);
320 sqimap_logout($imapConnection);
324 * This handles the default case as well as the error case
325 * (they had the same code) --> if (isset($smtpErrors))
327 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
329 if ($compose_new_win == '1') {
330 compose_Header($color, $mailbox);
333 displayPageHeader($color, $mailbox);
338 ClearAttachments($session);
340 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) {
341 getAttachments(0, $session);
344 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) {
345 getAttachments(0, $session);
348 if (isset($passed_id) && $passed_id && isset($ent_num) && $ent_num) {
349 getAttachments(0, $session);
353 showInputForm($session);
354 sqimap_logout($imapConnection);
360 /**************** Only function definitions go below *************/
363 /* This function is used when not sending or adding attachments */
364 function newMail () {
365 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
366 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
367 $draft_id, $use_signature, $composesession, $forward_cc, $passed_id;
369 $send_to = decodeHeader($send_to, false);
370 $send_to_cc = decodeHeader($send_to_cc, false);
371 $send_to_bcc = decodeHeader($send_to_bcc, false);
372 $send_to = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to))));
373 $send_to_cc = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to_cc))));
374 $send_to_bcc = str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', '"', $send_to_bcc))));
378 } elseif ($reply_id) {
380 } elseif ($passed_id) {
387 $use_signature = FALSE;
391 sqimap_mailbox_select($imapConnection, $mailbox);
392 $message = sqimap_get_message($imapConnection, $id, $mailbox);
393 $orig_header = $message->header
;
396 $ent_ar = preg_split('/_/',$ent_num);
397 foreach($ent_ar as $ent_num) {
398 $message = getEntity($message, $ent_num);
399 if ($message->header
->type0
== 'text' ||
400 $message->header
->type1
== 'message') {
401 $bodypart = decodeBody(
402 mime_fetch_body($imapConnection, $id, $ent_num),
403 $message->header
->encoding
);
404 if ($message->header
->type1
== 'html') {
405 $bodypart = strip_tags($bodypart);
410 } else if ($message->header
->type0
== 'text' ||
411 $message->header
->type1
== 'message') {
413 mime_fetch_body($imapConnection, $id, 1),
414 $message->header
->encoding
);
415 if ($message->header
->type1
== 'html') {
416 $body = strip_tags($body);
423 /* this corrects some wrapping/quoting problems on replies */
425 $rewrap_body = explode("\n", $body);
426 for ($i=0;$i<count($rewrap_body);$i++
) {
427 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
428 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
430 $rewrap_body[$i] = str_replace("\n", "\n$gt ", $rewrap_body[$i]);
432 $rewrap_body[$i] .= "\n";
434 $body = implode("", $rewrap_body);
437 $body_ary = explode("\n", $body);
438 $i = count($body_ary) - 1;
439 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
440 unset($body_ary[$i]);
444 for ($i=0; isset($body_ary[$i]); $i++
) {
446 if (preg_match("/^(>){1,}/", $body_ary[$i])) {
447 $body_ary[$i] = '>' . $body_ary[$i];
449 $body_ary[$i] = '> ' . $body_ary[$i];
453 sqWordWrap($body_ary[$i], $editor_size );
455 $body .= $body_ary[$i] . "\n";
456 unset($body_ary[$i]);
459 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
460 _("Subject") . ': ' . $orig_header->subject
. "\n" .
461 _("From") . ': ' . $orig_header->from
. "\n" .
463 getLongDateString( $orig_header->date
). "\n" .
464 _("To") . ': ' . $orig_header->to
[0] . "\n";
465 if (count($orig_header->to
) > 1) {
466 for ($x=1; $x < count($orig_header->to
); $x++
) {
467 $bodyTop .= ' ' . $orig_header->to
[$x] . "\n";
470 if (isset($forward_cc) && $forward_cc) {
471 $bodyTop .= _("Cc") . ': ' . $orig_header->cc
[0] . "\n";
472 if (count($orig_header->cc
) > 1) {
473 for ($x = 1; $x < count($orig_header->cc
); $x++
) {
474 $bodyTop .= ' ' . $orig_header->cc
[$x] . "\n";
479 $body = $bodyTop . $body;
482 $orig_from = decodeHeader($orig_header->from
, false);
483 $body = getReplyCitation($orig_from) . $body;
490 $send_to = sqimap_find_email($send_to);
493 /* This formats a CC string if they hit "reply all" */
494 if ($send_to_cc != '') {
495 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
496 $send_to_cc = str_replace(';', ',', $send_to_cc);
497 $sendcc = explode(',', $send_to_cc);
500 for ($i = 0; $i < count($sendcc); $i++
) {
501 $sendcc[$i] = trim($sendcc[$i]);
502 if ($sendcc[$i] == '') {
506 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
507 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
508 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
510 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
511 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
512 (trim($sendcc[$i]) != '')) {
513 $send_to_cc .= trim($sendcc[$i]) . ', ';
516 $send_to_cc = trim($send_to_cc);
517 if (substr($send_to_cc, -1) == ',') {
518 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
521 } /* function newMail() */
524 function getAttachments($message, $session) {
525 global $mailbox, $attachments, $attachment_dir, $imapConnection,
526 $ent_num, $forward_id, $draft_id, $username, $passed_id;
528 if (isset($draft_id)) {
530 } else if (isset($forward_id)) {
537 sqimap_mailbox_select($imapConnection, $mailbox);
538 $message = sqimap_get_message($imapConnection, $id, $mailbox);
541 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
542 if (count($message->entities
) == 0) {
543 if ($message->header
->entity_id
!= $ent_num) {
544 $filename = decodeHeader($message->header
->filename
);
546 if ($filename == "") {
547 $filename = "untitled-".$message->header
->entity_id
;
550 $localfilename = GenerateRandomString(32, '', 7);
551 $full_localfilename = "$hashed_attachment_dir/$localfilename";
552 while (file_exists($full_localfilename)) {
553 $localfilename = GenerateRandomString(32, '', 7);
554 $full_localfilename = "$hashed_attachment_dir/$localfilename";
557 $newAttachment = array();
558 $newAttachment['localfilename'] = $localfilename;
559 $newAttachment['remotefilename'] = $filename;
560 $newAttachment['type'] = strtolower($message->header
->type0
.
561 '/' . $message->header
->type1
);
562 $newAttachment['id'] = strtolower($message->header
->id
);
563 $newAttachment['session'] = $session;
565 /* Write Attachment to file */
566 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
567 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
568 $id, $message->header
->entity_id
),
569 $message->header
->encoding
));
572 $attachments[] = $newAttachment;
575 for ($i = 0; $i < count($message->entities
); $i++
) {
576 getAttachments($message->entities
[$i], $session);
582 function showInputForm ($session) {
583 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
584 $passed_body, $color, $use_signature, $signature, $prefix_sig,
585 $editor_size, $attachments, $subject, $newmail,
586 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
587 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
588 $username, $data_dir, $identity, $draft_id, $delete_draft,
589 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
590 $saved_draft, $mail_sent, $sig_first, $edit_as_new;
592 $file_uploads = ini_get('file_uploads');
593 $subject = decodeHeader($subject, false);
594 $reply_subj = decodeHeader($reply_subj, false);
595 $forward_subj = decodeHeader($forward_subj, false);
597 if ($use_javascript_addr_book) {
598 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
599 'function open_abook() { ' . "\n" .
600 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
601 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
602 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
603 ' nwin.opener = document.windows;' . "\n" .
605 '// --></SCRIPT>' . "\n\n";
608 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ';
610 echo 'ENCTYPE="multipart/form-data"';
612 do_hook("compose_form");
617 if (isset($draft_id) && !$edit_as_new) {
618 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
620 if (isset($delete_draft)) {
621 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
623 if (isset($session)) {
624 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
627 if ($saved_draft == 'yes') {
628 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
630 if ($mail_sent == 'yes') {
631 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
633 echo html_tag( 'table', '', 'center', '', 'width="100%" cellspacing="0" border="0"' ) . "\n";
634 if ($compose_new_win == '1') {
635 echo html_tag( 'table', 'center', $color[0], 'width="100%" border="0"' ) .
639 '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'>',
643 if ($location_of_buttons == 'top') {
644 showComposeButtonRow();
647 $idents = getPref($data_dir, $username, 'identities', 0);
649 echo html_tag( 'tr' ) . "\n" .
650 html_tag( 'td', "\n" . _("From:"), 'right', $color[4], 'width="10%"' ) .
651 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
652 '<select name=identity>' . "\n" .
653 '<option value=default>' .
654 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
655 $em = getPref($data_dir, $username, 'email_address');
657 echo htmlspecialchars(' <' . $em . '>') . "\n";
659 for ($i = 1; $i < $idents; $i ++
) {
660 echo '<option value="' . $i . '"';
661 if (isset($identity) && $identity == $i) {
664 echo '>' . htmlspecialchars(getPref($data_dir, $username,
666 $em = getPref($data_dir, $username, 'email_address' . $i);
668 echo htmlspecialchars(' <' . $em . '>') . "\n";
672 echo '</select>' . "\n" .
677 html_tag( 'td', "\n" . _("To:"), 'right', $color[4], 'width="10%"' ) .
679 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
680 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n",
681 'left', $color[4], 'width="90%"' )
684 html_tag( 'td', "\n" . _("CC:"), 'right', $color[4], 'width="10%"' ) .
686 ' <INPUT TYPE=text NAME="send_to_cc" VALUE="' .
687 htmlspecialchars($send_to_cc) . '" SIZE=60><BR>' . "\n",
688 'left', $color[4], 'width="90%"' )
691 html_tag( 'td', "\n" . _("BCC:"), 'right', $color[4], 'width="10%"' ) .
693 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
694 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n",
695 'left', $color[4], 'width="90%"' )
699 $reply_subj = str_replace('"', '\'', $reply_subj);
700 $reply_subj = trim($reply_subj);
701 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
702 $reply_subj = 'Re: ' . $reply_subj;
704 $subject = $reply_subj;
706 elseif ($forward_subj) {
707 $forward_subj = trim($forward_subj);
708 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
709 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
710 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
711 $forward_subj = '[Fwd: ' . $forward_subj . ']';
713 $subject = $forward_subj;
719 html_tag( 'td', "\n" . _("Subject:"), 'right', $color[4], 'width="10%"' ) .
721 ' <INPUT TYPE=text NAME="subject" VALUE="' .
722 htmlspecialchars($subject) . '" SIZE=60><BR>' . "\n",
723 'left', $color[4], 'width="90%"' )
726 if ($location_of_buttons == 'between') {
727 showComposeButtonRow();
730 echo html_tag( 'tr' ) . "\n";
731 if ($compose_new_win == '1') {
732 echo html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . "\n" .
733 ' <textarea name="body" rows="20" cols="' .
734 $editor_size . '" wrap="virtual">';
737 echo html_tag( 'td', '', 'left', $color[4], 'colspan="2"' ) . "\n" .
738 ' <textarea name="body" rows="20" cols="' .
739 $editor_size . '" wrap="virtual">';
741 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
742 if ($sig_first == '1') {
743 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
744 echo "\n\n".htmlspecialchars($body);
747 echo "\n\n".htmlspecialchars($body);
748 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
752 echo htmlspecialchars($body);
754 echo '</textarea><br>' . "\n" .
758 if ($location_of_buttons == 'bottom') {
759 showComposeButtonRow();
762 html_tag( 'td', ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">', 'left', '', 'colspan="2"' ) ."\n"
766 /* This code is for attachments */
769 html_tag( 'td', "\n" . _("Attach:") ."\n", 'right', '', 'valign="middle"' ) ."\n" .
770 html_tag( 'td', "\n" . '<INPUT NAME="attachfile" SIZE=48 TYPE="file">' .
771 ' <input type="submit" name="attach"' .
772 ' value="' . _("Add") .'">' . "\n" ,
773 'left', '', 'valign="middle"' ) ."\n"
776 if (count($attachments)) {
777 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
778 echo html_tag( 'tr' ) .
779 html_tag( 'td', "\n" . ' ', 'right', $color[0] ) .
780 html_tag( 'td', '', 'left', $color[0] );
781 foreach ($attachments as $key => $info) {
782 if ($info['session'] == $session) {
783 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
784 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
785 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
786 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
790 echo '<input type="submit" name="do_delete" value="' .
791 _("Delete selected attachments") . "\">\n" .
794 /* End of attachment code */
796 if ($compose_new_win == '1') {
797 echo '</table>'."\n";
799 echo '</table>' . "\n";
801 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
803 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
806 do_hook('compose_bottom');
807 echo '</BODY></HTML>' . "\n";
811 function showComposeButtonRow() {
812 global $use_javascript_addr_book, $save_as_draft,
813 $default_use_priority, $mailprio, $default_use_mdn,
814 $request_mdn, $request_dr,
815 $data_dir, $username;
817 echo html_tag( 'tr' ) .
818 html_tag( 'td', "\n", 'left' ) .
819 html_tag( 'td', '', 'left' );
820 if ($default_use_priority) {
821 if(!isset($mailprio)) {
824 echo _("Priority") .': <select name="mailprio">'.
825 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
826 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
827 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
830 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
831 if ($default_use_mdn) {
832 if ($mdn_user_support) {
833 echo "\n\t". _("Receipt") .': '.
834 '<input type="checkbox" name="request_mdn" value=1'.
835 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
836 ' <input type="checkbox" name="request_dr" value=1'.
837 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
841 echo " </td></tr>\n" .
843 html_tag( 'td', "\n", 'left' ) .
844 html_tag( 'td', '', 'left' );
845 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
846 if ($use_javascript_addr_book) {
847 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
848 " <input type=button value=\\\""._("Addresses").
849 "\\\" onclick='javascript:open_abook();'>\");".
850 " // --></SCRIPT><NOSCRIPT>\n".
851 " <input type=submit name=\"html_addr_search\" value=\"".
852 _("Addresses")."\">".
855 echo " <input type=submit name=\"html_addr_search\" value=\"".
856 _("Addresses")."\">";
858 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
860 if ($save_as_draft) {
861 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
864 do_hook('compose_button_row');
866 echo " </td></tr>\n\n";
869 function checkInput ($show) {
871 * I implemented the $show variable because the error messages
872 * were getting sent before the page header. So, I check once
873 * using $show=false, and then when i'm ready to display the error
876 global $body, $send_to, $subject, $color;
878 if ($send_to == "") {
880 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
885 } /* function checkInput() */
888 /* True if FAILURE */
889 function saveAttachedFiles($session) {
890 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
892 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
893 $localfilename = GenerateRandomString(32, '', 7);
894 $full_localfilename = "$hashed_attachment_dir/$localfilename";
895 while (file_exists($full_localfilename)) {
896 $localfilename = GenerateRandomString(32, '', 7);
897 $full_localfilename = "$hashed_attachment_dir/$localfilename";
900 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
901 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
906 $newAttachment['localfilename'] = $localfilename;
907 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
908 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
909 $newAttachment['session'] = $session;
911 if ($newAttachment['type'] == "") {
912 $newAttachment['type'] = 'application/octet-stream';
915 $attachments[] = $newAttachment;
919 function ClearAttachments($session)
921 global $username, $attachments, $attachment_dir;
922 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
924 $rem_attachments = array();
925 if (is_array($attachments)) {
926 foreach ($attachments as $info) {
927 if ($info['session'] == $session) {
928 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
929 if (file_exists($attached_file)) {
930 unlink($attached_file);
934 $rem_attachments[] = $info;
938 $attachments = $rem_attachments;
942 function getReplyCitation($orig_from)
944 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
946 /* First, return an empty string when no citation style selected. */
947 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
951 /* Decode the users name. */
952 $parpos = strpos($orig_from, '(');
953 if ($parpos === false) {
954 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
955 $orig_from = str_replace('"', '', $orig_from);
956 $orig_from = str_replace("'", '', $orig_from);
958 $end_parpos = strrpos($orig_from, ')');
959 $end_parpos -= ($end_parpos === false ?
$end_parpos : $parpos +
1);
960 $orig_from = trim(substr($orig_from, $parpos +
1, $end_parpos));
963 /* Make sure our final value isn't an empty string. */
964 if ($orig_from == '') {
968 /* Otherwise, try to select the desired citation style. */
969 switch ($reply_citation_style) {
972 $end = ' ' . _("said") . ':';
975 $start = '<' . _("quote") . ' ' . _("who") . '="';
979 $start = $reply_citation_start . ' ';
980 $end = $reply_citation_end;
986 /* Build and return the citation string. */
987 return ($start . $orig_from . $end . "\n");