From 041c93ce0bc00cb6417ce2e4bdce2ed84d37f50a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Tue, 22 May 2012 06:31:37 -0400 Subject: [PATCH] Removed $Id$ --- program/steps/mail/compose.inc | 167 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 114 insertions(+), 53 deletions(-) diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index cbef368..306de36 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -17,9 +17,6 @@ +-----------------------------------------------------------------------+ | Author: Thomas Bruederli <roundcube@gmail.com> | +-----------------------------------------------------------------------+ - - $Id$ - */ // define constants for message compose mode @@ -29,7 +26,6 @@ define('RCUBE_COMPOSE_EDIT', 0x0109); $MESSAGE_FORM = null; -$MESSAGE = null; $COMPOSE_ID = get_input_value('_id', RCUBE_INPUT_GET); $COMPOSE = null; @@ -119,7 +115,11 @@ } // redirect to a unique URL with all parameters stored in session - $OUTPUT->redirect(array('_action' => 'compose', '_id' => $COMPOSE['id'])); + $OUTPUT->redirect(array( + '_action' => 'compose', + '_id' => $COMPOSE['id'], + '_search' => $_REQUEST['_search'], + )); } @@ -181,7 +181,7 @@ $MESSAGE = new rcube_message($msg_uid); // make sure message is marked as read - if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN'])) + if ($MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN'])) $RCMAIL->storage->set_flag($msg_uid, 'SEEN'); if (!empty($MESSAGE->headers->charset)) @@ -240,6 +240,9 @@ if (!empty($COMPOSE['param']['attachment'])) $MESSAGE->forward_attachment = true; } +} +else { + $MESSAGE = new stdClass(); } $MESSAGE->compose = array(); @@ -587,10 +590,10 @@ $html_editor = intval($RCMAIL->config->get('htmleditor')); if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) { - $useHtml = $MESSAGE->has_html_part(); + $useHtml = $MESSAGE->has_html_part(false); } else if ($compose_mode == RCUBE_COMPOSE_REPLY) { - $useHtml = ($html_editor == 1 || ($html_editor == 2 && $MESSAGE->has_html_part())); + $useHtml = ($html_editor == 1 || ($html_editor == 2 && $MESSAGE->has_html_part(false))); } else { // RCUBE_COMPOSE_FORWARD or NEW $useHtml = ($html_editor == 1); @@ -622,40 +625,21 @@ } // reply/edit/draft/forward else if ($compose_mode) { - $has_html_part = $MESSAGE->has_html_part(); $isHtml = rcmail_compose_editor_mode(); - if ($isHtml) { - if ($has_html_part) { - $body = $MESSAGE->first_html_part(); - } - else { - $body = $MESSAGE->first_text_part(); - // try to remove the signature - if ($RCMAIL->config->get('strip_existing_sig', true)) - $body = rcmail_remove_signature($body); - // add HTML formatting - $body = rcmail_plain_body($body); - if ($body) - $body = '<pre>' . $body . '</pre>'; + if (!empty($MESSAGE->parts)) { + foreach ($MESSAGE->parts as $part) { + if ($part->type != 'content' || !$part->size) { + continue; + } + + if ($part_body = rcmail_compose_part_body($part, $isHtml)) { + $body .= ($body ? ($isHtml ? '<br/>' : "\n") : '') . $part_body; + } } } else { - if ($has_html_part) { - // use html part if it has been used for message (pre)viewing - // decrease line length for quoting - $len = $compose_mode == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH; - $txt = new html2text($MESSAGE->first_html_part(), false, true, $len); - $body = $txt->get_text(); - } - else { - $body = $MESSAGE->first_text_part($part); - if ($body && $part && $part->ctype_secondary == 'plain' - && $part->ctype_parameters['format'] == 'flowed' - ) { - $body = rcube_mime::unfold_flowed($body); - } - } + $body = rcmail_compose_part_body($MESSAGE, $isHtml); } // compose reply-body @@ -692,6 +676,70 @@ return $body; } +function rcmail_compose_part_body($part, $isHtml = false) +{ + global $RCMAIL, $MESSAGE, $compose_mode; + + // Check if we have enough memory to handle the message in it + // #1487424: we need up to 10x more memory than the body + if (!rcmail_mem_check($part->size * 10)) { + return ''; + } + + if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset'])) { + $part->ctype_parameters['charset'] = $MESSAGE->headers->charset; + } + + // fetch part if not available + if (!isset($part->body)) { + $part->body = $MESSAGE->get_part_content($part->mime_id); + } + + // message is cached but not exists (#1485443), or other error + if ($part->body === false) { + return ''; + } + + $body = $part->body; + + if ($isHtml) { + if ($part->ctype_secondary == 'html') { + } + else { + // try to remove the signature + if ($RCMAIL->config->get('strip_existing_sig', true)) { + $body = rcmail_remove_signature($body); + } + // add HTML formatting + $body = rcmail_plain_body($body); + if ($body) { + $body = '<pre>' . $body . '</pre>'; + } + } + } + else { + if ($part->ctype_secondary == 'html') { + // use html part if it has been used for message (pre)viewing + // decrease line length for quoting + $len = $compose_mode == RCUBE_COMPOSE_REPLY ? $LINE_LENGTH-2 : $LINE_LENGTH; + $txt = new html2text($body, false, true, $len); + $body = $txt->get_text(); + } + else { + if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') { + $body = rcube_mime::unfold_flowed($body); + } + + // try to remove the signature + if ($RCMAIL->config->get('strip_existing_sig', true)) { + $body = rcmail_remove_signature($body); + } + } + } + + return $body; +} + function rcmail_compose_body($attrib) { global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode, $LINE_LENGTH, $HTML_MODE, $MESSAGE_BODY; @@ -719,7 +767,9 @@ // If desired, set this textarea to be editable by TinyMCE if ($isHtml) { + $MESSAGE_BODY = htmlentities($MESSAGE_BODY, ENT_NOQUOTES, RCMAIL_CHARSET); $attrib['class'] = 'mce_editor'; + $attrib['is_escaped'] = true; $textarea = new html_textarea($attrib); $out .= $textarea->show($MESSAGE_BODY); } @@ -739,14 +789,14 @@ // include HTML editor rcube_html_editor(); - // include GoogieSpell + // Set language list if (!empty($CONFIG['enable_spellcheck'])) { $engine = $RCMAIL->config->get('spellcheck_engine','googie'); $dictionary = (bool) $RCMAIL->config->get('spellcheck_dictionary'); $spellcheck_langs = (array) $RCMAIL->config->get('spellcheck_languages', array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', - 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska')); + 'pt'=>'Português', 'ru'=>'Русский', 'fi'=>'Suomi', 'sv'=>'Svenska')); // googie works only with two-letter codes if ($engine == 'googie') { @@ -768,11 +818,15 @@ if (!$spellcheck_langs[$lang]) $lang = 'en'; + $OUTPUT->set_env('spell_langs', $spellcheck_langs); + $OUTPUT->set_env('spell_lang', $lang); + $editor_lang_set = array(); foreach ($spellcheck_langs as $key => $name) { $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key); } + // include GoogieSpell $OUTPUT->include_script('googiespell.js'); $OUTPUT->add_script(sprintf( "var googie = new GoogieSpell('%s/images/googiespell/','%s&lang=', %s);\n". @@ -784,7 +838,7 @@ "googie.lang_learn_word = \"%s\";\n". "googie.setLanguages(%s);\n". "googie.setCurrentLanguage('%s');\n". - "googie.setSpellContainer('spellcheck-control');\n". + "googie.setDecoration(false);\n". "googie.decorateTextarea('%s');\n". "%s.set_env('spellcheck', googie);", $RCMAIL->output->get_skin_path(), @@ -827,10 +881,6 @@ if (!$bodyIsHtml) { $body = preg_replace('/\r?\n/', "\n", $body); - - // try to remove the signature - if ($RCMAIL->config->get('strip_existing_sig', true)) - $body = rcmail_remove_signature($body); // soft-wrap and quote message text $body = rcmail_wrap_and_quote(rtrim($body, "\n"), $LINE_LENGTH); @@ -955,7 +1005,8 @@ { global $RCMAIL; - $len = strlen($body); + $body = str_replace("\r\n", "\n", $body); + $len = strlen($body); $sig_max_lines = $RCMAIL->config->get('sig_max_lines', 15); while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) { @@ -1110,10 +1161,22 @@ $data = $message->get_part_content($pid); } + $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; + $filename = $part->filename; + if (!strlen($filename)) { + if ($mimetype == 'text/html') { + $filename = rcube_label('htmlmessage'); + } + else { + $filename = 'Part_'.$pid; + } + $filename .= '.' . $part->ctype_secondary; + } + $attachment = array( 'group' => $COMPOSE['id'], - 'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary, - 'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary, + 'name' => $filename, + 'mimetype' => $mimetype, 'content_id' => $part->content_id, 'data' => $data, 'path' => $path, @@ -1350,7 +1413,7 @@ $attrib['value'] = '1'; $checkbox = new html_checkbox($attrib); - if ($MESSAGE && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) + if (in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) $mdn_default = (bool) $MESSAGE->headers->mdn_to; else $mdn_default = $RCMAIL->config->get('mdn_default'); @@ -1476,7 +1539,7 @@ } -function rcmail_adressbook_list($attrib = array()) +function rcmail_addressbook_list($attrib = array()) { global $RCMAIL, $OUTPUT; @@ -1505,7 +1568,7 @@ $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id))); } - $OUTPUT->add_gui_object('adressbookslist', $attrib['id']); + $OUTPUT->add_gui_object('addressbookslist', $attrib['id']); return html::tag('ul', $attrib, $out, html::$common_attrib); } @@ -1541,10 +1604,8 @@ 'receiptcheckbox' => 'rcmail_receipt_checkbox', 'dsncheckbox' => 'rcmail_dsn_checkbox', 'storetarget' => 'rcmail_store_target_selection', - 'adressbooks' => 'rcmail_adressbook_list', + 'addressbooks' => 'rcmail_addressbook_list', 'addresslist' => 'rcmail_contacts_list', )); $OUTPUT->send('compose'); - - -- Gitblit v1.9.1