d130c06f2d568bd6b2b8f05589f4eecc12863550
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');
28 /* --------------------- Specific Functions ------------------------------ */
30 function replyAllString($header) {
31 global $include_self_reply_all, $username, $data_dir;
34 * 1) Remove the addresses we'll be sending the message 'to'
36 $url_replytoall_avoid_addrs = '';
37 if (isset($header->replyto
)) {
38 $excl_ar = $header->getAddr_a('replyto');
41 * 2) Remove our identities from the CC list (they still can be in the
42 * TO list) only if $include_self_reply_all is turned off
44 if (!$include_self_reply_all) {
45 $email_address = trim(getPref($data_dir, $username, 'email_address'));
46 $excl_ar[$email_address] = '';
48 $idents = getPref($data_dir, $username, 'identities');
49 if ($idents != '' && $idents > 1) {
50 for ($i = 1; $i < $idents; $i ++
) {
51 $cur_email_address = getPref($data_dir, $username,
52 'email_address' . $i);
53 $cur_email_address = strtolower($cur_email_address);
54 $excl_ar[$cur_email_address] = '';
60 * 3) get the addresses.
62 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
65 * 4) generate the string.
67 $url_replytoallcc = '';
68 foreach( $url_replytoall_ar as $email => $personal) {
70 $url_replytoallcc .= ", \"$personal\" <$email>";
72 $url_replytoallcc .= ', '. $email;
75 $url_replytoallcc = substr($url_replytoallcc,2);
76 return $url_replytoallcc;
79 function getforwardHeader($orig_header) {
82 $display = array( _("Subject") => strlen(_("Subject")),
83 _("From") => strlen(_("From")),
84 _("Date") => strlen(_("Date")),
85 _("To") => strlen(_("To")),
86 _("Cc") => strlen(_("Cc")) );
87 $maxsize = max($display);
88 $indent = str_pad('',$maxsize+
2);
89 foreach($display as $key => $val) {
90 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
92 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH
) .
93 "\n". $display[_("Subject")] .
94 decodeHeader($orig_header->subject
) . "\n" .
96 decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
98 getLongDateString( $orig_header->date
). "\n" .
100 decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
101 if ($orig_header->cc
!= array() && $orig_header->cc
!='') {
102 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
104 $bodyTop .= str_pad('', $editor_size -2 , '-') .
108 /* ----------------------------------------------------------------------- */
111 * If the session is expired during a post this restores the compose session
114 //$session_expired = false;
115 if (session_is_registered('session_expired_post')) {
116 global $session_expired_post, $session_expired;
118 * extra check for username so we don't display previous post data from
119 * another user during this session.
121 if ($session_expired_post['username'] != $username) {
122 session_unregister('session_expired_post');
123 session_unregister('session_expired');
125 foreach ($session_expired_post as $postvar => $val) {
135 $session_expired = true;
137 session_unregister('session_expired_post');
138 session_unregister('session_expired');
139 if (!isset($mailbox)) {
142 if ($compose_new_win == '1') {
143 compose_Header($color, $mailbox);
145 displayPageHeader($color, $mailbox);
147 showInputForm($session, false);
151 if (!isset($attachments)) {
152 $attachments = array();
153 session_register('attachments');
156 if (!isset($composesession)) {
158 session_register('composesession');
161 if (!isset($session) ||
(isset($newmessage) && $newmessage)) {
162 $session = "$composesession" +
1;
163 $composesession = $session;
164 session_register('composesession');
167 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
172 include_once ('../src/draft_actions.php');
173 if (! isset($passed_id)) {
179 if (! isset($mailprio)) {
182 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
183 showInputForm($session);
186 $draft_message = _("Draft Email Saved");
187 /* If this is a resumed draft, then delete the original */
188 if(isset($delete_draft)) {
189 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
190 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
194 if ($compose_new_win == '1') {
195 Header("Location: compose.php?saved_draft=yes&session=$composesession");
199 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
200 "&startMessage=1¬e=".urlencode($draft_message));
208 if (isset($HTTP_POST_FILES['attachfile']) &&
209 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
210 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
211 $AttachFailure = saveAttachedFiles($session);
213 if (checkInput(false) && !isset($AttachFailure)) {
214 $urlMailbox = urlencode (trim($mailbox));
215 if (! isset($passed_id)) {
219 * Set $default_charset to correspond with the user's selection
220 * of language interface.
225 * This is to change all newlines to \n
226 * We'll change them to \r\n later (in the sendMessage function)
228 $body = str_replace("\r\n", "\n", $body);
229 $body = str_replace("\r", "\n", $body);
232 * Rewrap $body so that no line is bigger than $editor_size
233 * This should only really kick in the sqWordWrap function
234 * if the browser doesn't support "VIRTUAL" as the wrap type.
236 $body = explode("\n", $body);
238 foreach ($body as $line) {
239 if( $line <> '-- ' ) {
240 $line = rtrim($line);
242 if (strlen($line) <= $editor_size +
1) {
243 $newBody .= $line . "\n";
245 sqWordWrap($line, $editor_size);
246 $newBody .= $line . "\n";
251 do_hook('compose_send');
253 $MDN = False; // we are not sending a mdn response
254 if (! isset($mailprio)) {
255 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
256 $subject, $body, $passed_id, $MDN, '', $session);
258 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
259 $subject, $body, $passed_id, $MDN, $mailprio, $session);
262 showInputForm($session);
265 if ( isset($delete_draft)) {
266 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
267 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
270 if ($compose_new_win == '1') {
271 Header("Location: compose.php?mail_sent=yes");
274 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
279 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
282 if ($compose_new_win == '1') {
283 compose_Header($color, $mailbox);
286 displayPageHeader($color, $mailbox);
288 if (isset($AttachFailure)) {
289 plain_error_message(_("Could not move/copy file. File not attached"),
293 showInputForm($session);
294 /* sqimap_logout($imapConnection); */
296 } elseif (isset($html_addr_search_done)) {
297 if ($compose_new_win == '1') {
298 compose_Header($color, $mailbox);
301 displayPageHeader($color, $mailbox);
304 if (isset($send_to_search) && is_array($send_to_search)) {
305 foreach ($send_to_search as $k => $v) {
306 if (substr($k, 0, 1) == 'T') {
312 elseif (substr($k, 0, 1) == 'C') {
318 elseif (substr($k, 0, 1) == 'B') {
320 $send_to_bcc .= ', ';
326 showInputForm($session);
327 } elseif (isset($html_addr_search)) {
328 if (isset($HTTP_POST_FILES['attachfile']) &&
329 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
330 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
331 if (saveAttachedFiles($session)) {
332 plain_error_message(_("Could not move/copy file. File not attached"), $color);
336 * I am using an include so as to elminiate an extra unnecessary
337 * click. If you can think of a better way, please implement it.
339 include_once('./addrbook_search_html.php');
340 } elseif (isset($attach)) {
341 if (saveAttachedFiles($session)) {
342 plain_error_message(_("Could not move/copy file. File not attached"), $color);
344 if ($compose_new_win == '1') {
345 compose_Header($color, $mailbox);
348 displayPageHeader($color, $mailbox);
350 showInputForm($session);
352 elseif (isset($sigappend)) {
353 $idents = getPref($data_dir, $username, 'identities', 0);
355 if ($identity == 'default') {
360 $signature = getSig($data_dir, $username, $no);
362 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
363 if ($compose_new_win == '1') {
364 compose_Header($color, $mailbox);
366 displayPageHeader($color, $mailbox);
368 showInputForm($session);
369 } elseif (isset($do_delete)) {
370 if ($compose_new_win == '1') {
371 compose_Header($color, $mailbox);
374 displayPageHeader($color, $mailbox);
377 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
378 if (isset($delete) && is_array($delete)) {
379 foreach($delete as $index) {
380 $attached_file = $hashed_attachment_dir . '/'
381 . $attachments[$index]['localfilename'];
382 unlink ($attached_file);
383 unset ($attachments[$index]);
385 setPref($data_dir, $username, 'attachments', serialize($attachments));
388 showInputForm($session);
391 * This handles the default case as well as the error case
392 * (they had the same code) --> if (isset($smtpErrors))
395 if ($compose_new_win == '1') {
396 compose_Header($color, $mailbox);
398 displayPageHeader($color, $mailbox);
403 if (!isset($passed_ent_id)) {
406 if (!isset($passed_id)) {
409 if (!isset($mailbox)) {
412 if (!isset($action)) {
416 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
418 /* in case the origin is not read_body.php */
419 if (isset($send_to)) {
420 $values['send_to'] = $send_to;
422 if (isset($send_to_cc)) {
423 $values['send_to_cc'] = $send_to_cc;
425 if (isset($send_to_bcc)) {
426 $values['send_to_bcc'] = $send_to_bcc;
428 showInputForm($session, $values);
433 /**************** Only function definitions go below *************/
436 /* This function is used when not sending or adding attachments */
437 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
438 global $editor_size, $default_use_priority, $body,
439 $use_signature, $composesession, $data_dir, $username,
440 $username, $key, $imapServerAddress, $imapPort;
442 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
446 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
449 sqimap_mailbox_select($imapConnection, $mailbox);
450 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
452 if ($passed_ent_id) {
453 /* redefine the messsage in case of message/rfc822 */
454 $message = $message->getEntity($passed_ent_id);
455 /* message is an entity which contains the envelope and type0=message
456 * and type1=rfc822. The actual entities are childs from
457 * $message->entities[0]. That's where the encoding and is located
460 $entities = $message->entities
[0]->findDisplayEntity
461 (array(), $alt_order = array('text/plain'));
462 if (!count($entities)) {
463 $entities = $message->entities
[0]->findDisplayEntity
464 (array(), $alt_order = array('text/plain','html/plain'));
466 $orig_header = $message->rfc822_header
; /* here is the envelope located */
467 /* redefine the message for picking up the attachments */
468 $message = $message->entities
[0];
471 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
472 if (!count($entities)) {
473 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
475 $orig_header = $message->rfc822_header
;
477 $encoding = $message->header
->encoding
;
478 $type0 = $message->type0
;
479 $type1 = $message->type1
;
480 foreach ($entities as $ent) {
481 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
482 $body_part_entity = $message->getEntity($ent);
483 $bodypart = decodeBody($unencoded_bodypart,
484 $body_part_entity->header
->encoding
);
485 if ($type1 == 'html') {
486 $bodypart = strip_tags($bodypart);
490 if ($default_use_priority) {
491 $mailprio = substr($orig_header->priority
,0,1);
498 ClearAttachments($session);
501 $idents = getPref($data_dir, $username, 'identities');
502 $from_o = $orig_header->from
;
503 if (is_object($from_o)) {
504 $orig_from = $from_o->getAddress();
508 if (!empty($idents) && $idents > 1) {
509 for ($i = 1; $i < $idents; $i++
) {
510 $enc_from_name = '"'.
514 '" <' . getPref($data_dir, $username,
515 'email_address' . $i) . '>';
516 if ($enc_from_name == $orig_from) {
525 $use_signature = FALSE;
526 $send_to = $orig_header->getAddr_s('to');
527 $send_to_cc = $orig_header->getAddr_s('cc');
528 $send_to_bcc = $orig_header->getAddr_s('bcc');
529 $subject = decodeHeader($orig_header->subject
);
531 $body_ary = explode("\n", $body);
532 $cnt = count($body_ary) ;
534 for ($i=0; $i < $cnt; $i++
) {
535 if (!ereg("^[>\\s]*$", $body_ary[$i]) ||
!$body_ary[$i]) {
536 sqWordWrap($body_ary[$i], $editor_size );
537 $body .= $body_ary[$i] . "\n";
539 unset($body_ary[$i]);
542 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
544 case ('edit_as_new'):
545 $send_to = $orig_header->getAddr_s('to');
546 $send_to_cc = $orig_header->getAddr_s('cc');
547 $send_to_bcc = $orig_header->getAddr_s('bcc');
548 $subject = decodeHeader($orig_header->subject
);
549 $mailprio = $orig_header->priority
;
551 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
556 $subject = decodeHeader($orig_header->subject
);
557 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
558 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
559 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
560 $subject = '[Fwd: ' . $subject . ']';
562 $body = getforwardHeader($orig_header) . $body;
564 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
566 case ('forward_as_attachment'):
567 getMessage_RFC822_Attachment($message, $session, $passed_id, $passed_ent_id, $imapConnection);
571 $send_to_cc = replyAllString($orig_header);
573 $send_to = $orig_header->reply_to
;
574 if (is_object($send_to)) {
575 $send_to = $send_to->getAddr_s('reply_to');
577 $send_to = $orig_header->getAddr_s('from');
579 $subject = decodeHeader($orig_header->subject
);
580 $subject = str_replace('"', "'", $subject);
581 $subject = trim($subject);
582 if (substr(strtolower($subject), 0, 3) != 're:') {
583 $subject = 'Re: ' . $subject;
585 /* this corrects some wrapping/quoting problems on replies */
586 $rewrap_body = explode("\n", $body);
588 $body = getReplyCitation($orig_header->from
->personal
);
589 $cnt = count($rewrap_body);
590 for ($i=0;$i<$cnt;$i++
) {
591 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
592 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
594 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
596 $body .= '> ' . $rewrap_body[$i] . "\n";
598 unset($rewrap_body[$i]);
604 sqimap_logout($imapConnection);
606 $ret = array( 'send_to' => $send_to,
607 'send_to_cc' => $send_to_cc,
608 'send_to_bcc' => $send_to_bcc,
609 'subject' => $subject,
610 'mailprio' => $mailprio,
612 'identity' => $identity );
615 } /* function newMail() */
617 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
618 global $attachments, $attachment_dir, $username, $data_dir;
620 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
621 if (!count($message->entities
) ||
622 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
623 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
624 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
625 $filename = decodeHeader($message->rfc822_header
->subject
.'.eml');
626 if ($filename == "") {
627 $filename = "untitled-".$message->entity_id
.'.eml';
630 $filename = decodeHeader($message->getFilename());
632 $localfilename = GenerateRandomString(32, '', 7);
633 $full_localfilename = "$hashed_attachment_dir/$localfilename";
634 while (file_exists($full_localfilename)) {
635 $localfilename = GenerateRandomString(32, '', 7);
636 $full_localfilename = "$hashed_attachment_dir/$localfilename";
639 $newAttachment = array();
640 $newAttachment['localfilename'] = $localfilename;
641 $newAttachment['remotefilename'] = $filename;
642 $newAttachment['type'] = strtolower($message->type0
.
643 '/' . $message->type1
);
644 $newAttachment['id'] = strtolower($message->header
->id
);
645 $newAttachment['session'] = $session;
647 /* Write Attachment to file */
648 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
649 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
650 $passed_id, $message->entity_id
),
651 $message->header
->encoding
));
653 $attachments[] = $newAttachment;
656 for ($i = 0; $i < count($message->entities
); $i++
) {
657 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
660 setPref($data_dir, $username, 'attachments', serialize($attachments));
664 function getMessage_RFC822_Attachment($message, $session, $passed_id,
665 $passed_ent_id='', $imapConnection) {
666 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
667 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
668 if (!$passed_ent_id) {
669 $body_a = sqimap_run_command($imapConnection,
670 'FETCH '.$passed_id.' RFC822',
671 TRUE, $response, $readmessage,
674 $body_a = sqimap_run_command($imapConnection,
675 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
676 TRUE, $response, $readmessage, $uid_support);
677 $message = $message->parent
;
679 if ($response = 'OK') {
680 $subject = encodeHeader($message->rfc822_header
->subject
);
681 array_shift($body_a);
682 $body = implode('', $body_a) . "\r\n";
684 $localfilename = GenerateRandomString(32, 'FILE', 7);
685 $full_localfilename = "$hashed_attachment_dir/$localfilename";
687 $fp = fopen( $full_localfilename, 'wb');
690 $newAttachment = array();
691 $newAttachment['localfilename'] = $localfilename;
692 $newAttachment['type'] = "message/rfc822";
693 $newAttachment['remotefilename'] = $subject.'.eml';
694 $newAttachment['session'] = $session;
695 $attachments[] = $newAttachment;
697 setPref($data_dir, $username, 'attachments', serialize($attachments));
701 function showInputForm ($session, $values=false) {
702 global $send_to, $send_to_cc, $body,
703 $passed_body, $color, $use_signature, $signature, $prefix_sig,
704 $editor_size, $attachments, $subject, $newmail,
705 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
706 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
707 $username, $data_dir, $identity, $draft_id, $delete_draft,
708 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
709 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
712 $subject = decodeHeader($subject, false);
714 $send_to = $values['send_to'];
715 $send_to_cc = $values['send_to_cc'];
716 $send_to_bcc = $values['send_to_bcc'];
717 $subject = $values['subject'];
718 $mailprio = $values['mailprio'];
719 $body = $values['body'];
720 $identity = $values['identity'];
723 if ($use_javascript_addr_book) {
724 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
725 'function open_abook() { ' . "\n" .
726 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
727 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
728 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
729 ' nwin.opener = document.windows;' . "\n" .
731 '// --></SCRIPT>' . "\n\n";
734 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
735 'ENCTYPE="multipart/form-data"';
736 do_hook("compose_form");
741 if ($action == 'draft') {
742 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
744 if (isset($delete_draft)) {
745 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
747 if (isset($session)) {
748 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
751 if (isset($passed_id)) {
752 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
755 if ($saved_draft == 'yes') {
756 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
758 if ($mail_sent == 'yes') {
759 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
761 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
762 if ($compose_new_win == '1') {
763 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
764 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
766 if ($location_of_buttons == 'top') {
767 showComposeButtonRow();
770 $idents = getPref($data_dir, $username, 'identities', 0);
772 echo ' <TR>' . "\n" .
773 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
776 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
777 '<select name=identity>' . "\n" .
778 '<option value=default>' .
779 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
780 $em = getPref($data_dir, $username, 'email_address');
782 echo htmlspecialchars(' <' . $em . '>') . "\n";
784 for ($i = 1; $i < $idents; $i ++
) {
785 echo '<option value="' . $i . '"';
786 if (isset($identity) && $identity == $i) {
789 echo '>' . htmlspecialchars(getPref($data_dir, $username,
791 $em = getPref($data_dir, $username, 'email_address' . $i);
793 echo htmlspecialchars(' <' . $em . '>') . "\n";
797 echo '</select>' . "\n" .
801 echo ' <TR>' . "\n" .
802 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
804 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
805 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
806 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
810 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
812 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
813 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
814 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
818 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
820 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
821 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
822 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
823 '</TD></TR>' . "\n" .
825 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
827 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
828 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
829 htmlspecialchars($subject) . '">';
830 echo '</td></tr>' . "\n\n";
832 if ($location_of_buttons == 'between') {
833 showComposeButtonRow();
835 if ($compose_new_win == '1') {
836 echo ' <TR>' . "\n" .
837 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
838 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
839 $editor_size . '" WRAP="VIRTUAL">';
842 echo ' <TR>' . "\n" .
843 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
844 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
845 $editor_size . '" WRAP="VIRTUAL">';
847 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
848 if ($sig_first == '1') {
849 if ($charset == 'iso-2022-jp') {
850 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
852 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
854 echo "\n\n".htmlspecialchars($body);
857 echo "\n\n".htmlspecialchars($body);
858 if ($charset == 'iso-2022-jp') {
859 echo "\n\n".($prefix_sig==true?
"-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
861 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
866 echo htmlspecialchars($body);
868 echo '</TEXTAREA><BR>' . "\n" .
872 if ($location_of_buttons == 'bottom') {
873 showComposeButtonRow();
875 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
876 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
877 ' <BR><BR>' .
878 ' </TD></TR>' . "\n";
881 /* This code is for attachments */
882 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
884 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
886 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
888 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
891 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
892 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
893 ' <input type="submit" name="attach"' .
894 ' value="' . _("Add") .'">' . "\n" .
900 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
901 foreach ($attachments as $key => $info) {
902 if ($info['session'] == $session) {
903 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
904 $s_a[] = '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
905 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
906 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
910 foreach ($s_a as $s) {
911 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
913 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
914 _("Delete selected attachments") . "\">\n" .
917 echo ' </table></td></tr>' .
921 /* End of attachment code */
922 if ($compose_new_win == '1') {
923 echo '</TABLE>'."\n";
925 echo '</TABLE>' . "\n" .
926 '<input type="hidden" name="username" value="'. $username . "\">\n" .
927 '<input type=hidden name=action value=' . $action . ">\n" .
928 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
931 do_hook('compose_bottom');
932 echo '</BODY></HTML>' . "\n";
936 function showComposeButtonRow() {
937 global $use_javascript_addr_book, $save_as_draft,
938 $default_use_priority, $mailprio, $default_use_mdn,
939 $request_mdn, $request_dr,
940 $data_dir, $username;
942 echo " <TR><TD>\n</TD><TD>\n";
943 if ($default_use_priority) {
944 if(!isset($mailprio)) {
947 echo _("Priority") .': <select name="mailprio">'.
948 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
949 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
950 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
953 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
954 if ($default_use_mdn) {
955 if ($mdn_user_support) {
956 echo "\n\t". _("Receipt") .': '.
957 '<input type="checkbox" name="request_mdn" value=1'.
958 ($request_mdn=='1'?
' checked':'') .'>'. _("On Read").
959 ' <input type="checkbox" name="request_dr" value=1'.
960 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
964 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
965 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
966 if ($use_javascript_addr_book) {
967 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
968 " <input type=button value=\\\""._("Addresses").
969 "\\\" onclick='javascript:open_abook();'>\");".
970 " // --></SCRIPT><NOSCRIPT>\n".
971 " <input type=submit name=\"html_addr_search\" value=\"".
972 _("Addresses")."\">".
975 echo " <input type=submit name=\"html_addr_search\" value=\"".
976 _("Addresses")."\">";
979 if ($save_as_draft) {
980 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
983 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
984 do_hook('compose_button_row');
986 echo " </TD></TR>\n\n";
989 function checkInput ($show) {
991 * I implemented the $show variable because the error messages
992 * were getting sent before the page header. So, I check once
993 * using $show=false, and then when i'm ready to display the error
996 global $body, $send_to, $send_to_bcc, $subject, $color;
998 if ($send_to == '' && $send_to_bcc == '') {
1000 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1005 } /* function checkInput() */
1008 /* True if FAILURE */
1009 function saveAttachedFiles($session) {
1010 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
1013 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1014 $localfilename = GenerateRandomString(32, '', 7);
1015 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1016 while (file_exists($full_localfilename)) {
1017 $localfilename = GenerateRandomString(32, '', 7);
1018 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1021 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1022 if (function_exists("move_uploaded_file")) {
1023 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1027 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1033 $newAttachment['localfilename'] = $localfilename;
1034 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
1035 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
1036 $newAttachment['session'] = $session;
1038 if ($newAttachment['type'] == "") {
1039 $newAttachment['type'] = 'application/octet-stream';
1041 $attachments[] = $newAttachment;
1042 setPref($data_dir, $username, 'attachments', serialize($attachments));
1045 function ClearAttachments($session)
1047 global $username, $attachments, $attachment_dir, $data_dir;
1048 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1050 $rem_attachments = array();
1051 if (is_array($attachments)) {
1052 foreach ($attachments as $info) {
1053 if ($info['session'] == $session) {
1054 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
1055 if (file_exists($attached_file)) {
1056 unlink($attached_file);
1060 $rem_attachments[] = $info;
1064 $attachments = $rem_attachments;
1065 setPref($data_dir, $username, 'attachments', serialize($attachments));
1069 function getReplyCitation($orig_from)
1071 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1073 /* First, return an empty string when no citation style selected. */
1074 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
1078 /* Make sure our final value isn't an empty string. */
1079 if ($orig_from == '') {
1083 /* Otherwise, try to select the desired citation style. */
1084 switch ($reply_citation_style) {
1087 $end = ' ' . _("said") . ':';
1090 $start = '<' . _("quote") . ' ' . _("who") . '="';
1093 case 'user-defined':
1094 $start = $reply_citation_start .
1095 ($reply_citation_start == '' ?
'' : ' ');
1096 $end = $reply_citation_end;
1102 /* Build and return the citation string. */
1103 return ($start . $orig_from . $end . "\n");