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 /* in case the origin is not read_body.php */
363 if (isset($send_to)) {
364 $values['send_to'] = $send_to;
366 if (isset($send_to_cc)) {
367 $values['send_to_cc'] = $send_cc;
369 if (isset($send_to_bcc)) {
370 $values['send_to_bcc'] = $send_bcc;
373 showInputForm($session, $values);
374 sqimap_logout($imapConnection);
378 * This handles the default case as well as the error case
379 * (they had the same code) --> if (isset($smtpErrors))
381 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
383 if ($compose_new_win == '1') {
384 compose_Header($color, $mailbox);
387 displayPageHeader($color, $mailbox);
392 if (!isset($passed_ent_id)) $passed_ent_id = '';
393 if (!isset($passed_id)) $passed_id = '';
394 if (!isset($mailbox)) $mailbox = '';
395 if (!isset($action)) $action = '';
397 $values = newMail($imapConnection,$mailbox,$passed_id,$passed_ent_id, $action, $session);
399 /* in case the origin is not read_body.php */
400 if (isset($send_to)) {
401 $values['send_to'] = $send_to;
403 if (isset($send_to_cc)) {
404 $values['send_to_cc'] = $send_cc;
406 if (isset($send_to_bcc)) {
407 $values['send_to_bcc'] = $send_bcc;
409 showInputForm($session, $values);
410 sqimap_logout($imapConnection);
415 /**************** Only function definitions go below *************/
418 /* This function is used when not sending or adding attachments */
419 function newMail ($imapConnection, $mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
420 global $editor_size, $default_use_priority,
421 $use_signature, $composesession, $data_dir, $username;
423 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
426 sqimap_mailbox_select($imapConnection, $mailbox);
427 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
429 if ($passed_ent_id) {
430 /* redefine the messsage in case of message/rfc822 */
431 $message = $message->getEntity($passed_ent_id);
432 /* message is an entity which contains the envelope and type0=message
433 * and type1=rfc822. The actual entities are childs from
434 * $message->entities[0]. That's where the encoding and is located
437 $entities = $message->entities
[0]->findDisplayEntity
438 (array(), $alt_order = array('text/plain'));
439 if (!count($entities)) {
440 $entities = $message->entities
[0]->findDisplayEntity
441 (array(), $alt_order = array('text/plain','html/plain'));
443 $orig_header = $message->header
; /* here is the envelope located */
444 /* redefine the message for picking up the attachments */
445 $message = $message->entities
[0];
448 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
449 if (!count($entities)) {
450 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
452 $orig_header = $message->header
;
454 $encoding = $message->header
->encoding
;
455 $type0 = $message->type0
;
456 $type1 = $message->type1
;
458 foreach ($entities as $ent) {
459 $bodypart = decodeBody(
460 mime_fetch_body($imapConnection, $passed_id, $ent),
462 if ($type1 == 'html') {
463 $bodypart = strip_tags($bodypart);
467 if ($default_use_priority) {
468 $mailprio = substr($orig_header->priority
,0,1);
472 ClearAttachments($session);
475 $idents = getPref($data_dir, $username, 'identities');
476 $from_o = $message->header
->from
;
477 if (is_object($from_o)) {
478 $orig_from = $from_o->getAddress();
482 if (!empty($idents) && $idents > 1) {
483 for ($i = 1; $i < $idents; $i++
) {
484 $enc_from_name = '"'.
488 '" <' . getPref($data_dir, $username,
489 'email_address' . $i) . '>';
490 if ($enc_from_name == $orig_from) {
499 $use_signature = FALSE;
500 $send_to = $orig_header->getAddr_s('to');
501 $send_to_cc = $orig_header->getAddr_s('cc');
502 $send_to_bcc = $orig_header->getAddr_s('bcc');
503 $subject = $orig_header->subject
;
505 $body_ary = explode("\n", $body);
506 $cnt = count($body_ary) ;
508 for ($i=0; $i < $cnt; $i++
) {
509 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
510 sqWordWrap($body_ary[$i], $editor_size );
511 $body .= $body_ary[$i] . "\n";
513 unset($body_ary[$i]);
516 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
518 case ('edit_as_new'):
519 $send_to = $orig_header->getAddr_s('to');
520 $send_to_cc = $orig_header->getAddr_s('cc');
521 $send_to_bcc = $orig_header->getAddr_s('bcc');
522 $subject = $orig_header->subject
;
523 $mailprio = $orig_header->priority
;
525 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
530 // $orig_from = $orig_header->from->getAddress();
531 $subject = $orig_header->subject
;
532 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
533 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
534 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
535 $subject = '[Fwd: ' . $subject . ']';
537 $body = getforwardHeader($orig_header) . $body;
539 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
541 case ('reply' ||
'reply_all'):
542 $send_to = $orig_header->reply_to
;
544 $send_to = $send_to->getAddress();
546 $send_to = $orig_header->from
->getAddress();
548 // $orig_from = $orig_header->from->getAddress();
549 $subject = $orig_header->subject
;
550 $subject = str_replace('"', "'", $subject);
551 $subject = trim($subject);
552 if (substr(strtolower($subject), 0, 3) != 're:') {
553 $subject = 'Re: ' . $subject;
555 if ($action == 'reply_all') {
556 $send_to_cc = replyAllString($orig_header);
558 /* this corrects some wrapping/quoting problems on replies */
559 $rewrap_body = explode("\n", $body);
560 $body = getReplyCitation($orig_header->from
->personal
);
561 $cnt = count($rewrap_body);
562 for ($i=0;$i<$cnt;$i++
) {
563 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
564 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
566 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
568 $body .= '> ' . $rewrap_body[$i] . "\n";
570 unset($rewrap_body[$i]);
578 'send_to' => $send_to,
579 'send_to_cc' => $send_to_cc,
580 'send_to_bcc' => $send_to_bcc,
581 'subject' => $subject,
582 'mailprio' => $mailprio,
584 'identity' => $identity
588 } /* function newMail() */
591 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
592 global $attachments, $attachment_dir, $username;
594 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
595 if (!count($message->entities
) ||
596 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
597 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
598 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
599 $filename = decodeHeader($message->header
->subject
.'.eml');
600 if ($filename == "") {
601 $filename = "untitled-".$message->entity_id
.'.eml';
604 $filename = decodeHeader($message->header
->filename
);
605 if ($filename == "") {
606 $filename = "untitled-".$message->entity_id
;
609 $localfilename = GenerateRandomString(32, '', 7);
610 $full_localfilename = "$hashed_attachment_dir/$localfilename";
611 while (file_exists($full_localfilename)) {
612 $localfilename = GenerateRandomString(32, '', 7);
613 $full_localfilename = "$hashed_attachment_dir/$localfilename";
616 $newAttachment = array();
617 $newAttachment['localfilename'] = $localfilename;
618 $newAttachment['remotefilename'] = $filename;
619 $newAttachment['type'] = strtolower($message->type0
.
620 '/' . $message->type1
);
621 $newAttachment['id'] = strtolower($message->header
->id
);
622 $newAttachment['session'] = $session;
624 /* Write Attachment to file */
625 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
626 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
627 $passed_id, $message->entity_id
),
628 $message->header
->encoding
));
631 $attachments[] = $newAttachment;
634 for ($i = 0; $i < count($message->entities
); $i++
) {
635 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
641 function showInputForm ($session, $values=false) {
642 global $send_to, $send_to_cc, $body,
643 $passed_body, $color, $use_signature, $signature, $prefix_sig,
644 $editor_size, $attachments, $subject, $newmail,
645 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
646 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
647 $username, $data_dir, $identity, $draft_id, $delete_draft,
648 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
649 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action;
651 $subject = decodeHeader($subject, false);
653 $send_to = $values['send_to'];
654 $send_to_cc = $values['send_to_cc'];
655 $send_to_bcc = $values['send_to_bcc'];
656 $subject = $values['subject'];
657 $mailprio = $values['mailprio'];
658 $body = $values['body'];
659 $identity = $values['identity'];
662 if ($use_javascript_addr_book) {
663 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
664 'function open_abook() { ' . "\n" .
665 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
666 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
667 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
668 ' nwin.opener = document.windows;' . "\n" .
670 '// --></SCRIPT>' . "\n\n";
673 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
674 'ENCTYPE="multipart/form-data"';
675 do_hook("compose_form");
680 if ($action == 'draft') {
681 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
683 if (isset($delete_draft)) {
684 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
686 if (isset($session)) {
687 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
690 if ($saved_draft == 'yes') {
691 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
693 if ($mail_sent == 'yes') {
694 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
696 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
697 if ($compose_new_win == '1') {
698 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
699 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
701 if ($location_of_buttons == 'top') {
702 showComposeButtonRow();
705 $idents = getPref($data_dir, $username, 'identities', 0);
707 echo ' <TR>' . "\n" .
708 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
711 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
712 '<select name=identity>' . "\n" .
713 '<option value=default>' .
714 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
715 $em = getPref($data_dir, $username, 'email_address');
717 echo htmlspecialchars(' <' . $em . '>') . "\n";
719 for ($i = 1; $i < $idents; $i ++
) {
720 echo '<option value="' . $i . '"';
721 if (isset($identity) && $identity == $i) {
724 echo '>' . htmlspecialchars(getPref($data_dir, $username,
726 $em = getPref($data_dir, $username, 'email_address' . $i);
728 echo htmlspecialchars(' <' . $em . '>') . "\n";
732 echo '</select>' . "\n" .
736 echo ' <TR>' . "\n" .
737 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
739 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
740 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
741 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
745 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
747 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
748 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
749 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
753 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
755 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
756 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
757 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
758 '</TD></TR>' . "\n" .
760 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
762 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
763 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
764 htmlspecialchars($subject) . '">';
765 echo '</td></tr>' . "\n\n";
767 if ($location_of_buttons == 'between') {
768 showComposeButtonRow();
770 if ($compose_new_win == '1') {
771 echo ' <TR>' . "\n" .
772 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
773 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
774 $editor_size . '" WRAP="VIRTUAL">';
777 echo ' <TR>' . "\n" .
778 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
779 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
780 $editor_size . '" WRAP="VIRTUAL">';
782 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
783 if ($sig_first == '1') {
784 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
785 echo "\n\n".htmlspecialchars($body);
788 echo "\n\n".htmlspecialchars($body);
789 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
793 echo htmlspecialchars($body);
795 echo '</TEXTAREA><BR>' . "\n" .
799 if ($location_of_buttons == 'bottom') {
800 showComposeButtonRow();
802 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
803 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
806 /* This code is for attachments */
807 echo ' <TR>' . "\n" .
808 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
811 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
812 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
813 ' <input type="submit" name="attach"' .
814 ' value="' . _("Add") .'">' . "\n" .
818 if (count($attachments)) {
819 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
820 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
822 '</td><td align=left bgcolor="' . $color[0] . '">';
823 foreach ($attachments as $key => $info) {
824 if ($info['session'] == $session) {
825 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
826 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
827 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
828 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
832 echo '<input type="submit" name="do_delete" value="' .
833 _("Delete selected attachments") . "\">\n" .
836 /* End of attachment code */
837 if ($compose_new_win == '1') {
838 echo '</TABLE>'."\n";
840 echo '</TABLE>' . "\n";
841 if ($action = 'reply' ||
$action = 'reply_all') {
842 echo '<input type=hidden name=reply_id value=' . $passed_id . ">\n";
844 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
847 do_hook('compose_bottom');
848 echo '</BODY></HTML>' . "\n";
852 function showComposeButtonRow() {
853 global $use_javascript_addr_book, $save_as_draft,
854 $default_use_priority, $mailprio, $default_use_mdn,
855 $request_mdn, $request_dr,
856 $data_dir, $username;
858 echo " <TR><TD>\n</TD><TD>\n";
859 if ($default_use_priority) {
860 if(!isset($mailprio)) {
863 echo _("Priority") .': <select name="mailprio">'.
864 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
865 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
866 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
869 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
870 if ($default_use_mdn) {
871 if ($mdn_user_support) {
872 echo "\n\t". _("Receipt") .': '.
873 '<input type="checkbox" name="request_mdn" value=1'.
874 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
875 ' <input type="checkbox" name="request_dr" value=1'.
876 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
880 echo " </td></tr>\n <TR><td>\n </td><td>\n";
881 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
882 if ($use_javascript_addr_book) {
883 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
884 " <input type=button value=\\\""._("Addresses").
885 "\\\" onclick='javascript:open_abook();'>\");".
886 " // --></SCRIPT><NOSCRIPT>\n".
887 " <input type=submit name=\"html_addr_search\" value=\"".
888 _("Addresses")."\">".
891 echo " <input type=submit name=\"html_addr_search\" value=\"".
892 _("Addresses")."\">";
894 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
896 if ($save_as_draft) {
897 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
900 do_hook('compose_button_row');
902 echo " </TD></TR>\n\n";
905 function checkInput ($show) {
907 * I implemented the $show variable because the error messages
908 * were getting sent before the page header. So, I check once
909 * using $show=false, and then when i'm ready to display the error
912 global $body, $send_to, $subject, $color;
914 if ($send_to == "") {
916 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
921 } /* function checkInput() */
924 /* True if FAILURE */
925 function saveAttachedFiles($session) {
926 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
928 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
929 $localfilename = GenerateRandomString(32, '', 7);
930 $full_localfilename = "$hashed_attachment_dir/$localfilename";
931 while (file_exists($full_localfilename)) {
932 $localfilename = GenerateRandomString(32, '', 7);
933 $full_localfilename = "$hashed_attachment_dir/$localfilename";
936 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
937 if (function_exists("move_uploaded_file")) {
938 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
943 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
952 $newAttachment['localfilename'] = $localfilename;
953 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
954 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
955 $newAttachment['session'] = $session;
957 if ($newAttachment['type'] == "") {
958 $newAttachment['type'] = 'application/octet-stream';
961 $attachments[] = $newAttachment;
965 function ClearAttachments($session)
967 global $username, $attachments, $attachment_dir;
968 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
970 $rem_attachments = array();
971 if (is_array($attachments)) {
972 foreach ($attachments as $info) {
973 if ($info['session'] == $session) {
974 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
975 if (file_exists($attached_file)) {
976 unlink($attached_file);
980 $rem_attachments[] = $info;
984 $attachments = $rem_attachments;
988 function getReplyCitation($orig_from)
990 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
992 /* First, return an empty string when no citation style selected. */
993 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
997 /* Make sure our final value isn't an empty string. */
998 if ($orig_from == '') {
1002 /* Otherwise, try to select the desired citation style. */
1003 switch ($reply_citation_style) {
1006 $end = ' ' . _("said") . ':';
1009 $start = '<' . _("quote") . ' ' . _("who") . '="';
1012 case 'user-defined':
1013 $start = $reply_citation_start . ' ';
1014 $end = $reply_citation_end;
1020 /* Build and return the citation string. */
1021 return ($start . $orig_from . $end . "\n");