X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fcompose.php;h=749a542ba86679060474bb78348ae23c30d782b1;hb=0f8a1ce94ff62c4a6022969cf2b3e8fb695282f4;hp=0d8784f99efbd139862f7b875e8a3a9d7bbff366;hpb=944eb7852dbddee896b1f0c4b260c634e1142deb;p=squirrelmail.git diff --git a/src/compose.php b/src/compose.php index 0d8784f9..749a542b 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1,396 +1,754 @@ header; - if ($ent_num) + +/** + * compose.php + * + * Copyright (c) 1999-2002 The SquirrelMail Project Team + * Licensed under the GNU GPL. For full terms see the file COPYING. + * + * This code sends a mail. + * + * There are 4 modes of operation: + * - Start new mail + * - Add an attachment + * - Send mail + * - Save As Draft + * + * $Id$ + */ + +require_once('../src/validate.php'); +require_once('../functions/imap.php'); +require_once('../functions/date.php'); +require_once('../functions/mime.php'); +require_once('../functions/smtp.php'); +require_once('../functions/display_messages.php'); +require_once('../functions/plugin.php'); + +if (!isset($attachments)) { + $attachments = array(); + session_register('attachments'); +} + +if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { + $mailbox = 'INBOX'; +} + +if (isset($draft)) { + include_once ('../src/draft_actions.php'); + if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) { + showInputForm(); + exit(); + } else { + $draft_message = _("Draft Email Saved"); + /* If this is a resumed draft, then delete the original */ + if(isset($delete_draft)) { + Header("Location: delete_message.php?mailbox=$draft_folder". + "&message=$delete_draft&sort=$sort&startMessage=1"); + exit(); + } else { + Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort". + "&startMessage=1¬e=$draft_message"); + exit(); + } + } +} + +if (isset($send)) { + if (isset($HTTP_POST_FILES['attachfile']) && + $HTTP_POST_FILES['attachfile']['tmp_name'] && + $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { + $AttachFailure = saveAttachedFiles(); + } + if (checkInput(false) && !isset($AttachFailure)) { + $urlMailbox = urlencode (trim($mailbox)); + if (! isset($reply_id)) { + $reply_id = 0; + } + /* + * Set $default_charset to correspond with the user's selection + * of language interface. + */ + set_my_charset(); + + /* + * This is to change all newlines to \n + * We'll change them to \r\n later (in the sendMessage function) + */ + $body = str_replace("\r\n", "\n", $body); + $body = str_replace("\r", "\n", $body); + + /* + * Rewrap $body so that no line is bigger than $editor_size + * This should only really kick in the sqWordWrap function + * if the browser doesn't support "HARD" as the wrap type + * Or, in Opera's case, something goes wrong. + */ + $body = explode("\n", $body); + $newBody = ''; + foreach ($body as $line) { + if( $line <> '-- ' ) { + $line = rtrim($line); + } + if (strlen($line) <= $editor_size + 1) { + $newBody .= $line . "\n"; + } else { + sqWordWrap($line, $editor_size) . "\n"; + $newBody .= $line; + } + } + $body = $newBody; + + do_hook("compose_send"); + + if (! isset($mailprio)) { + $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, + $subject, $body, $reply_id); + } else { + $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc, + $subject, $body, $reply_id, $mailprio); + } + if (! $Result) { + showInputForm(); + exit(); + } + if ( isset($delete_draft)) { + Header("Location: delete_message.php?mailbox=$draft_folder". + "&message=$delete_draft&sort=$sort&startMessage=1"); + exit(); + } + + Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort". + "&startMessage=1"); + } else { + /* + *$imapConnection = sqimap_login($username, $key, $imapServerAddress, + * $imapPort, 0); + */ + displayPageHeader($color, $mailbox); + + if (isset($AttachFailure)) { + plain_error_message(_("Could not move/copy file. File not attached"), + $color); + } + + checkInput(true); + showInputForm(); + /* sqimap_logout($imapConnection); */ + } +} +elseif (isset($html_addr_search_done)) { + displayPageHeader($color, $mailbox); + + if (isset($send_to_search) && is_array($send_to_search)) { + foreach ($send_to_search as $k => $v) { + if (substr($k, 0, 1) == 'T') { + if ($send_to) { + $send_to .= ', '; + } + $send_to .= $v; + } + elseif (substr($k, 0, 1) == 'C') { + if ($send_to_cc) { + $send_to_cc .= ', '; + } + $send_to_cc .= $v; + } + elseif (substr($k, 0, 1) == 'B') { + if ($send_to_bcc) { + $send_to_bcc .= ', '; + } + $send_to_bcc .= $v; + } + } + } + showInputForm(); +} +elseif (isset($html_addr_search)) { + if (isset($HTTP_POST_FILES['attachfile']) && + $HTTP_POST_FILES['attachfile']['tmp_name'] && + $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') { + if (saveAttachedFiles()) { + plain_error_message(_("Could not move/copy file. File not attached"), $color); + } + } + /* + * I am using an include so as to elminiate an extra unnecessary + * click. If you can think of a better way, please implement it. + */ + include_once('./addrbook_search_html.php'); +} +elseif (isset($attach)) { + if (saveAttachedFiles()) { + plain_error_message(_("Could not move/copy file. File not attached"), $color); + } + displayPageHeader($color, $mailbox); + showInputForm(); +} +elseif (isset($do_delete)) { + displayPageHeader($color, $mailbox); + + $hashed_attachment_dir = getHashedDir($username, $attachment_dir); + if (isset($delete) && is_array($delete)) { + foreach($delete as $index) { + $attached_file = $hashed_attachment_dir . '/' + . $attachments[$index]['localfilename']; + unlink ($attached_file); + unset ($attachments[$index]); + } + } + + showInputForm(); +} else { + /* + * This handles the default case as well as the error case + * (they had the same code) --> if (isset($smtpErrors)) + */ + $imapConnection = sqimap_login($username, $key, $imapServerAddress, + $imapPort, 0); + displayPageHeader($color, $mailbox); + + $newmail = true; + + ClearAttachments(); + + if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) { + getAttachments(0); + } + + if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) { + getAttachments(0); + } + + newMail(); + showInputForm(); + sqimap_logout($imapConnection); +} + +exit(); + + +/**************** Only function definitions go below *************/ + + +/* This function is used when not sending or adding attachments */ +function newMail () { + global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, + $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size, + $draft_id, $use_signature; + + $send_to = decodeHeader($send_to, false); + $send_to_cc = decodeHeader($send_to_cc, false); + $send_to_bcc = decodeHeader($send_to_bcc, false); + + if ($forward_id) { + $id = $forward_id; + } elseif ($reply_id) { + $id = $reply_id; + } + + if ($draft_id){ + $id = $draft_id; + $use_signature = FALSE; + } + + if (isset($id)) { + sqimap_mailbox_select($imapConnection, $mailbox); + $message = sqimap_get_message($imapConnection, $id, $mailbox); + $orig_header = $message->header; + if ($ent_num) { $message = getEntity($message, $ent_num); + } + if ($message->header->type0 == 'text' || + $message->header->type1 == 'message') { + if ($ent_num) { + $body = decodeBody( + mime_fetch_body($imapConnection, $id, $ent_num), + $message->header->encoding); + } else { + $body = decodeBody( + mime_fetch_body($imapConnection, $id, 1), + $message->header->encoding); + } + } else { + $body = ''; + } - if ($message->header->type0 == "text" || $message->header->type1 == "message") { - if ($ent_num) - $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding); - else - $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding); - } else { - $body = ""; - } - - if ($message->header->type1 == "html") + if ($message->header->type1 == 'html') { $body = strip_tags($body); - - $body_ary = explode("\n", $body); - $body = ""; - for ($i=0; $i < count($body_ary); $i++) { - if ($i==0 && $forward_id) { - $tmp = "-------- " . _("Original Message") . " --------\n"; - $tmp .= _("Subject") . ": " . $orig_header->subject . "\n"; - $tmp .= " " . _("From") . ": " . $orig_header->from . "\n"; - $tmp .= " " . _("To") . ": " . $orig_header->to[0] . "\n"; - if (count($orig_header->to) > 1) { - for ($x=1; $x < count($orig_header->to); $x++) { - $tmp .= " " . $orig_header->to[$x] . "\n"; - } - } - $tmp .= "\n" . $body_ary[$i]; - } else { - $tmp = $body_ary[$i]; + } + + sqUnWordWrap($body); + $body_ary = explode("\n", $body); + $i = count($body_ary) - 1; + while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) { + unset($body_ary[$i]); + $i --; + } + $body = ''; + for ($i=0; isset($body_ary[$i]); $i++) { + if ($reply_id) { + if (ereg('^[ >]+', $body_ary[$i])) { + $body_ary[$i] = '>' . $body_ary[$i]; + } else { + $body_ary[$i] = '> ' . $body_ary[$i]; + } + } + if (!$draft_id) { + sqWordWrap($body_ary[$i], $editor_size - 1); } - if ($forward_id) - $body = "$body$tmp\n"; - else - $body = "$body> $tmp\n"; - } - sqimap_mailbox_close($imapConnection); - return $body; - } - - if (!$send_to) { - $send_to = sqimap_find_email($send_to); - } - - /** This formats a CC string if they hit "reply all" **/ - if ($send_to_cc != "") { - $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc); - $send_to_cc = ereg_replace(";", ",", $send_to_cc); - $sendcc = explode(",", $send_to_cc); - $send_to_cc = ""; - - for ($i = 0; $i < count($sendcc); $i++) { + $body .= $body_ary[$i] . "\n"; + unset($body_ary[$i]); + } + if ($forward_id) { + $bodyTop = '-------- ' . _("Original Message") . " --------\n" . + _("Subject") . ': ' . $orig_header->subject . "\n" . + _("From") . ': ' . $orig_header->from . "\n" . + _("Date") . ': ' . + getLongDateString( $orig_header->date ). "\n" . + _("To") . ': ' . $orig_header->to[0] . "\n"; + if (count($orig_header->to) > 1) { + for ($x=1; $x < count($orig_header->to); $x++) { + $bodyTop .= ' ' . $orig_header->to[$x] . "\n"; + } + } + $bodyTop .= "\n"; + $body = $bodyTop . $body; + } + elseif ($reply_id) { + $orig_from = decodeHeader($orig_header->from, false); + $body = getReplyCitation($orig_from) . $body; + } + + return; + } + + if (!$send_to) { + $send_to = sqimap_find_email($send_to); + } + + /* This formats a CC string if they hit "reply all" */ + if ($send_to_cc != '') { + $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc); + $send_to_cc = str_replace(';', ',', $send_to_cc); + $sendcc = explode(',', $send_to_cc); + $send_to_cc = ''; + + for ($i = 0; $i < count($sendcc); $i++) { $sendcc[$i] = trim($sendcc[$i]); - if ($sendcc[$i] == "") - continue; - + if ($sendcc[$i] == '') { + continue; + } + $sendcc[$i] = sqimap_find_email($sendcc[$i]); - $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]); - $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]); - + $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']); + $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']); + if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) && (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) && - (trim($sendcc[$i]) != "")) { - $send_to_cc .= trim($sendcc[$i]) . ", "; + (trim($sendcc[$i]) != '')) { + $send_to_cc .= trim($sendcc[$i]) . ', '; } - } - $send_to_cc = trim($send_to_cc); - if (substr($send_to_cc, -1) == ",") { + } + $send_to_cc = trim($send_to_cc); + if (substr($send_to_cc, -1) == ',') { $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1); - } - } - } // function newMail() - - function showInputForm () { - global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body, - $passed_body, $color, $use_signature, $signature, $editor_size, - $attachments, $subject, $newmail, $use_javascript_addr_book, - $send_to_bcc, $reply_id, $mailbox, $from_htmladdr_search; - - $subject = sqStripSlashes(decodeHeader($subject)); - $reply_subj = decodeHeader($reply_subj); - $forward_subj = decodeHeader($forward_subj); - $body = sqStripSlashes($body); - - if ($use_javascript_addr_book) { - echo "\n\n\n"; - } - - echo "\n
"; - do_hook("compose_bottom"); - } - - function showSentForm () { - echo "