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;
401 $send_to = $send_to_cc = $send_to_bcc = $subject = $mailprio = $body = '';
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 $use_signature = FALSE;
454 $send_to = $orig_header->getAddr_s('to');
455 $send_to_cc = $orig_header->getAddr_s('cc');
456 $send_to_bcc = $orig_header->getAddr_s('bcc');
457 $subject = $orig_header->subject
;
459 $body_ary = explode("\n", $body);
460 $cnt = count($body_ary) ;
462 for ($i=0; $i < $cnt; $i++
) {
463 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
464 sqWordWrap($body_ary[$i], $editor_size );
465 $body .= $body_ary[$i] . "\n";
467 unset($body_ary[$i]);
470 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
472 case ('edit_as_new'):
473 $send_to = $orig_header->getAddr_s('to');
474 $send_to_cc = $orig_header->getAddr_s('cc');
475 $send_to_bcc = $orig_header->getAddr_s('bcc');
476 $subject = $orig_header->subject
;
477 $mailprio = $orig_header->priority
;
478 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
483 $orig_from = $orig_header->from
->getAddress();
484 $subject = $orig_header->subject
;
485 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
486 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
487 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
488 $subject = '[Fwd: ' . $subject . ']';
490 $body = getforwardHeader($orig_header) . $body;
492 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
494 case ('reply' ||
'reply_all'):
495 $send_to = $orig_header->reply_to
;
497 $send_to = $send_to->getAddress();
499 $send_to = $orig_header->from
->getAddress();
501 $orig_from = $orig_header->from
->getAddress();
502 $subject = $orig_header->subject
;
503 $subject = str_replace('"', "'", $subject);
504 $subject = trim($subject);
505 if (substr(strtolower($subject), 0, 3) != 're:') {
506 $subject = 'Re: ' . $subject;
508 if ($action == 'reply_all') {
509 $send_to_cc = replyAllString($orig_header);
511 /* this corrects some wrapping/quoting problems on replies */
512 $rewrap_body = explode("\n", $body);
513 $body = getReplyCitation($orig_header->from
->personal
);
514 $cnt = count($rewrap_body);
515 for ($i=0;$i<$cnt;$i++
) {
516 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
517 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
519 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
521 $body .= '> ' . $rewrap_body[$i] . "\n";
523 unset($rewrap_body[$i]);
531 'send_to' => $send_to,
532 'send_to_cc' => $send_to_cc,
533 'send_to_bcc' => $send_to_bcc,
534 'subject' => $subject,
535 'mailprio' => $mailprio,
540 } /* function newMail() */
543 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
544 global $attachments, $attachment_dir, $username;
546 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
547 if (!count($message->entities
) ||
548 ($message->type0
== 'message' && $message->type1
== 'rfc822')) {
549 if ( !in_array($message->entity_id
, $entities) && $message->entity_id
) {
550 if ($message->type0
== 'message' && $message->type1
== 'rfc822') {
551 $filename = decodeHeader($message->header
->subject
.'.eml');
552 if ($filename == "") {
553 $filename = "untitled-".$message->entity_id
.'.eml';
556 $filename = decodeHeader($message->header
->filename
);
557 if ($filename == "") {
558 $filename = "untitled-".$message->entity_id
;
561 $localfilename = GenerateRandomString(32, '', 7);
562 $full_localfilename = "$hashed_attachment_dir/$localfilename";
563 while (file_exists($full_localfilename)) {
564 $localfilename = GenerateRandomString(32, '', 7);
565 $full_localfilename = "$hashed_attachment_dir/$localfilename";
568 $newAttachment = array();
569 $newAttachment['localfilename'] = $localfilename;
570 $newAttachment['remotefilename'] = $filename;
571 $newAttachment['type'] = strtolower($message->type0
.
572 '/' . $message->type1
);
573 $newAttachment['id'] = strtolower($message->header
->id
);
574 $newAttachment['session'] = $session;
576 /* Write Attachment to file */
577 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
578 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
579 $passed_id, $message->entity_id
),
580 $message->header
->encoding
));
583 $attachments[] = $newAttachment;
586 for ($i = 0; $i < count($message->entities
); $i++
) {
587 getAttachments($message->entities
[$i], $session, $passed_id, $entities, $imapConnection);
593 function showInputForm ($session, $values=false) {
594 global $send_to, $send_to_cc, $body,
595 $passed_body, $color, $use_signature, $signature, $prefix_sig,
596 $editor_size, $attachments, $subject, $newmail,
597 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
598 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
599 $username, $data_dir, $identity, $draft_id, $delete_draft,
600 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
601 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action;
603 $subject = decodeHeader($subject, false);
605 $send_to = $values['send_to'];
606 $send_to_cc = $values['send_to_cc'];
607 $send_to_bcc = $values['send_to_bcc'];
608 $subject = $values['subject'];
609 $mailprio = $values['mailprio'];
610 $body = $values['body'];
613 if ($use_javascript_addr_book) {
614 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
615 'function open_abook() { ' . "\n" .
616 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
617 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
618 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
619 ' nwin.opener = document.windows;' . "\n" .
621 '// --></SCRIPT>' . "\n\n";
624 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
625 'ENCTYPE="multipart/form-data"';
626 do_hook("compose_form");
631 if ($action == 'draft') {
632 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
634 if (isset($delete_draft)) {
635 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
637 if (isset($session)) {
638 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
641 if ($saved_draft == 'yes') {
642 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
644 if ($mail_sent == 'yes') {
645 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
647 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
648 if ($compose_new_win == '1') {
649 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
650 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
652 if ($location_of_buttons == 'top') {
653 showComposeButtonRow();
656 $idents = getPref($data_dir, $username, 'identities', 0);
658 echo ' <TR>' . "\n" .
659 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
662 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
663 '<select name=identity>' . "\n" .
664 '<option value=default>' .
665 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
666 $em = getPref($data_dir, $username, 'email_address');
668 echo htmlspecialchars(' <' . $em . '>') . "\n";
670 for ($i = 1; $i < $idents; $i ++
) {
671 echo '<option value="' . $i . '"';
672 if (isset($identity) && $identity == $i) {
675 echo '>' . htmlspecialchars(getPref($data_dir, $username,
677 $em = getPref($data_dir, $username, 'email_address' . $i);
679 echo htmlspecialchars(' <' . $em . '>') . "\n";
683 echo '</select>' . "\n" .
687 echo ' <TR>' . "\n" .
688 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
690 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
691 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
692 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
696 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
698 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
699 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
700 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
704 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
706 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
707 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
708 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
709 '</TD></TR>' . "\n" .
711 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
713 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
714 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
715 htmlspecialchars($subject) . '">';
716 echo '</td></tr>' . "\n\n";
718 if ($location_of_buttons == 'between') {
719 showComposeButtonRow();
721 if ($compose_new_win == '1') {
722 echo ' <TR>' . "\n" .
723 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
724 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
725 $editor_size . '" WRAP="VIRTUAL">';
728 echo ' <TR>' . "\n" .
729 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
730 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
731 $editor_size . '" WRAP="VIRTUAL">';
733 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
734 if ($sig_first == '1') {
735 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
736 echo "\n\n".htmlspecialchars($body);
739 echo "\n\n".htmlspecialchars($body);
740 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
744 echo htmlspecialchars($body);
746 echo '</TEXTAREA><BR>' . "\n" .
750 if ($location_of_buttons == 'bottom') {
751 showComposeButtonRow();
753 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
754 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
757 /* This code is for attachments */
758 echo ' <TR>' . "\n" .
759 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
762 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
763 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
764 ' <input type="submit" name="attach"' .
765 ' value="' . _("Add") .'">' . "\n" .
769 if (count($attachments)) {
770 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
771 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
773 '</td><td align=left bgcolor="' . $color[0] . '">';
774 foreach ($attachments as $key => $info) {
775 if ($info['session'] == $session) {
776 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
777 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
778 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
779 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
783 echo '<input type="submit" name="do_delete" value="' .
784 _("Delete selected attachments") . "\">\n" .
787 /* End of attachment code */
788 if ($compose_new_win == '1') {
789 echo '</TABLE>'."\n";
791 echo '</TABLE>' . "\n";
792 if ($action = 'reply' ||
$action = 'reply_all') {
793 echo '<input type=hidden name=reply_id value=' . $passed_id . ">\n";
795 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
798 do_hook('compose_bottom');
799 echo '</BODY></HTML>' . "\n";
803 function showComposeButtonRow() {
804 global $use_javascript_addr_book, $save_as_draft,
805 $default_use_priority, $mailprio, $default_use_mdn,
806 $request_mdn, $request_dr,
807 $data_dir, $username;
809 echo " <TR><TD>\n</TD><TD>\n";
810 if ($default_use_priority) {
811 if(!isset($mailprio)) {
814 echo _("Priority") .': <select name="mailprio">'.
815 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
816 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
817 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
820 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
821 if ($default_use_mdn) {
822 if ($mdn_user_support) {
823 echo "\n\t". _("Receipt") .': '.
824 '<input type="checkbox" name="request_mdn" value=1'.
825 ($request_mdn=='1'?
' checked':'') .'>'. _("On read").
826 ' <input type="checkbox" name="request_dr" value=1'.
827 ($request_dr=='1'?
' checked':'') .'>'. _("On Delivery");
831 echo " </td></tr>\n <TR><td>\n </td><td>\n";
832 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
833 if ($use_javascript_addr_book) {
834 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
835 " <input type=button value=\\\""._("Addresses").
836 "\\\" onclick='javascript:open_abook();'>\");".
837 " // --></SCRIPT><NOSCRIPT>\n".
838 " <input type=submit name=\"html_addr_search\" value=\"".
839 _("Addresses")."\">".
842 echo " <input type=submit name=\"html_addr_search\" value=\"".
843 _("Addresses")."\">";
845 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
847 if ($save_as_draft) {
848 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
851 do_hook('compose_button_row');
853 echo " </TD></TR>\n\n";
856 function checkInput ($show) {
858 * I implemented the $show variable because the error messages
859 * were getting sent before the page header. So, I check once
860 * using $show=false, and then when i'm ready to display the error
863 global $body, $send_to, $subject, $color;
865 if ($send_to == "") {
867 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
872 } /* function checkInput() */
875 /* True if FAILURE */
876 function saveAttachedFiles($session) {
877 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
879 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
880 $localfilename = GenerateRandomString(32, '', 7);
881 $full_localfilename = "$hashed_attachment_dir/$localfilename";
882 while (file_exists($full_localfilename)) {
883 $localfilename = GenerateRandomString(32, '', 7);
884 $full_localfilename = "$hashed_attachment_dir/$localfilename";
887 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
888 if (function_exists("move_uploaded_file")) {
889 if (!@move_uploaded_file
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
894 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
903 $newAttachment['localfilename'] = $localfilename;
904 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
905 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
906 $newAttachment['session'] = $session;
908 if ($newAttachment['type'] == "") {
909 $newAttachment['type'] = 'application/octet-stream';
912 $attachments[] = $newAttachment;
916 function ClearAttachments($session)
918 global $username, $attachments, $attachment_dir;
919 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
921 $rem_attachments = array();
922 if (is_array($attachments)) {
923 foreach ($attachments as $info) {
924 if ($info['session'] == $session) {
925 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
926 if (file_exists($attached_file)) {
927 unlink($attached_file);
931 $rem_attachments[] = $info;
935 $attachments = $rem_attachments;
939 function getReplyCitation($orig_from)
941 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
943 /* First, return an empty string when no citation style selected. */
944 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
948 /* Make sure our final value isn't an empty string. */
949 if ($orig_from == '') {
953 /* Otherwise, try to select the desired citation style. */
954 switch ($reply_citation_style) {
957 $end = ' ' . _("said") . ':';
960 $start = '<' . _("quote") . ' ' . _("who") . '="';
964 $start = $reply_citation_start . ' ';
965 $end = $reply_citation_end;
971 /* Build and return the citation string. */
972 return ($start . $orig_from . $end . "\n");