From 44b47dfb359f8a7412208079202fca0adf741540 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Wed, 20 Aug 2014 08:30:24 +0200 Subject: Add config/preference option to disable saving messages in localStorage (#1489979) --- config/defaults.inc.php | 4 ++++ program/js/app.js | 9 +++++++-- program/localization/en_US/labels.inc | 1 + program/steps/mail/compose.inc | 1 + program/steps/settings/func.inc | 14 ++++++++++++++ program/steps/settings/save_prefs.inc | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/config/defaults.inc.php b/config/defaults.inc.php index 56791fb99..5e9a2bbdd 100644 --- a/config/defaults.inc.php +++ b/config/defaults.inc.php @@ -947,6 +947,10 @@ $config['compose_extwin'] = false; // 0 - never, 1 - always, 2 - on reply to HTML message, 3 - on forward or reply to HTML message $config['htmleditor'] = 0; +// save copies of compose messages in the browser's local storage +// for recovery in case of browser crashes and session timeout. +$config['compose_save_localstorage'] = true; + // show pretty dates as standard $config['prettydate'] = true; diff --git a/program/js/app.js b/program/js/app.js index 20ad93a1a..0fca47191 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3361,7 +3361,8 @@ function rcube_webmail() } // check for locally stored compose data - this.compose_restore_dialog(0, html_mode) + if (this.env.save_localstorage) + this.compose_restore_dialog(0, html_mode) if (input_to.val() == '') input_to.focus(); @@ -3793,7 +3794,7 @@ function rcube_webmail() } // save compose form content to local storage every 5 seconds - if (!this.local_save_timer && window.localStorage) { + if (!this.local_save_timer && window.localStorage && this.env.save_localstorage) { // track typing activity and only save on changes this.compose_type_activity = this.compose_type_activity_last = 0; $(document).bind('keypress', function(e){ ref.compose_type_activity++; }); @@ -3849,6 +3850,10 @@ function rcube_webmail() // store the contents of the compose form to localstorage this.save_compose_form_local = function() { + // feature is disabled + if (!this.env.save_localstorage) + return; + var formdata = { session:this.env.session_id, changed:new Date().getTime() }, ed, empty = true; diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index 449b278f8..a8d9abc13 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -484,6 +484,7 @@ $labels['2231folding'] = 'Full RFC 2231 (Thunderbird)'; $labels['miscfolding'] = 'RFC 2047/2231 (MS Outlook)'; $labels['2047folding'] = 'Full RFC 2047 (other)'; $labels['force7bit'] = 'Use MIME encoding for 8-bit characters'; +$labels['savelocalstorage'] = "Save in the browser's local storage (temporarily)"; $labels['advancedoptions'] = 'Advanced options'; $labels['toggleadvancedoptions'] = 'Toggle advanced options'; $labels['focusonnewmessage'] = 'Focus browser window on new message'; diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index a3c8a8a64..1770a1bcb 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -91,6 +91,7 @@ $OUTPUT->set_env('session_id', session_id()); $OUTPUT->set_env('mailbox', $RCMAIL->storage->get_folder()); $OUTPUT->set_env('top_posting', intval($RCMAIL->config->get('reply_mode')) > 0); $OUTPUT->set_env('recipients_separator', trim($RCMAIL->config->get('recipients_separator', ','))); +$OUTPUT->set_env('save_localstorage', (bool)$RCMAIL->config->get('compose_save_localstorage')); $drafts_mbox = $RCMAIL->config->get('drafts_mbox'); $config_show_sig = $RCMAIL->config->get('show_sig', 1); diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index 619710f32..0b2039a78 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -918,6 +918,20 @@ function rcmail_user_prefs($current = null) ); } + if (!isset($no_override['compose_save_localstorage'])) { + if (!$current) { + continue 2; + } + + $field_id = 'rcmfd_compose_save_localstorage'; + $input = new html_checkbox(array('name' => '_compose_save_localstorage', 'id' => $field_id, 'value' => 1)); + + $blocks['advanced']['options']['compose_save_localstorage'] = array( + 'title' => html::label($field_id, rcube::Q($RCMAIL->gettext('savelocalstorage'))), + 'content' => $input->show($config['compose_save_localstorage']?1:0), + ); + } + break; // Addressbook config diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc index 7a17f21f4..f0ce9c9a3 100644 --- a/program/steps/settings/save_prefs.inc +++ b/program/steps/settings/save_prefs.inc @@ -90,6 +90,7 @@ case 'compose': 'default_font_size' => rcube_utils::get_input_value('_default_font_size', rcube_utils::INPUT_POST), 'reply_all_mode' => intval($_POST['_reply_all_mode']), 'forward_attachment' => !empty($_POST['_forward_attachment']), + 'compose_save_localstorage' => intval($_POST['_compose_save_localstorage']), ); break; -- cgit v1.2.3