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 /* ----------------------------------------------------------------------- */
103 if (!isset($attachments)) {
104 $attachments = array();
105 session_register('attachments');
108 if (!isset($composesession)) {
110 session_register('composesession');
113 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
114 $session = "$composesession" +
1;
115 $composesession = $session;
118 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
123 include_once ('../src/draft_actions.php');
124 if (! isset($reply_id)) {
130 if (! isset($mailprio)) {
133 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $mailprio, $session)) {
134 showInputForm($session);
137 $draft_message = _("Draft Email Saved");
138 /* If this is a resumed draft, then delete the original */
139 if(isset($delete_draft)) {
140 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
141 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
145 if ($compose_new_win == '1') {
146 Header("Location: compose.php?saved_draft=yes&session=$composesession");
150 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
151 "&startMessage=1¬e=".urlencode($draft_message));
159 if (isset($HTTP_POST_FILES['attachfile']) &&
160 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
161 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
162 $AttachFailure = saveAttachedFiles($session);
164 if (checkInput(false) && !isset($AttachFailure)) {
165 $urlMailbox = urlencode (trim($mailbox));
166 if (! isset($reply_id)) {
170 * Set $default_charset to correspond with the user's selection
171 * of language interface.
176 * This is to change all newlines to \n
177 * We'll change them to \r\n later (in the sendMessage function)
179 $body = str_replace("\r\n", "\n", $body);
180 $body = str_replace("\r", "\n", $body);
183 * Rewrap $body so that no line is bigger than $editor_size
184 * This should only really kick in the sqWordWrap function
185 * if the browser doesn't support "VIRTUAL" as the wrap type.
187 $body = explode("\n", $body);
189 foreach ($body as $line) {
190 if( $line <> '-- ' ) {
191 $line = rtrim($line);
193 if (strlen($line) <= $editor_size +
1) {
194 $newBody .= $line . "\n";
196 sqWordWrap($line, $editor_size);
197 $newBody .= $line . "\n";
202 do_hook('compose_send');
204 $MDN = False; // we are not sending a mdn response
205 if (! isset($mailprio)) {
206 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
207 $subject, $body, $reply_id, $MDN, '', $session);
209 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
210 $subject, $body, $reply_id, $MDN, $mailprio, $session);
213 showInputForm($session);
216 if ( isset($delete_draft)) {
217 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
218 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
221 if ($compose_new_win == '1') {
222 Header("Location: compose.php?mail_sent=yes");
225 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
230 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
233 if ($compose_new_win == '1') {
234 compose_Header($color, $mailbox);
237 displayPageHeader($color, $mailbox);
239 if (isset($AttachFailure)) {
240 plain_error_message(_("Could not move/copy file. File not attached"),
244 showInputForm($session);
245 /* sqimap_logout($imapConnection); */
247 } elseif (isset($html_addr_search_done)) {
248 if ($compose_new_win == '1') {
249 compose_Header($color, $mailbox);
252 displayPageHeader($color, $mailbox);
255 if (isset($send_to_search) && is_array($send_to_search)) {
256 foreach ($send_to_search as $k => $v) {
257 if (substr($k, 0, 1) == 'T') {
263 elseif (substr($k, 0, 1) == 'C') {
269 elseif (substr($k, 0, 1) == 'B') {
271 $send_to_bcc .= ', ';
277 showInputForm($session);
278 } elseif (isset($html_addr_search)) {
279 if (isset($HTTP_POST_FILES['attachfile']) &&
280 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
281 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
282 if (saveAttachedFiles($session)) {
283 plain_error_message(_("Could not move/copy file. File not attached"), $color);
287 * I am using an include so as to elminiate an extra unnecessary
288 * click. If you can think of a better way, please implement it.
290 include_once('./addrbook_search_html.php');
291 } elseif (isset($attach)) {
292 if (saveAttachedFiles($session)) {
293 plain_error_message(_("Could not move/copy file. File not attached"), $color);
295 if ($compose_new_win == '1') {
296 compose_Header($color, $mailbox);
299 displayPageHeader($color, $mailbox);
301 showInputForm($session);
303 elseif (isset($sigappend)) {
304 $idents = getPref($data_dir, $username, 'identities', 0);
306 if ($identity == 'default') {
311 $signature = getSig($data_dir, $username, $no);
313 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
314 if ($compose_new_win == '1') {
315 compose_Header($color, $mailbox);
317 displayPageHeader($color, $mailbox);
319 showInputForm($session);
320 } elseif (isset($do_delete)) {
321 if ($compose_new_win == '1') {
322 compose_Header($color, $mailbox);
325 displayPageHeader($color, $mailbox);
328 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
329 if (isset($delete) && is_array($delete)) {
330 foreach($delete as $index) {
331 $attached_file = $hashed_attachment_dir . '/'
332 . $attachments[$index]['localfilename'];
333 unlink ($attached_file);
334 unset ($attachments[$index]);
338 showInputForm($session);
340 } elseif (isset($attachedmessages)) {
343 * This handles the case if we attache message
345 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
347 if ($compose_new_win == '1') {
348 compose_Header($color, $mailbox);
351 displayPageHeader($color, $mailbox);
356 if (!isset($passed_ent_id)) $passed_ent_id = '';
357 if (!isset($passed_id)) $passed_id = '';
358 if (!isset($mailbox)) $mailbox = '';
359 if (!isset($action)) $action = '';
361 $values = newMail($imapConnection,$mailbox,$passed_id,$passed_ent_id, $action, $session);
362 showInputForm($session, $values);
363 sqimap_logout($imapConnection);
367 * This handles the default case as well as the error case
368 * (they had the same code) --> if (isset($smtpErrors))
370 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
372 if ($compose_new_win == '1') {
373 compose_Header($color, $mailbox);
376 displayPageHeader($color, $mailbox);
381 if (!isset($passed_ent_id)) $passed_ent_id = '';
382 if (!isset($passed_id)) $passed_id = '';
383 if (!isset($mailbox)) $mailbox = '';
384 if (!isset($action)) $action = '';
386 $values = newMail($imapConnection,$mailbox,$passed_id,$passed_ent_id, $action, $session);
387 showInputForm($session, $values);
388 sqimap_logout($imapConnection);
393 /**************** Only function definitions go below *************/
396 /* This function is used when not sending or adding attachments */
397 function newMail ($imapConnection, $mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
398 global $editor_size, $default_use_priority,
399 $use_signature, $composesession, $data_dir, $username;
401 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
404 sqimap_mailbox_select($imapConnection, $mailbox);
405 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
407 if ($passed_ent_id) {
408 /* redefine the messsage in case of message/rfc822 */
409 $message = $message->getEntity($passed_ent_id);
410 /* message is an entity which contains the envelope and type0=message
411 * and type1=rfc822. The actual entities are childs from
412 * $message->entities[0]. That's where the encoding and is located
415 $entities = $message->entities
[0]->findDisplayEntity
416 (array(), $alt_order = array('text/plain'));
417 if (!count($entities)) {
418 $entities = $message->entities
[0]->findDisplayEntity
419 (array(), $alt_order = array('text/plain','html/plain'));
421 $orig_header = $message->header
; /* here is the envelope located */
422 /* redefine the message for picking up the attachments */
423 $message = $message->entities
[0];
426 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
427 if (!count($entities)) {
428 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
430 $orig_header = $message->header
;
432 $encoding = $message->header
->encoding
;
433 $type0 = $message->type0
;
434 $type1 = $message->type1
;
436 foreach ($entities as $ent) {
437 $bodypart = decodeBody(
438 mime_fetch_body($imapConnection, $passed_id, $ent),
440 if ($type1 == 'html') {
441 $bodypart = strip_tags($bodypart);
445 if ($default_use_priority) {
446 $mailprio = substr($orig_header->priority
,0,1);
450 ClearAttachments($session);
453 $idents = getPref($data_dir, $username, 'identities');
454 $from_o = $message->header
->from
;
455 if (is_object($from_o)) {
456 $orig_from = $from_o->getAddress();
460 if (!empty($idents) && $idents > 1) {
461 for ($i = 1; $i < $idents; $i++
) {
462 $enc_from_name = '"'.
466 '" <' . getPref($data_dir, $username,
467 'email_address' . $i) . '>';
468 if ($enc_from_name == $orig_from) {
477 $use_signature = FALSE;
478 $send_to = $orig_header->getAddr_s('to');
479 $send_to_cc = $orig_header->getAddr_s('cc');
480 $send_to_bcc = $orig_header->getAddr_s('bcc');
481 $subject = $orig_header->subject
;
483 $body_ary = explode("\n", $body);
484 $cnt = count($body_ary) ;
486 for ($i=0; $i < $cnt; $i++
) {
487 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
488 sqWordWrap($body_ary[$i], $editor_size );
489 $body .= $body_ary[$i] . "\n";
491 unset($body_ary[$i]);
494 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
496 case ('edit_as_new'):
497 $send_to = $orig_header->getAddr_s('to');
498 $send_to_cc = $orig_header->getAddr_s('cc');
499 $send_to_bcc = $orig_header->getAddr_s('bcc');
500 $subject = $orig_header->subject
;
501 $mailprio = $orig_header->priority
;
503 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
508 // $orig_from = $orig_header->from->getAddress();
509 $subject = $orig_header->subject
;
510 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
511 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
512 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
513 $subject = '[Fwd: ' . $subject . ']';
515 $body = getforwardHeader($orig_header) . $body;
517 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
519 case ('reply' ||
'reply_all'):
520 $send_to = $orig_header->reply_to
;
522 $send_to = $send_to->getAddress();
524 $send_to = $orig_header->from
->getAddress();
526 // $orig_from = $orig_header->from->getAddress();
527 $subject = $orig_header->subject
;
528 $subject = str_replace('"', "'", $subject);
529 $subject = trim($subject);
530 if (substr(strtolower($subject), 0, 3) != 're:') {
531 $subject = 'Re: ' . $subject;
533 if ($action == 'reply_all') {
534 $send_to_cc = replyAllString($orig_header);
536 /* this corrects some wrapping/quoting problems on replies */
537 $rewrap_body = explode("\n", $body);
538 $body = getReplyCitation($orig_header->from
->personal
);
539 $cnt = count($rewrap_body);
540 for ($i=0;$i<$cnt;$i++
) {
541 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
542 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
544 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
546 $body .= '> ' . $rewrap_body[$i] . "\n";
548 unset($rewrap_body[$i]);
556 'send_to' => $send_to,
557 'send_to_cc' => $send_to_cc,
558 'send_to_bcc' => $send_to_bcc,
559 'subject' => $subject,
560 'mailprio' => $mailprio,
562 'identity' => $identity
566 } /* function newMail() */
569 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
570 global $attachments, $attachment_dir, $username;
572 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
573 if (!count($message->entities
) ||
574 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
575 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
576 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
577 $filename = decodeHeader($message->header
->subject
.'.eml');
578 if ($filename == "") {
579 $filename = "untitled-".$message->entity_id
.'.eml';
582 $filename = decodeHeader($message->header
->filename
);
583 if ($filename == "") {
584 $filename = "untitled-".$message->entity_id
;
587 $localfilename = GenerateRandomString(32, '', 7);
588 $full_localfilename = "$hashed_attachment_dir/$localfilename";
589 while (file_exists($full_localfilename)) {
590 $localfilename = GenerateRandomString(32, '', 7);
591 $full_localfilename = "$hashed_attachment_dir/$localfilename";
594 $newAttachment = array();
595 $newAttachment['localfilename'] = $localfilename;
596 $newAttachment['remotefilename'] = $filename;
597 $newAttachment['type'] = strtolower($message->type0
.
598 '/' . $message->type1
);
599 $newAttachment['id'] = strtolower($message->header
->id
);
600 $newAttachment['session'] = $session;
602 /* Write Attachment to file */
603 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
604 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
605 $passed_id, $message->entity_id
),
606 $message->header
->encoding
));
609 $attachments[] = $newAttachment;
612 for ($i = 0; $i < count($message->entities
); $i++
) {
613 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
619 function showInputForm ($session, $values=false) {
620 global $send_to, $send_to_cc, $body,
621 $passed_body, $color, $use_signature, $signature, $prefix_sig,
622 $editor_size, $attachments, $subject, $newmail,
623 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
624 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
625 $username, $data_dir, $identity, $draft_id, $delete_draft,
626 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
627 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action;
629 $subject = decodeHeader($subject, false);
631 $send_to = $values['send_to'];
632 $send_to_cc = $values['send_to_cc'];
633 $send_to_bcc = $values['send_to_bcc'];
634 $subject = $values['subject'];
635 $mailprio = $values['mailprio'];
636 $body = $values['body'];
637 $identity = $values['identity'];
640 if ($use_javascript_addr_book) {
641 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
642 'function open_abook() { ' . "\n" .
643 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
644 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
645 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
646 ' nwin.opener = document.windows;' . "\n" .
648 '// --></SCRIPT>' . "\n\n";
651 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
652 'ENCTYPE="multipart/form-data"';
653 do_hook("compose_form");
658 if ($action == 'draft') {
659 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
661 if (isset($delete_draft)) {
662 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
664 if (isset($session)) {
665 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
668 if ($saved_draft == 'yes') {
669 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
671 if ($mail_sent == 'yes') {
672 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
674 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
675 if ($compose_new_win == '1') {
676 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
677 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
679 if ($location_of_buttons == 'top') {
680 showComposeButtonRow();
683 $idents = getPref($data_dir, $username, 'identities', 0);
685 echo ' <TR>' . "\n" .
686 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
689 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
690 '<select name=identity>' . "\n" .
691 '<option value=default>' .
692 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
693 $em = getPref($data_dir, $username, 'email_address');
695 echo htmlspecialchars(' <' . $em . '>') . "\n";
697 for ($i = 1; $i < $idents; $i ++
) {
698 echo '<option value="' . $i . '"';
699 if (isset($identity) && $identity == $i) {
702 echo '>' . htmlspecialchars(getPref($data_dir, $username,
704 $em = getPref($data_dir, $username, 'email_address' . $i);
706 echo htmlspecialchars(' <' . $em . '>') . "\n";
710 echo '</select>' . "\n" .
714 echo ' <TR>' . "\n" .
715 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
717 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
718 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
719 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
723 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
725 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
726 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
727 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
731 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
733 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
734 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
735 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
736 '</TD></TR>' . "\n" .
738 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
740 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
741 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
742 htmlspecialchars($subject) . '">';
743 echo '</td></tr>' . "\n\n";
745 if ($location_of_buttons == 'between') {
746 showComposeButtonRow();
748 if ($compose_new_win == '1') {
749 echo ' <TR>' . "\n" .
750 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
751 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
752 $editor_size . '" WRAP="VIRTUAL">';
755 echo ' <TR>' . "\n" .
756 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
757 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
758 $editor_size . '" WRAP="VIRTUAL">';
760 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
761 if ($sig_first == '1') {
762 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
763 echo "\n\n".htmlspecialchars($body);
766 echo "\n\n".htmlspecialchars($body);
767 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
771 echo htmlspecialchars($body);
773 echo '</TEXTAREA><BR>' . "\n" .
777 if ($location_of_buttons == 'bottom') {
778 showComposeButtonRow();
780 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
781 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
784 /* This code is for attachments */
785 echo ' <TR>' . "\n" .
786 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
789 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
790 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
791 ' <input type="submit" name="attach"' .
792 ' value="' . _("Add") .'">' . "\n" .
796 if (count($attachments)) {
797 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
798 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
800 '</td><td align=left bgcolor="' . $color[0] . '">';
801 foreach ($attachments as $key => $info) {
802 if ($info['session'] == $session) {
803 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
804 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
805 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
806 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
810 echo '<input type="submit" name="do_delete" value="' .
811 _("Delete selected attachments") . "\">\n" .
814 /* End of attachment code */
815 if ($compose_new_win == '1') {
816 echo '</TABLE>'."\n";
818 echo '</TABLE>' . "\n";
819 if ($action = 'reply' ||
$action = 'reply_all') {
820 echo '<input type=hidden name=reply_id value=' . $passed_id . ">\n";
822 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
825 do_hook('compose_bottom');
826 echo '</BODY></HTML>' . "\n";
830 function showComposeButtonRow() {
831 global $use_javascript_addr_book, $save_as_draft,
832 $default_use_priority, $mailprio, $default_use_mdn,
833 $request_mdn, $request_dr,
834 $data_dir, $username;
836 echo " <TR><TD>\n</TD><TD>\n";
837 if ($default_use_priority) {
838 if(!isset($mailprio)) {
841 echo _("Priority") .': <select name="mailprio">'.
842 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
843 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
844 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
847 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
848 if ($default_use_mdn) {
849 if ($mdn_user_support) {
850 echo "\n\t". _("Receipt") .': '.
851 '<input type="checkbox" name="request_mdn" value=1'.
852 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
853 ' <input type="checkbox" name="request_dr" value=1'.
854 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
858 echo " </td></tr>\n <TR><td>\n </td><td>\n";
859 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
860 if ($use_javascript_addr_book) {
861 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
862 " <input type=button value=\\\""._("Addresses").
863 "\\\" onclick='javascript:open_abook();'>\");".
864 " // --></SCRIPT><NOSCRIPT>\n".
865 " <input type=submit name=\"html_addr_search\" value=\"".
866 _("Addresses")."\">".
869 echo " <input type=submit name=\"html_addr_search\" value=\"".
870 _("Addresses")."\">";
872 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
874 if ($save_as_draft) {
875 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
878 do_hook('compose_button_row');
880 echo " </TD></TR>\n\n";
883 function checkInput ($show) {
885 * I implemented the $show variable because the error messages
886 * were getting sent before the page header. So, I check once
887 * using $show=false, and then when i'm ready to display the error
890 global $body, $send_to, $subject, $color;
892 if ($send_to == "") {
894 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
899 } /* function checkInput() */
902 /* True if FAILURE */
903 function saveAttachedFiles($session) {
904 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
906 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
907 $localfilename = GenerateRandomString(32, '', 7);
908 $full_localfilename = "$hashed_attachment_dir/$localfilename";
909 while (file_exists($full_localfilename)) {
910 $localfilename = GenerateRandomString(32, '', 7);
911 $full_localfilename = "$hashed_attachment_dir/$localfilename";
914 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
915 if (function_exists("move_uploaded_file")) {
916 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
921 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
930 $newAttachment['localfilename'] = $localfilename;
931 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
932 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
933 $newAttachment['session'] = $session;
935 if ($newAttachment['type'] == "") {
936 $newAttachment['type'] = 'application/octet-stream';
939 $attachments[] = $newAttachment;
943 function ClearAttachments($session)
945 global $username, $attachments, $attachment_dir;
946 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
948 $rem_attachments = array();
949 if (is_array($attachments)) {
950 foreach ($attachments as $info) {
951 if ($info['session'] == $session) {
952 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
953 if (file_exists($attached_file)) {
954 unlink($attached_file);
958 $rem_attachments[] = $info;
962 $attachments = $rem_attachments;
966 function getReplyCitation($orig_from)
968 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
970 /* First, return an empty string when no citation style selected. */
971 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
975 /* Make sure our final value isn't an empty string. */
976 if ($orig_from == '') {
980 /* Otherwise, try to select the desired citation style. */
981 switch ($reply_citation_style) {
984 $end = ' ' . _("said") . ':';
987 $start = '<' . _("quote") . ' ' . _("who") . '="';
991 $start = $reply_citation_start . ' ';
992 $end = $reply_citation_end;
998 /* Build and return the citation string. */
999 return ($start . $orig_from . $end . "\n");