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) {
82 _("Subject") => strlen(_("Subject")),
83 _("From") => strlen(_("From")),
84 _("Date") => strlen(_("Date")),
85 _("To") => strlen(_("To")),
86 _("Cc") => strlen(_("Cc"))
88 $maxsize = max($display);
89 $indent = str_pad('',$maxsize+
2);
90 foreach($display as $key => $val) {
91 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
93 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
);
94 $bodyTop .= "\n". $display[_("Subject")] . decodeHeader($orig_header->subject
) . "\n" .
95 $display[_("From")] . decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
96 $display[_("Date")] . getLongDateString( $orig_header->date
). "\n" .
97 $display[_("To")] . decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
98 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
99 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
101 $bodyTop .= str_pad('', $editor_size -2 , '-');
105 /* ----------------------------------------------------------------------- */
108 * If the session is expired during a post this restores the compose session
111 //$session_expired = false;
112 if (session_is_registered('session_expired_post')) {
113 global $session_expired_post, $session_expired;
115 * extra check for username so we don't display previous post data from
116 * another user during this session.
118 if ($session_expired_post['username'] != $username) {
119 session_unregister('session_expired_post');
120 session_unregister('session_expired');
122 foreach ($session_expired_post as $postvar => $val) {
132 $session_expired = true;
134 session_unregister('session_expired_post');
135 session_unregister('session_expired');
136 if (!isset($mailbox)) {
139 if ($compose_new_win == '1') {
140 compose_Header($color, $mailbox);
142 displayPageHeader($color, $mailbox);
144 showInputForm($session, false);
148 if (!isset($attachments)) {
149 $attachments = array();
150 session_register('attachments');
153 if (!isset($composesession)) {
155 session_register('composesession');
158 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
159 $session = "$composesession" +
1;
160 $composesession = $session;
163 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
168 include_once ('../src/draft_actions.php');
169 if (! isset($passed_id)) {
175 if (! isset($mailprio)) {
178 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
179 showInputForm($session);
182 $draft_message = _("Draft Email Saved");
183 /* If this is a resumed draft, then delete the original */
184 if(isset($delete_draft)) {
185 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
186 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
190 if ($compose_new_win == '1') {
191 Header("Location: compose.php?saved_draft=yes&session=$composesession");
195 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
196 "&startMessage=1¬e=".urlencode($draft_message));
204 if (isset($HTTP_POST_FILES['attachfile']) &&
205 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
206 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
207 $AttachFailure = saveAttachedFiles($session);
209 if (checkInput(false) && !isset($AttachFailure)) {
210 $urlMailbox = urlencode (trim($mailbox));
211 if (! isset($passed_id)) {
215 * Set $default_charset to correspond with the user's selection
216 * of language interface.
221 * This is to change all newlines to \n
222 * We'll change them to \r\n later (in the sendMessage function)
224 $body = str_replace("\r\n", "\n", $body);
225 $body = str_replace("\r", "\n", $body);
228 * Rewrap $body so that no line is bigger than $editor_size
229 * This should only really kick in the sqWordWrap function
230 * if the browser doesn't support "VIRTUAL" as the wrap type.
232 $body = explode("\n", $body);
234 foreach ($body as $line) {
235 if( $line <> '-- ' ) {
236 $line = rtrim($line);
238 if (strlen($line) <= $editor_size +
1) {
239 $newBody .= $line . "\n";
241 sqWordWrap($line, $editor_size);
242 $newBody .= $line . "\n";
247 do_hook('compose_send');
249 $MDN = False; // we are not sending a mdn response
250 if (! isset($mailprio)) {
251 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
252 $subject, $body, $passed_id, $MDN, '', $session);
254 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
255 $subject, $body, $passed_id, $MDN, $mailprio, $session);
258 showInputForm($session);
261 if ( isset($delete_draft)) {
262 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
263 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
266 if ($compose_new_win == '1') {
267 Header("Location: compose.php?mail_sent=yes");
270 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
275 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
278 if ($compose_new_win == '1') {
279 compose_Header($color, $mailbox);
282 displayPageHeader($color, $mailbox);
284 if (isset($AttachFailure)) {
285 plain_error_message(_("Could not move/copy file. File not attached"),
289 showInputForm($session);
290 /* sqimap_logout($imapConnection); */
292 } elseif (isset($html_addr_search_done)) {
293 if ($compose_new_win == '1') {
294 compose_Header($color, $mailbox);
297 displayPageHeader($color, $mailbox);
300 if (isset($send_to_search) && is_array($send_to_search)) {
301 foreach ($send_to_search as $k => $v) {
302 if (substr($k, 0, 1) == 'T') {
308 elseif (substr($k, 0, 1) == 'C') {
314 elseif (substr($k, 0, 1) == 'B') {
316 $send_to_bcc .= ', ';
322 showInputForm($session);
323 } elseif (isset($html_addr_search)) {
324 if (isset($HTTP_POST_FILES['attachfile']) &&
325 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
326 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
327 if (saveAttachedFiles($session)) {
328 plain_error_message(_("Could not move/copy file. File not attached"), $color);
332 * I am using an include so as to elminiate an extra unnecessary
333 * click. If you can think of a better way, please implement it.
335 include_once('./addrbook_search_html.php');
336 } elseif (isset($attach)) {
337 if (saveAttachedFiles($session)) {
338 plain_error_message(_("Could not move/copy file. File not attached"), $color);
340 if ($compose_new_win == '1') {
341 compose_Header($color, $mailbox);
344 displayPageHeader($color, $mailbox);
346 showInputForm($session);
348 elseif (isset($sigappend)) {
349 $idents = getPref($data_dir, $username, 'identities', 0);
351 if ($identity == 'default') {
356 $signature = getSig($data_dir, $username, $no);
358 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
359 if ($compose_new_win == '1') {
360 compose_Header($color, $mailbox);
362 displayPageHeader($color, $mailbox);
364 showInputForm($session);
365 } elseif (isset($do_delete)) {
366 if ($compose_new_win == '1') {
367 compose_Header($color, $mailbox);
370 displayPageHeader($color, $mailbox);
373 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
374 if (isset($delete) && is_array($delete)) {
375 foreach($delete as $index) {
376 $attached_file = $hashed_attachment_dir . '/'
377 . $attachments[$index]['localfilename'];
378 unlink ($attached_file);
379 unset ($attachments[$index]);
381 setPref($data_dir, $username, 'attachments', serialize($attachments));
384 showInputForm($session);
387 * This handles the default case as well as the error case
388 * (they had the same code) --> if (isset($smtpErrors))
391 if ($compose_new_win == '1') {
392 compose_Header($color, $mailbox);
394 displayPageHeader($color, $mailbox);
399 if (!isset($passed_ent_id)) $passed_ent_id = '';
400 if (!isset($passed_id)) $passed_id = '';
401 if (!isset($mailbox)) $mailbox = '';
402 if (!isset($action)) $action = '';
404 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
406 /* in case the origin is not read_body.php */
407 if (isset($send_to)) {
408 $values['send_to'] = $send_to;
410 if (isset($send_to_cc)) {
411 $values['send_to_cc'] = $send_to_cc;
413 if (isset($send_to_bcc)) {
414 $values['send_to_bcc'] = $send_to_bcc;
416 showInputForm($session, $values);
421 /**************** Only function definitions go below *************/
424 /* This function is used when not sending or adding attachments */
425 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
426 global $editor_size, $default_use_priority,
427 $use_signature, $composesession, $data_dir, $username,
428 $username, $key, $imapServerAddress, $imapPort;
430 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
434 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
437 sqimap_mailbox_select($imapConnection, $mailbox);
438 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
440 if ($passed_ent_id) {
441 /* redefine the messsage in case of message/rfc822 */
442 $message = $message->getEntity($passed_ent_id);
443 /* message is an entity which contains the envelope and type0=message
444 * and type1=rfc822. The actual entities are childs from
445 * $message->entities[0]. That's where the encoding and is located
448 $entities = $message->entities
[0]->findDisplayEntity
449 (array(), $alt_order = array('text/plain'));
450 if (!count($entities)) {
451 $entities = $message->entities
[0]->findDisplayEntity
452 (array(), $alt_order = array('text/plain','html/plain'));
454 $orig_header = $message->rfc822_header
; /* here is the envelope located */
455 /* redefine the message for picking up the attachments */
456 $message = $message->entities
[0];
459 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
460 if (!count($entities)) {
461 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
463 $orig_header = $message->rfc822_header
;
465 $encoding = $message->header
->encoding
;
466 $type0 = $message->type0
;
467 $type1 = $message->type1
;
468 foreach ($entities as $ent) {
469 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
470 $body_part_entity = $message->getEntity($ent);
471 $bodypart = decodeBody($unencoded_bodypart,
472 $body_part_entity->header
->encoding
);
473 if ($type1 == 'html') {
474 $bodypart = strip_tags($bodypart);
478 if ($default_use_priority) {
479 $mailprio = substr($orig_header->priority
,0,1);
486 ClearAttachments($session);
489 $idents = getPref($data_dir, $username, 'identities');
490 $from_o = $orig_header->from
;
491 if (is_object($from_o)) {
492 $orig_from = $from_o->getAddress();
496 if (!empty($idents) && $idents > 1) {
497 for ($i = 1; $i < $idents; $i++
) {
498 $enc_from_name = '"'.
502 '" <' . getPref($data_dir, $username,
503 'email_address' . $i) . '>';
504 if ($enc_from_name == $orig_from) {
513 $use_signature = FALSE;
514 $send_to = $orig_header->getAddr_s('to');
515 $send_to_cc = $orig_header->getAddr_s('cc');
516 $send_to_bcc = $orig_header->getAddr_s('bcc');
517 $subject = $orig_header->subject
;
519 $body_ary = explode("\n", $body);
520 $cnt = count($body_ary) ;
522 for ($i=0; $i < $cnt; $i++
) {
523 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
524 sqWordWrap($body_ary[$i], $editor_size );
525 $body .= $body_ary[$i] . "\n";
527 unset($body_ary[$i]);
530 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
532 case ('edit_as_new'):
533 $send_to = $orig_header->getAddr_s('to');
534 $send_to_cc = $orig_header->getAddr_s('cc');
535 $send_to_bcc = $orig_header->getAddr_s('bcc');
536 $subject = $orig_header->subject
;
537 $mailprio = $orig_header->priority
;
539 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
544 $subject = $orig_header->subject
;
545 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
546 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
547 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
548 $subject = '[Fwd: ' . $subject . ']';
550 $body = getforwardHeader($orig_header) . $body;
552 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
555 $send_to_cc = replyAllString($orig_header);
557 $send_to = $orig_header->reply_to
;
558 if (is_object($send_to)) {
559 $send_to = $send_to->getAddr_s('reply_to');
561 $send_to = $orig_header->getAddr_s('from');
563 $subject = $orig_header->subject
;
564 $subject = str_replace('"', "'", $subject);
565 $subject = trim($subject);
566 if (substr(strtolower($subject), 0, 3) != 're:') {
567 $subject = 'Re: ' . $subject;
569 /* this corrects some wrapping/quoting problems on replies */
570 $rewrap_body = explode("\n", $body);
571 $body = getReplyCitation($orig_header->from
->personal
);
572 $cnt = count($rewrap_body);
573 for ($i=0;$i<$cnt;$i++
) {
574 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
575 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
577 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
579 $body .= '> ' . $rewrap_body[$i] . "\n";
581 unset($rewrap_body[$i]);
587 sqimap_logout($imapConnection);
590 'send_to' => $send_to,
591 'send_to_cc' => $send_to_cc,
592 'send_to_bcc' => $send_to_bcc,
593 'subject' => $subject,
594 'mailprio' => $mailprio,
596 'identity' => $identity
600 } /* function newMail() */
603 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
604 global $attachments, $attachment_dir, $username, $data_dir;
606 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
607 if (!count($message->entities
) ||
608 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
609 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
610 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
611 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
612 if ($filename == "") {
613 $filename = "untitled-".$message->entity_id
.'.eml';
616 $filename = decodeHeader($message->header
->getParameter('filename'));
617 if ($filename == '') {
618 $name = decodeHeader($message->header
->getParameter('name'));
620 $filename = "untitled-".$message->entity_id
;
626 $localfilename = GenerateRandomString(32, '', 7);
627 $full_localfilename = "$hashed_attachment_dir/$localfilename";
628 while (file_exists($full_localfilename)) {
629 $localfilename = GenerateRandomString(32, '', 7);
630 $full_localfilename = "$hashed_attachment_dir/$localfilename";
633 $newAttachment = array();
634 $newAttachment['localfilename'] = $localfilename;
635 $newAttachment['remotefilename'] = $filename;
636 $newAttachment['type'] = strtolower($message->type0
.
637 '/' . $message->type1
);
638 $newAttachment['id'] = strtolower($message->header
->id
);
639 $newAttachment['session'] = $session;
641 /* Write Attachment to file */
642 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
643 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
644 $passed_id, $message->entity_id
),
645 $message->header
->encoding
));
648 $attachments[] = $newAttachment;
649 setPref($data_dir, $username, 'attachments', $attachments);
652 for ($i = 0; $i < count($message->entities
); $i++
) {
653 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
659 function showInputForm ($session, $values=false) {
660 global $send_to, $send_to_cc, $body,
661 $passed_body, $color, $use_signature, $signature, $prefix_sig,
662 $editor_size, $attachments, $subject, $newmail,
663 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
664 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
665 $username, $data_dir, $identity, $draft_id, $delete_draft,
666 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
667 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
670 $subject = decodeHeader($subject, false);
672 $send_to = $values['send_to'];
673 $send_to_cc = $values['send_to_cc'];
674 $send_to_bcc = $values['send_to_bcc'];
675 $subject = $values['subject'];
676 $mailprio = $values['mailprio'];
677 $body = $values['body'];
678 $identity = $values['identity'];
681 if ($use_javascript_addr_book) {
682 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
683 'function open_abook() { ' . "\n" .
684 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
685 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
686 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
687 ' nwin.opener = document.windows;' . "\n" .
689 '// --></SCRIPT>' . "\n\n";
692 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
693 'ENCTYPE="multipart/form-data"';
694 do_hook("compose_form");
699 if ($action == 'draft') {
700 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
702 if (isset($delete_draft)) {
703 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
705 if (isset($session)) {
706 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
710 if ($saved_draft == 'yes') {
711 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
713 if ($mail_sent == 'yes') {
714 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
716 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
717 if ($compose_new_win == '1') {
718 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
719 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
721 if ($location_of_buttons == 'top') {
722 showComposeButtonRow();
725 $idents = getPref($data_dir, $username, 'identities', 0);
727 echo ' <TR>' . "\n" .
728 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
731 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
732 '<select name=identity>' . "\n" .
733 '<option value=default>' .
734 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
735 $em = getPref($data_dir, $username, 'email_address');
737 echo htmlspecialchars(' <' . $em . '>') . "\n";
739 for ($i = 1; $i < $idents; $i ++
) {
740 echo '<option value="' . $i . '"';
741 if (isset($identity) && $identity == $i) {
744 echo '>' . htmlspecialchars(getPref($data_dir, $username,
746 $em = getPref($data_dir, $username, 'email_address' . $i);
748 echo htmlspecialchars(' <' . $em . '>') . "\n";
752 echo '</select>' . "\n" .
756 echo ' <TR>' . "\n" .
757 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
759 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
760 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
761 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
765 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
767 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
768 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
769 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
773 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
775 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
776 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
777 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
778 '</TD></TR>' . "\n" .
780 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
782 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
783 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
784 htmlspecialchars($subject) . '">';
785 echo '</td></tr>' . "\n\n";
787 if ($location_of_buttons == 'between') {
788 showComposeButtonRow();
790 if ($compose_new_win == '1') {
791 echo ' <TR>' . "\n" .
792 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
793 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
794 $editor_size . '" WRAP="VIRTUAL">';
797 echo ' <TR>' . "\n" .
798 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
799 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
800 $editor_size . '" WRAP="VIRTUAL">';
802 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
803 if ($sig_first == '1') {
804 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
805 echo "\n\n".htmlspecialchars($body);
808 echo "\n\n".htmlspecialchars($body);
809 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
813 echo htmlspecialchars($body);
815 echo '</TEXTAREA><BR>' . "\n" .
819 if ($location_of_buttons == 'bottom') {
820 showComposeButtonRow();
822 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
823 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
826 /* This code is for attachments */
827 echo ' <TR>' . "\n" .
828 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
831 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
832 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
833 ' <input type="submit" name="attach"' .
834 ' value="' . _("Add") .'">' . "\n" .
838 if (count($attachments)) {
839 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
840 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
842 '</td><td align=left bgcolor="' . $color[0] . '">';
843 foreach ($attachments as $key => $info) {
844 if ($info['session'] == $session) {
845 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
846 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
847 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
848 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
852 echo '<input type="submit" name="do_delete" value="' .
853 _("Delete selected attachments") . "\">\n" .
856 /* End of attachment code */
857 if ($compose_new_win == '1') {
858 echo '</TABLE>'."\n";
860 echo '</TABLE>' . "\n";
862 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
863 echo '<input type=hidden name=action value=' . $action . ">\n";
864 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
867 do_hook('compose_bottom');
868 echo '</BODY></HTML>' . "\n";
872 function showComposeButtonRow() {
873 global $use_javascript_addr_book, $save_as_draft,
874 $default_use_priority, $mailprio, $default_use_mdn,
875 $request_mdn, $request_dr,
876 $data_dir, $username;
878 echo " <TR><TD>\n</TD><TD>\n";
879 if ($default_use_priority) {
880 if(!isset($mailprio)) {
883 echo _("Priority") .': <select name="mailprio">'.
884 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
885 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
886 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
889 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
890 if ($default_use_mdn) {
891 if ($mdn_user_support) {
892 echo "\n\t". _("Receipt") .': '.
893 '<input type="checkbox" name="request_mdn" value=1'.
894 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
895 ' <input type="checkbox" name="request_dr" value=1'.
896 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
900 echo " </td></tr>\n <TR><td>\n </td><td>\n";
901 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
902 if ($use_javascript_addr_book) {
903 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
904 " <input type=button value=\\\""._("Addresses").
905 "\\\" onclick='javascript:open_abook();'>\");".
906 " // --></SCRIPT><NOSCRIPT>\n".
907 " <input type=submit name=\"html_addr_search\" value=\"".
908 _("Addresses")."\">".
911 echo " <input type=submit name=\"html_addr_search\" value=\"".
912 _("Addresses")."\">";
914 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
916 if ($save_as_draft) {
917 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
920 do_hook('compose_button_row');
922 echo " </TD></TR>\n\n";
925 function checkInput ($show) {
927 * I implemented the $show variable because the error messages
928 * were getting sent before the page header. So, I check once
929 * using $show=false, and then when i'm ready to display the error
932 global $body, $send_to, $subject, $color;
934 if ($send_to == "") {
936 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
941 } /* function checkInput() */
944 /* True if FAILURE */
945 function saveAttachedFiles($session) {
946 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
949 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
950 $localfilename = GenerateRandomString(32, '', 7);
951 $full_localfilename = "$hashed_attachment_dir/$localfilename";
952 while (file_exists($full_localfilename)) {
953 $localfilename = GenerateRandomString(32, '', 7);
954 $full_localfilename = "$hashed_attachment_dir/$localfilename";
957 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
958 if (function_exists("move_uploaded_file")) {
959 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
963 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
969 $newAttachment['localfilename'] = $localfilename;
970 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
971 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
972 $newAttachment['session'] = $session;
974 if ($newAttachment['type'] == "") {
975 $newAttachment['type'] = 'application/octet-stream';
977 $attachments[] = $newAttachment;
978 setPref($data_dir, $username, 'attachments', serialize($attachments));
982 function ClearAttachments($session)
984 global $username, $attachments, $attachment_dir, $data_dir;
985 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
987 $rem_attachments = array();
988 if (is_array($attachments)) {
989 foreach ($attachments as $info) {
990 if ($info['session'] == $session) {
991 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
992 if (file_exists($attached_file)) {
993 unlink($attached_file);
997 $rem_attachments[] = $info;
1001 $attachments = $rem_attachments;
1002 setPref($data_dir, $username, 'attachments', serialize($attachments));
1006 function getReplyCitation($orig_from)
1008 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1010 /* First, return an empty string when no citation style selected. */
1011 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1015 /* Make sure our final value isn't an empty string. */
1016 if ($orig_from == '') {
1020 /* Otherwise, try to select the desired citation style. */
1021 switch ($reply_citation_style) {
1024 $end = ' ' . _("said") . ':';
1027 $start = '<' . _("quote") . ' ' . _("who") . '="';
1030 case 'user-defined':
1031 $start = $reply_citation_start .
1032 ($reply_citation_start == '' ?
'' : ' ');
1033 $end = $reply_citation_end;
1039 /* Build and return the citation string. */
1040 return ($start . $orig_from . $end . "\n");