summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
Diffstat (limited to 'program')
-rw-r--r--program/include/rcube_message.php17
-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
4 files changed, 73 insertions, 53 deletions
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,