X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fcompose.php;h=898e63a7c4e015baacc6f732e239d7470448345f;hb=e69274846f4b8eb858e706f997676f3f34d1ee27;hp=0e7dcfbe78f93cfc2f339b4cd1ca226b1606e390;hpb=c5d828b34ad16d7eccc94db221ed3aaa7fc85feb;p=squirrelmail.git diff --git a/src/compose.php b/src/compose.php index 0e7dcfbe..898e63a7 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1,216 +1,421 @@ 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$ + */ + +/*****************************************************************/ +/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ +/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ +/*** + Base level indent should begin at left margin, as ***/ +/*** the require_once below looks. ***/ +/*** + All identation should consist of four space blocks ***/ +/*** + Tab characters are evil. ***/ +/*** + all comments should use "slash-star ... star-slash" ***/ +/*** style -- no pound characters, no slash-slash style ***/ +/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ +/*** ALWAYS USE { AND } CHARACTERS!!! ***/ +/*** + Please use ' instead of ", when possible. Note " ***/ +/*** should always be used in _( ) function calls. ***/ +/*** Thank you for your help making the SM code more readable. ***/ +/*****************************************************************/ + +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'); +} + +/* 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); + $send_to_cc = decodeHeader($send_to_cc); + $send_to_bcc = decodeHeader($send_to_bcc); + + 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 { + } + 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 ($forward_id) - $body = "$body$tmp\n"; - else - $body = "$body> $tmp\n"; + if (!$draft_id) { + sqWordWrap($body_ary[$i], $editor_size - 1); + } + $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" . + _("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; + } else if ($reply_id) { + $orig_from = decodeHeader($orig_header->from); + $body = getReplyCitation($orig_from) . $body; } - sqimap_mailbox_close($imapConnection); - return $body; - } - $send_to = sqStripSlashes($send_to); - - if (!$send_to) { + 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 = ereg_replace(";", ",", $send_to_cc); - $sendcc = explode(",", $send_to_cc); - $send_to_cc = ""; - - for ($i = 0; $i < count($sendcc); $i++) { + /* 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++) { $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 newMail() */ + + +function getAttachments($message) { + global $mailbox, $attachments, $attachment_dir, $imapConnection, + $ent_num, $forward_id, $draft_id, $username; + + if (isset($draft_id)) { + $id = $draft_id; + } else { + $id = $forward_id; + } - 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; + if (!$message) { + sqimap_mailbox_select($imapConnection, $mailbox); + $message = sqimap_get_message($imapConnection, $id, $mailbox); + } - $subject = sqStripSlashes(decodeHeader($subject)); - $reply_subj = decodeHeader($reply_subj); - $forward_subj = decodeHeader($forward_subj); + $hashed_attachment_dir = getHashedDir($username, $attachment_dir); + if (count($message->entities) == 0) { + if ($message->header->entity_id != $ent_num) { + $filename = decodeHeader($message->header->filename); - if ($use_javascript_addr_book) { - echo "\n\n\n"; - } + if ($filename == "") { + $filename = "untitled-".$message->header->entity_id; + } - echo "\n