diff options
author | alecpl <alec@alec.pl> | 2010-10-06 17:15:38 +0000 |
---|---|---|
committer | alecpl <alec@alec.pl> | 2010-10-06 17:15:38 +0000 |
commit | 868deb5dabdc4d63210e4f53a2a80a904247af6a (patch) | |
tree | e5391d3273ca70bc7a4727ccc8db4bcdc401c2c2 | |
parent | ace511a771656c983046919333cee501339c98a1 (diff) |
- Make htmleditor option behaviour consistent, add option to use HTML on reply to HTML message (#1485840)
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | config/main.inc.php.dist | 3 | ||||
-rw-r--r-- | installer/config.php | 10 | ||||
-rw-r--r-- | program/include/rcube_message.php | 17 | ||||
-rw-r--r-- | program/steps/mail/compose.inc | 99 | ||||
-rw-r--r-- | program/steps/settings/func.inc | 7 | ||||
-rw-r--r-- | program/steps/settings/save_prefs.inc | 3 |
7 files changed, 82 insertions, 58 deletions
@@ -19,6 +19,7 @@ CHANGELOG Roundcube Webmail - Fix keyboard doesn't work with autocomplete list with Chrome (#1487029) - Improve tabs to fixed width and add tabs in identities info (#1486974) - Add unique index on users.username+users.mail_host +- Make htmleditor option more consistent and add option to use HTML on reply to HTML message (#1485840) RELEASE 0.4.2 ------------- diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist index 00ba825c3..8ec7f08e4 100644 --- a/config/main.inc.php.dist +++ b/config/main.inc.php.dist @@ -479,7 +479,8 @@ $rcmail_config['prefer_html'] = true; $rcmail_config['show_images'] = 0; // compose html formatted messages by default -$rcmail_config['htmleditor'] = false; +// 0 - never, 1 - always, 2 - on reply to HTML message only +$rcmail_config['htmleditor'] = 0; // show pretty dates as standard $rcmail_config['prettydate'] = true; diff --git a/installer/config.php b/installer/config.php index f35c6c2c0..5250782f9 100644 --- a/installer/config.php +++ b/installer/config.php @@ -14,7 +14,6 @@ $RCI->bool_config_props = array( 'smtp_log' => 1, 'prefer_html' => 1, 'preview_pane' => 1, - 'htmleditor' => 1, 'debug_level' => 1, ); @@ -543,13 +542,16 @@ echo $check_prevpane->show(intval($RCI->getprop('preview_pane'))); <dt class="propname">htmleditor <span class="userconf">*</span></dt> <dd> +<label for="cfghtmlcompose">Compose HTML formatted messages</label> <?php -$check_htmlcomp = new html_checkbox(array('name' => '_htmleditor', 'id' => "cfghtmlcompose", 'value' => 1)); -echo $check_htmlcomp->show(intval($RCI->getprop('htmleditor'))); +$select_htmlcomp = new html_select(array('name' => '_htmleditor', 'id' => "cfghtmlcompose")); +$select_htmlcomp->add('never', 0); +$select_htmlcomp->add('always', 1); +$select_htmlcomp->add('on reply to HTML message only', 2); +echo $select_htmlcomp->show(intval($RCI->getprop('htmleditor'))); ?> -<label for="cfghtmlcompose">Compose HTML formatted messages</label><br /> </dd> <dt class="propname">draft_autosave <span class="userconf">*</span></dt> diff --git a/program/include/rcube_message.php b/program/include/rcube_message.php index 19f36b335..dfccb36e9 100644 --- a/program/include/rcube_message.php +++ b/program/include/rcube_message.php @@ -214,27 +214,21 @@ class rcube_message /** * Return the first text part of this message * + * @param rcube_message_part $part Reference to the part if found * @return string Plain text message/part content */ - function first_text_part() + function first_text_part(&$part=null) { // no message structure, return complete body if (empty($this->parts)) return $this->body; - $out = null; - // check all message parts foreach ($this->mime_parts as $mime_id => $part) { $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary; if ($mimetype == 'text/plain') { - $out = $this->imap->get_message_part($this->uid, $mime_id, $part); - - // re-format format=flowed content - if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') - $out = self::unfold_flowed($out); - break; + return $this->imap->get_message_part($this->uid, $mime_id, $part); } else if ($mimetype == 'text/html') { $out = $this->imap->get_message_part($this->uid, $mime_id, $part); @@ -245,11 +239,12 @@ class rcube_message // create instance of html2text class $txt = new html2text($out); - $out = $txt->get_text(); + return $txt->get_text(); } } - return $out; + $part = null; + return null; } diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index c69a0a12f..c1f491403 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -358,7 +358,6 @@ function rcmail_compose_headers($attrib) } } - if ($fname && $field_type) { // pass the following attributes to the form class @@ -491,48 +490,74 @@ function rcmail_compose_header_from($attrib) } -function rcmail_prepare_message_body() +function rcmail_compose_editor_mode() { - global $RCMAIL, $CONFIG, $MESSAGE, $compose_mode, $LINE_LENGTH, $HTML_MODE; + global $RCMAIL, $MESSAGE, $compose_mode; + static $useHtml; - if ($CONFIG['htmleditor'] || (($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) && $MESSAGE->has_html_part())) - $isHtml = true; - else - $isHtml = false; + if ($useHtml !== null) + return $useHtml; - $body = ''; + $html_editor = intval($RCMAIL->config->get('htmleditor')); + + if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) { + $useHtml = $MESSAGE->has_html_part(); + } + else if ($compose_mode == RCUBE_COMPOSE_REPLY) { + $useHtml = ($html_editor == 1 || ($html_editor == 2 && $MESSAGE->has_html_part())); + } + else { // RCUBE_COMPOSE_FORWARD or NEW + $useHtml = ($html_editor == 1); + } + + return $useHtml; +} + + +function rcmail_prepare_message_body() +{ + global $RCMAIL, $MESSAGE, $compose_mode, $LINE_LENGTH, $HTML_MODE; // use posted message body - if (!empty($_POST['_message'])) - { + if (!empty($_POST['_message'])) { $body = get_input_value('_message', RCUBE_INPUT_POST, true); + $isHtml = (bool) get_input_value('_is_html', RCUBE_INPUT_POST); } - else if ($_SESSION['compose']['param']['body']) - { + else if ($_SESSION['compose']['param']['body']) { $body = $_SESSION['compose']['param']['body']; $isHtml = false; } - else if ($compose_mode) - { + // reply/edit/draft/forward + else if ($compose_mode) { $has_html_part = $MESSAGE->has_html_part(); - if (($isHtml || $compose_mode == RCUBE_COMPOSE_DRAFT) && $has_html_part) - { - $body = $MESSAGE->first_html_part(); - $isHtml = true; - } - 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(); - $isHtml = false; + $isHtml = rcmail_compose_editor_mode(); + + if ($isHtml) { + if ($has_html_part) { + $body = $MESSAGE->first_html_part(); + } + else { + $body = rcmail_plain_body($MESSAGE->first_text_part()); + if ($body) + $body = '<pre>' . $body . '</pre>'; + } } - else - { - $body = $MESSAGE->first_text_part(); - $isHtml = false; + 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_message::unfold_flowed($body); + } + } } // compose reply-body @@ -545,6 +570,9 @@ function rcmail_prepare_message_body() else if ($compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) $body = rcmail_create_draft_body($body, $isHtml); } + else { // new message + $isHtml = rcmail_compose_editor_mode(); + } $plugin = $RCMAIL->plugins->exec_hook('message_compose_body', array('body' => $body, 'html' => $isHtml, 'mode' => $compose_mode)); @@ -1151,11 +1179,7 @@ function rcmail_editor_selector($attrib) global $CONFIG, $MESSAGE, $compose_mode; // determine whether HTML or plain text should be checked - if ($compose_mode) - $useHtml = (($CONFIG['htmleditor'] || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT) - && $MESSAGE->has_html_part()); - else - $useHtml = $CONFIG['htmleditor'] ? true : false; + $useHtml = rcmail_compose_editor_mode(); if (empty($attrib['editorid'])) $attrib['editorid'] = 'rcmComposeBody'; @@ -1172,8 +1196,7 @@ function rcmail_editor_selector($attrib) return $select->show($useHtml ? 'html' : 'plain'); - foreach ($choices as $value => $text) - { + foreach ($choices as $value => $text) { $attrib['id'] = '_' . $value; $attrib['value'] = $value; $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text))); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index 6717b2c09..a7d4c11f0 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -466,11 +466,14 @@ function rcmail_user_prefs($current=null) // Show checkbox for HTML Editor if (!isset($no_override['htmleditor'])) { $field_id = 'rcmfd_htmleditor'; - $input_htmleditor = new html_checkbox(array('name' => '_htmleditor', 'id' => $field_id, 'value' => 1)); + $select_htmleditor = new html_select(array('name' => '_htmleditor', 'id' => $field_id)); + $select_htmleditor->add(rcube_label('never'), 0); + $select_htmleditor->add(rcube_label('always'), 1); + $select_htmleditor->add(rcube_label('htmlonreply'), 2); $blocks['main']['options']['htmleditor'] = array( 'title' => html::label($field_id, Q(rcube_label('htmleditor'))), - 'content' => $input_htmleditor->show($config['htmleditor']?1:0), + 'content' => $select_htmleditor->show(intval($config['htmleditor'])), ); } diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index 4621427ee..ae3d6d704 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -58,11 +58,10 @@ switch ($CURR_SECTION) 'default_charset' => get_input_value('_default_charset', RCUBE_INPUT_POST), ); - break; case 'compose': $a_user_prefs = array( - 'htmleditor' => isset($_POST['_htmleditor']) ? TRUE : FALSE, + 'htmleditor' => intval($_POST['_htmleditor']), 'draft_autosave' => isset($_POST['_draft_autosave']) ? intval($_POST['_draft_autosave']) : 0, 'mime_param_folding' => isset($_POST['_mime_param_folding']) ? intval($_POST['_mime_param_folding']) : 0, 'force_7bit' => isset($_POST['_force_7bit']) ? TRUE : FALSE, |