summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-10-06 17:15:38 +0000
committeralecpl <alec@alec.pl>2010-10-06 17:15:38 +0000
commit868deb5dabdc4d63210e4f53a2a80a904247af6a (patch)
treee5391d3273ca70bc7a4727ccc8db4bcdc401c2c2 /program/steps
parentace511a771656c983046919333cee501339c98a1 (diff)
- Make htmleditor option behaviour consistent, add option to use HTML on reply to HTML message (#1485840)
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/mail/compose.inc99
-rw-r--r--program/steps/settings/func.inc7
-rw-r--r--program/steps/settings/save_prefs.inc3
3 files changed, 67 insertions, 42 deletions
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,