From a02c77c584906f629d382409e76f0df4d2cfaf01 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Fri, 15 Mar 2013 10:30:53 +0100 Subject: [PATCH] Add ability to toggle between view as HTML and text while viewing a message (#1486939) --- CHANGELOG | 1 + program/js/app.js | 13 +++++++++- program/localization/en_US/labels.inc | 2 ++ program/steps/mail/compose.inc | 19 ++++++++++---- program/steps/mail/show.inc | 27 ++++++++++++++++---- skins/classic/images/icons/html.png | Bin 0 -> 379 bytes skins/classic/images/icons/text.png | Bin 0 -> 372 bytes skins/classic/mail.css | 19 +++++++++----- skins/classic/templates/message.html | 8 ++++++ skins/classic/templates/messagepreview.html | 10 +++++++- 10 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 skins/classic/images/icons/html.png create mode 100644 skins/classic/images/icons/text.png diff --git a/CHANGELOG b/CHANGELOG index 6d0a959a6..42d6cc72a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Add ability to toggle between HTML and text while viewing a message (#1486939) - Better handling of session errors in ajax requests (#1488960) - Fix HTML part detection for some specific message structures (#1488992) - Don't show fake address - phishing prevention (#1488981) diff --git a/program/js/app.js b/program/js/app.js index 637d6f5d8..d3c319ecd 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -229,7 +229,7 @@ function rcube_webmail() this.env.message_commands = ['show', 'reply', 'reply-all', 'reply-list', 'moveto', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource', 'print', 'load-attachment', 'download-attachment', 'show-headers', 'hide-headers', 'download', - 'forward', 'forward-inline', 'forward-attachment']; + 'forward', 'forward-inline', 'forward-attachment', 'change-format']; if (this.env.action == 'show' || this.env.action == 'preview') { this.enable_command(this.env.message_commands, this.env.uid); @@ -608,6 +608,17 @@ function rcube_webmail() } break; + case 'change-format': + url = this.env.permaurl + '&_format=' + props; + + if (this.env.action == 'preview') + url = url.replace(/_action=show/, '_action=preview') + '&_framed=1'; + if (this.env.extwin) + url += '&_extwin=1'; + + location.href = url; + break; + case 'menu-open': if (props && props.menu == 'attachmentmenu') { var mimetype = this.env.attachments[props.id]; diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 61a13e9ab..252e0ce68 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -205,6 +205,8 @@ $labels['body'] = 'Body'; $labels['openinextwin'] = 'Open in new window'; $labels['emlsave'] = 'Download (.eml)'; +$labels['changeformattext'] = 'Display in plain text format'; +$labels['changeformathtml'] = 'Display in HTML format'; // message compose $labels['editasnew'] = 'Edit as new'; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 640272400..6a579f754 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -183,9 +183,18 @@ $LINE_LENGTH = $RCMAIL->config->get('line_length', 72); if (!empty($msg_uid) && empty($COMPOSE['as_attachment'])) { - // similar as in program/steps/mail/show.inc - // re-set 'prefer_html' to have possibility to use html part for compose - $CONFIG['prefer_html'] = $CONFIG['prefer_html'] || $CONFIG['htmleditor'] || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT; + $mbox_name = $RCMAIL->storage->get_folder(); + + // set format before rcube_message construction + // use the same format as for the message view + if (isset($_SESSION['msg_formats'][$mbox_name.':'.$msg_uid])) { + $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$msg_uid]); + } + else { + $prefer_html = $CONFIG['prefer_html'] || $CONFIG['htmleditor'] || $compose_mode == RCUBE_COMPOSE_DRAFT || $compose_mode == RCUBE_COMPOSE_EDIT; + $RCMAIL->config->set('prefer_html', $prefer_html); + } + $MESSAGE = new rcube_message($msg_uid); // make sure message is marked as read @@ -538,8 +547,8 @@ function rcmail_compose_editor_mode() function rcmail_message_is_html() { - global $MESSAGE; - return ($MESSAGE instanceof rcube_message) && $MESSAGE->has_html_part(true); + global $RCMAIL, $MESSAGE; + return $RCMAIL->config->get('prefer_html') && ($MESSAGE instanceof rcube_message) && $MESSAGE->has_html_part(true); } function rcmail_prepare_message_body() diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index 87555cbbe..552c180f5 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -19,7 +19,7 @@ +-----------------------------------------------------------------------+ */ -$PRINT_MODE = $RCMAIL->action=='print' ? TRUE : FALSE; +$PRINT_MODE = $RCMAIL->action == 'print' ? TRUE : FALSE; // Read browser capabilities and store them in session if ($caps = get_input_value('_caps', RCUBE_INPUT_GET)) { @@ -31,8 +31,21 @@ if ($caps = get_input_value('_caps', RCUBE_INPUT_GET)) { $_SESSION['browser_caps'] = $browser_caps; } +$uid = get_input_value('_uid', RCUBE_INPUT_GET); +$mbox_name = $RCMAIL->storage->get_folder(); + // similar code as in program/steps/mail/get.inc -if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { +if ($uid) { + // set message format (need to be done before rcube_message construction) + if (!empty($_GET['_format'])) { + $prefer_html = $_GET['_format'] == 'html'; + $RCMAIL->config->set('prefer_html', $prefer_html); + $_SESSION['msg_formats'][$mbox_name.':'.$uid] = $prefer_html; + } + else if (isset($_SESSION['msg_formats'][$mbox_name.':'.$uid])) { + $RCMAIL->config->set('prefer_html', $_SESSION['msg_formats'][$mbox_name.':'.$uid]); + } + $MESSAGE = new rcube_message($uid); // if message not found (wrong UID)... @@ -40,7 +53,6 @@ if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { rcmail_message_error($uid); } - $mbox_name = $RCMAIL->storage->get_folder(); // show images? rcmail_check_safe($MESSAGE); @@ -106,6 +118,11 @@ if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', 'movingmessage', 'deletingmessage', 'markingmessage'); + $prefer_html = $RCMAIL->config->get('prefer_html'); + if ($MESSAGE->has_html_part()) { + $OUTPUT->set_env('optional_format', $prefer_html ? 'text' : 'html'); + } + // check for unset disposition notification if ($MESSAGE->headers->mdn_to && empty($MESSAGE->headers->flags['MDNSENT']) @@ -288,9 +305,9 @@ $OUTPUT->add_handlers(array( )); -if ($RCMAIL->action=='print' && $OUTPUT->template_exists('messageprint')) +if ($RCMAIL->action == 'print' && $OUTPUT->template_exists('messageprint')) $OUTPUT->send('messageprint', false); -else if ($RCMAIL->action=='preview' && $OUTPUT->template_exists('messagepreview')) +else if ($RCMAIL->action == 'preview' && $OUTPUT->template_exists('messagepreview')) $OUTPUT->send('messagepreview', false); else $OUTPUT->send('message', false); diff --git a/skins/classic/images/icons/html.png b/skins/classic/images/icons/html.png new file mode 100644 index 0000000000000000000000000000000000000000..3f022f6786bcb3f013bec2a59405ac27ead7c776 GIT binary patch literal 379 zcmeAS@N?(olHy`uVBq!ia0vp^{2QL70(Y)*K0-AbW|YuPggqWUHSE}40^^8ML!Ydo7?PWgZ1?M+JtHBL3*Pv4(kzHa_5>43X)pZIn2eh;U6#_UIL z$t?LeldHD%lAEG)5^PLn|EaMu|9BO-=Li@oTG6+Yrm+;XS0uN1uIJ!WVSKZIyB@i zjXA!zI@iBCy8isDfQ{DY&O|h;GH5?YIpUgDCdvFwIgNky{B4ZuRy{oW<1hOM*1XkI VZ_a%+JrfuV44$rjF6*2UngF7PnQs69 literal 0 HcmV?d00001 diff --git a/skins/classic/images/icons/text.png b/skins/classic/images/icons/text.png new file mode 100644 index 0000000000000000000000000000000000000000..94891be80f11f481969c0db9d623ea0d8fe198de GIT binary patch literal 372 zcmeAS@N?(olHy`uVBq!ia0vp^{2QL70(Y)*K0-AbW|YuPggqWCvojHIB#^vaDTpX z_}9N_#Tt6n(>d!)87DY8ZnJW_{3rXs(KHvUy{j&*l6}&aeZVzH{D$epS6klid3(d} z+QQrCy32E?Sp79tU*B-rZu`cYu_xF+)~
+ diff --git a/skins/classic/templates/messagepreview.html b/skins/classic/templates/messagepreview.html index 935238edf..80dbe381a 100644 --- a/skins/classic/templates/messagepreview.html +++ b/skins/classic/templates/messagepreview.html @@ -9,7 +9,15 @@
- +