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/display_messages.php');
26 require_once('../functions/plugin.php');
28 if (!isset($attachments)) {
29 $attachments = array();
30 session_register('attachments');
33 if (!isset($composesession)) {
35 session_register('composesession');
38 if (!isset($session)) {
39 $session = "$composesession" +
1;
40 $composesession = $session;
43 if (!isset($mailbox) ||
$mailbox == '' ||
($mailbox == 'None')) {
48 include_once ('../src/draft_actions.php');
49 if (! isset($reply_id)) {
55 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN, $session)) {
56 showInputForm($session);
59 $draft_message = _("Draft Email Saved");
60 /* If this is a resumed draft, then delete the original */
61 if(isset($delete_draft)) {
62 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
63 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
67 if ($compose_new_win == '1') {
68 Header("Location: compose.php?saved_draft=yes&session=$composesession");
72 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
73 "&startMessage=1¬e=$draft_message");
81 if (isset($HTTP_POST_FILES['attachfile']) &&
82 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
83 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
84 $AttachFailure = saveAttachedFiles($session);
86 if (checkInput(false) && !isset($AttachFailure)) {
87 $urlMailbox = urlencode (trim($mailbox));
88 if (! isset($reply_id)) {
92 * Set $default_charset to correspond with the user's selection
93 * of language interface.
98 * This is to change all newlines to \n
99 * We'll change them to \r\n later (in the sendMessage function)
101 $body = str_replace("\r\n", "\n", $body);
102 $body = str_replace("\r", "\n", $body);
105 * Rewrap $body so that no line is bigger than $editor_size
106 * This should only really kick in the sqWordWrap function
107 * if the browser doesn't support "HARD" as the wrap type
108 * Or, in Opera's case, something goes wrong.
110 $body = explode("\n", $body);
112 foreach ($body as $line) {
113 if( $line <> '-- ' ) {
114 $line = rtrim($line);
116 if (strlen($line) <= $editor_size +
1) {
117 $newBody .= $line . "\n";
119 sqWordWrap($line, $editor_size) . "\n";
125 do_hook('compose_send');
127 $MDN = False; // we are not sending a mdn response
128 if (! isset($mailprio)) {
129 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
130 $subject, $body, $reply_id, $MDN, '', $session);
132 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
133 $subject, $body, $reply_id, $MDN, $mailprio, $session);
136 showInputForm($session);
139 if ( isset($delete_draft)) {
140 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
141 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
144 if ($compose_new_win == '1') {
145 Header("Location: compose.php?mail_sent=yes&session=$composesession");
148 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
153 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
156 if ($compose_new_win == '1') {
157 compose_Header($color, $mailbox);
160 displayPageHeader($color, $mailbox);
162 if (isset($AttachFailure)) {
163 plain_error_message(_("Could not move/copy file. File not attached"),
168 showInputForm($session);
169 /* sqimap_logout($imapConnection); */
171 } elseif (isset($html_addr_search_done)) {
172 if ($compose_new_win == '1') {
173 compose_Header($color, $mailbox);
176 displayPageHeader($color, $mailbox);
179 if (isset($send_to_search) && is_array($send_to_search)) {
180 foreach ($send_to_search as $k => $v) {
181 if (substr($k, 0, 1) == 'T') {
187 elseif (substr($k, 0, 1) == 'C') {
193 elseif (substr($k, 0, 1) == 'B') {
195 $send_to_bcc .= ', ';
201 showInputForm($session);
202 } elseif (isset($html_addr_search)) {
203 if (isset($HTTP_POST_FILES['attachfile']) &&
204 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
205 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
206 if (saveAttachedFiles($session)) {
207 plain_error_message(_("Could not move/copy file. File not attached"), $color);
211 * I am using an include so as to elminiate an extra unnecessary
212 * click. If you can think of a better way, please implement it.
214 include_once('./addrbook_search_html.php');
215 } elseif (isset($attach)) {
216 if (saveAttachedFiles($session)) {
217 plain_error_message(_("Could not move/copy file. File not attached"), $color);
219 if ($compose_new_win == '1') {
220 compose_Header($color, $mailbox);
223 displayPageHeader($color, $mailbox);
225 showInputForm($session);
227 elseif (isset($sigappend)) {
228 $idents = getPref($data_dir, $username, 'identities', 0);
230 if ($identity == 'default') {
235 $signature = getSig($data_dir, $username, $no);
237 $body .= "\n\n".($prefix_sig==true?
"-- \n":'').$signature;
238 if ($compose_new_win == '1') {
239 compose_Header($color, $mailbox);
241 displayPageHeader($color, $mailbox);
243 showInputForm($session);
244 } elseif (isset($do_delete)) {
245 if ($compose_new_win == '1') {
246 compose_Header($color, $mailbox);
249 displayPageHeader($color, $mailbox);
252 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
253 if (isset($delete) && is_array($delete)) {
254 foreach($delete as $index) {
255 $attached_file = $hashed_attachment_dir . '/'
256 . $attachments[$index]['localfilename'];
257 unlink ($attached_file);
258 unset ($attachments[$index]);
262 showInputForm($session);
264 } elseif (isset($attachedmessages)) {
267 * This handles the case if we attache message
269 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
271 if ($compose_new_win == '1') {
272 compose_Header($color, $mailbox);
275 displayPageHeader($color, $mailbox);
281 showInputForm($session);
282 sqimap_logout($imapConnection);
286 * This handles the default case as well as the error case
287 * (they had the same code) --> if (isset($smtpErrors))
289 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
291 if ($compose_new_win == '1') {
292 compose_Header($color, $mailbox);
295 displayPageHeader($color, $mailbox);
300 ClearAttachments($session);
302 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) {
303 getAttachments(0, $session);
306 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) {
307 getAttachments(0, $session);
311 showInputForm($session);
312 sqimap_logout($imapConnection);
318 /**************** Only function definitions go below *************/
321 /* This function is used when not sending or adding attachments */
322 function newMail () {
323 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
324 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
325 $draft_id, $use_signature, $composesession;
327 $send_to = decodeHeader($send_to, false);
328 $send_to_cc = decodeHeader($send_to_cc, false);
329 $send_to_bcc = decodeHeader($send_to_bcc, false);
333 } elseif ($reply_id) {
339 $use_signature = FALSE;
343 sqimap_mailbox_select($imapConnection, $mailbox);
344 $message = sqimap_get_message($imapConnection, $id, $mailbox);
345 $orig_header = $message->header
;
347 $message = getEntity($message, $ent_num);
349 if ($message->header
->type0
== 'text' ||
350 $message->header
->type1
== 'message') {
353 mime_fetch_body($imapConnection, $id, $ent_num),
354 $message->header
->encoding
);
357 mime_fetch_body($imapConnection, $id, 1),
358 $message->header
->encoding
);
364 if ($message->header
->type1
== 'html') {
365 $body = strip_tags($body);
369 $body_ary = explode("\n", $body);
370 $i = count($body_ary) - 1;
371 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
372 unset($body_ary[$i]);
376 for ($i=0; isset($body_ary[$i]); $i++
) {
378 if (ereg('^[ >]+', $body_ary[$i])) {
379 $body_ary[$i] = '>' . $body_ary[$i];
381 $body_ary[$i] = '> ' . $body_ary[$i];
385 sqWordWrap($body_ary[$i], $editor_size - 1);
387 $body .= $body_ary[$i] . "\n";
388 unset($body_ary[$i]);
391 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
392 _("Subject") . ': ' . $orig_header->subject
. "\n" .
393 _("From") . ': ' . $orig_header->from
. "\n" .
395 getLongDateString( $orig_header->date
). "\n" .
396 _("To") . ': ' . $orig_header->to
[0] . "\n";
397 if (count($orig_header->to
) > 1) {
398 for ($x=1; $x < count($orig_header->to
); $x++
) {
399 $bodyTop .= ' ' . $orig_header->to
[$x] . "\n";
403 $body = $bodyTop . $body;
406 $orig_from = decodeHeader($orig_header->from
, false);
407 $body = getReplyCitation($orig_from) . $body;
414 $send_to = sqimap_find_email($send_to);
417 /* This formats a CC string if they hit "reply all" */
418 if ($send_to_cc != '') {
419 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
420 $send_to_cc = str_replace(';', ',', $send_to_cc);
421 $sendcc = explode(',', $send_to_cc);
424 for ($i = 0; $i < count($sendcc); $i++
) {
425 $sendcc[$i] = trim($sendcc[$i]);
426 if ($sendcc[$i] == '') {
430 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
431 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
432 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
434 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
435 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
436 (trim($sendcc[$i]) != '')) {
437 $send_to_cc .= trim($sendcc[$i]) . ', ';
440 $send_to_cc = trim($send_to_cc);
441 if (substr($send_to_cc, -1) == ',') {
442 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
445 } /* function newMail() */
448 function getAttachments($message, $session) {
449 global $mailbox, $attachments, $attachment_dir, $imapConnection,
450 $ent_num, $forward_id, $draft_id, $username;
452 if (isset($draft_id)) {
459 sqimap_mailbox_select($imapConnection, $mailbox);
460 $message = sqimap_get_message($imapConnection, $id, $mailbox);
463 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
464 if (count($message->entities
) == 0) {
465 if ($message->header
->entity_id
!= $ent_num) {
466 $filename = decodeHeader($message->header
->filename
);
468 if ($filename == "") {
469 $filename = "untitled-".$message->header
->entity_id
;
472 $localfilename = GenerateRandomString(32, '', 7);
473 $full_localfilename = "$hashed_attachment_dir/$localfilename";
474 while (file_exists($full_localfilename)) {
475 $localfilename = GenerateRandomString(32, '', 7);
476 $full_localfilename = "$hashed_attachment_dir/$localfilename";
479 $newAttachment = array();
480 $newAttachment['localfilename'] = $localfilename;
481 $newAttachment['remotefilename'] = $filename;
482 $newAttachment['type'] = strtolower($message->header
->type0
.
483 '/' . $message->header
->type1
);
484 $newAttachment['id'] = strtolower($message->header
->id
);
485 $newAttachment['session'] = $session;
487 /* Write Attachment to file */
488 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
489 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
490 $id, $message->header
->entity_id
),
491 $message->header
->encoding
));
494 $attachments[] = $newAttachment;
497 for ($i = 0; $i < count($message->entities
); $i++
) {
498 getAttachments($message->entities
[$i], $session);
504 function showInputForm ($session) {
505 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
506 $passed_body, $color, $use_signature, $signature, $prefix_sig,
507 $editor_size, $attachments, $subject, $newmail,
508 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
509 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
510 $username, $data_dir, $identity, $draft_id, $delete_draft,
511 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
512 $saved_draft, $mail_sent, $sig_first;
514 $subject = decodeHeader($subject, false);
515 $reply_subj = decodeHeader($reply_subj, false);
516 $forward_subj = decodeHeader($forward_subj, false);
518 if ($use_javascript_addr_book) {
519 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
520 'function open_abook() { ' . "\n" .
521 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
522 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
523 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
524 ' nwin.opener = document.windows;' . "\n" .
526 '// --></SCRIPT>' . "\n\n";
529 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
530 'ENCTYPE="multipart/form-data"';
531 do_hook("compose_form");
536 if (isset($draft_id)) {
537 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
539 if (isset($delete_draft)) {
540 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
542 if (isset($session)) {
543 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
546 if ($saved_draft == 'yes') {
547 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
549 if ($mail_sent == 'yes') {
550 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
552 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
553 if ($compose_new_win == '1') {
554 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
556 if ($location_of_buttons == 'top') {
557 showComposeButtonRow();
560 $idents = getPref($data_dir, $username, 'identities', 0);
562 echo ' <TR>' . "\n" .
563 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
566 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
567 '<select name=identity>' . "\n" .
568 '<option value=default>' .
569 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
570 $em = getPref($data_dir, $username, 'email_address');
572 echo htmlspecialchars(' <' . $em . '>') . "\n";
574 for ($i = 1; $i < $idents; $i ++
) {
575 echo '<option value="' . $i . '"';
576 if (isset($identity) && $identity == $i) {
579 echo '>' . htmlspecialchars(getPref($data_dir, $username,
581 $em = getPref($data_dir, $username, 'email_address' . $i);
583 echo htmlspecialchars(' <' . $em . '>') . "\n";
587 echo '</select>' . "\n" .
591 echo ' <TR>' . "\n" .
592 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
594 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
595 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
596 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
600 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
602 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
603 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
604 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
608 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
610 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
611 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
612 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
613 '</TD></TR>' . "\n" .
615 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
617 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
619 $reply_subj = str_replace('"', "'", $reply_subj);
620 $reply_subj = trim($reply_subj);
621 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
622 $reply_subj = 'Re: ' . $reply_subj;
624 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
625 htmlspecialchars($reply_subj) . '">';
627 elseif ($forward_subj) {
628 $forward_subj = trim($forward_subj);
629 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
630 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
631 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
632 $forward_subj = '[Fwd: ' . $forward_subj . ']';
634 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
635 htmlspecialchars($forward_subj) . '">';
637 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
638 htmlspecialchars($subject) . '">';
640 echo '</td></tr>' . "\n\n";
642 if ($location_of_buttons == 'between') {
643 showComposeButtonRow();
646 echo ' <TR>' . "\n" .
647 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
648 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
649 $editor_size . '" WRAP=HARD>';
650 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
651 if ($sig_first == '1') {
652 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
653 echo "\n\n".htmlspecialchars($body);
656 echo "\n\n".htmlspecialchars($body);
657 echo "\n\n".($prefix_sig==true?
"-- \n":'').htmlspecialchars($signature);
661 echo htmlspecialchars($body);
663 echo '</TEXTAREA><BR>' . "\n" .
667 if ($location_of_buttons == 'bottom') {
668 showComposeButtonRow();
670 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
671 echo ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
674 /* This code is for attachments */
675 echo ' <TR>' . "\n" .
676 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
679 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
680 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
681 ' <input type="submit" name="attach"' .
682 ' value="' . _("Add") .'">' . "\n" .
686 if (count($attachments)) {
687 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
688 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
690 '</td><td align=left bgcolor="' . $color[0] . '">';
691 foreach ($attachments as $key => $info) {
692 if ($info['session'] == $session) {
693 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
694 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
695 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
696 show_readable_size(filesize($attached_file)) . ")<br>\n";
700 echo '<input type="submit" name="do_delete" value="' .
701 _("Delete selected attachments") . "\">\n" .
704 /* End of attachment code */
706 echo '</TABLE>' . "\n";
708 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
710 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
713 do_hook('compose_bottom');
714 echo '</BODY></HTML>' . "\n";
718 function showComposeButtonRow() {
719 global $use_javascript_addr_book, $save_as_draft,
720 $default_use_priority, $mailprio, $default_use_mdn,
721 $data_dir, $username;
723 echo " <TR><TD>\n</TD><TD>\n";
724 if ($default_use_priority) {
725 if(!isset($mailprio)) {
728 echo _("Priority") .': <select name="mailprio">'.
729 '<option value="1"'.($mailprio=='1'?
' selected':'').'>'. _("High") .'</option>'.
730 '<option value="3"'.($mailprio=='3'?
' selected':'').'>'. _("Normal") .'</option>'.
731 '<option value="5"'.($mailprio=='5'?
' selected':'').'>'. _("Low").'</option>'.
734 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
735 if ($default_use_mdn) {
736 if ($mdn_user_support) {
737 echo "\n\t". _("Receipt") .': '.
738 '<input type="checkbox" name="request_mdn" value=1>'. _("On read").
739 ' <input type="checkbox" name="request_dr" value=1>'. _("On Delivery");
743 echo " <TR><td>\n </td><td>\n";
744 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
745 if ($use_javascript_addr_book) {
746 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
747 " <input type=button value=\\\""._("Addresses").
748 "\\\" onclick='javascript:open_abook();'>\");".
749 " // --></SCRIPT><NOSCRIPT>\n".
750 " <input type=submit name=\"html_addr_search\" value=\"".
751 _("Addresses")."\">".
754 echo " <input type=submit name=\"html_addr_search\" value=\"".
755 _("Addresses")."\">";
757 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
759 if ($save_as_draft) {
760 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
763 do_hook('compose_button_row');
765 echo " </TD></TR>\n\n";
768 function checkInput ($show) {
770 * I implemented the $show variable because the error messages
771 * were getting sent before the page header. So, I check once
772 * using $show=false, and then when i'm ready to display the error
775 global $body, $send_to, $subject, $color;
777 if ($send_to == "") {
779 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
784 } /* function checkInput() */
787 /* True if FAILURE */
788 function saveAttachedFiles($session) {
789 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
791 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
792 $localfilename = GenerateRandomString(32, '', 7);
793 $full_localfilename = "$hashed_attachment_dir/$localfilename";
794 while (file_exists($full_localfilename)) {
795 $localfilename = GenerateRandomString(32, '', 7);
796 $full_localfilename = "$hashed_attachment_dir/$localfilename";
799 if (!@rename
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
800 if (!@copy
($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
805 $newAttachment['localfilename'] = $localfilename;
806 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
807 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
808 $newAttachment['session'] = $session;
810 if ($newAttachment['type'] == "") {
811 $newAttachment['type'] = 'application/octet-stream';
814 $attachments[] = $newAttachment;
818 function ClearAttachments($session)
820 global $username, $attachments, $attachment_dir;
821 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
823 $rem_attachments = array();
824 foreach ($attachments as $info) {
825 if ($info['session'] == $session) {
826 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
827 if (file_exists($attached_file)) {
828 unlink($attached_file);
831 $rem_attachments[] = $info;
834 $attachments = $rem_attachments;
838 function getReplyCitation($orig_from)
840 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
842 /* First, return an empty string when no citation style selected. */
843 if (($reply_citation_style == '') ||
($reply_citation_style == 'none')) {
847 /* Decode the users name. */
848 $parpos = strpos($orig_from, '(');
849 if ($parpos === false) {
850 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
851 $orig_from = str_replace('"', '', $orig_from);
852 $orig_from = str_replace("'", '', $orig_from);
854 $end_parpos = strrpos($orig_from, ')');
855 $end_parpos -= ($end_parpos === false ?
$end_parpos : $parpos +
1);
856 $orig_from = trim(substr($orig_from, $parpos +
1, $end_parpos));
859 /* Make sure our final value isn't an empty string. */
860 if ($orig_from == '') {
864 /* Otherwise, try to select the desired citation style. */
865 switch ($reply_citation_style) {
868 $end = ' ' . _("said") . ':';
871 $start = '<' . _("quote") . ' ' . _("who") . '="';
875 $start = $reply_citation_start;
876 $end = $reply_citation_end;
882 /* Build and return the citation string. */
883 return ($start . $orig_from . $end . "\n");