From 95298fa428a521a56443b7962a0c48927b1f864a Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Fri, 26 Jan 2018 11:12:39 +0100 Subject: [PATCH] Add option to encrypt & sign with Mailvelope > 2.0 UI elements added to larry and classic skin --- program/js/app.js | 32 +++++++++++++++++++++++++-- program/localization/en_US/labels.inc | 1 + skins/classic/functions.js | 6 ++++- skins/classic/templates/compose.html | 12 +++++++++- skins/larry/mail.css | 1 - skins/larry/styles.css | 1 + skins/larry/templates/compose.html | 12 +++++++++- skins/larry/ui.js | 6 ++++- 8 files changed, 64 insertions(+), 7 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 7764eaf1c..72ec0253d 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3564,7 +3564,11 @@ function rcube_webmail() ref.mailvelope_init(action, kr); }; - mailvelope.getKeyring(keyring).then(fn, function(err) { + mailvelope.getVersion().then(function(v) { + mailvelope.VERSION = v; + mailvelope.VERSION_MAJOR = Math.floor(parseFloat(v)); + return mailvelope.getKeyring(keyring); + }).then(fn, function(err) { // attempt to create a new keyring for this app/user mailvelope.createKeyring(keyring).then(fn, function(err) { console.error(err); @@ -3604,8 +3608,12 @@ function rcube_webmail() else if (action == 'compose') { this.env.compose_commands.push('compose-encrypted'); + var sign_supported = mailvelope.VERSION_MAJOR >= 2; var is_html = $('[name="_is_html"]').val() > 0; + if (sign_supported) + this.env.compose_commands.push('compose-encrypted-signed'); + if (this.env.pgp_mime_message) { // fetch PGP/Mime part and open load into Mailvelope editor var lock = this.set_busy(true, this.get_label('loadingdata')); @@ -3616,6 +3624,8 @@ function rcube_webmail() error: function(o, status, err) { ref.http_error(o, status, err, lock); ref.enable_command('compose-encrypted', !is_html); + if (sign_supported) + ref.enable_command('compose-encrypted-signed', !is_html); }, success: function(data) { ref.set_busy(false, null, lock); @@ -3627,24 +3637,38 @@ function rcube_webmail() ref.compose_encrypted({ quotedMail: data }); ref.enable_command('compose-encrypted', true); + ref.enable_command('compose-encrypted-signed', false); } }); } else { // enable encrypted compose toggle this.enable_command('compose-encrypted', !is_html); + if (sign_supported) + this.enable_command('compose-encrypted-signed', !is_html); } // make sure to disable encryption button after toggling editor into HTML mode this.addEventListener('actionafter', function(args) { - if (args.ret && args.action == 'toggle-editor') + if (args.ret && args.action == 'toggle-editor') { ref.enable_command('compose-encrypted', !args.props.html); + if (sign_supported) + ref.enable_command('compose-encrypted-signed', !args.props.html); + } }); } else if (action == 'edit-identity') { ref.mailvelope_identity_keygen(); } }; + // handler for the 'compose-encrypted-signed' command + this.compose_encrypted_signed = function(props) + { + props = props || {}; + props.signMsg = true; + this.compose_encrypted(props); + }; + // handler for the 'compose-encrypted' command this.compose_encrypted = function(props) { @@ -3677,6 +3701,10 @@ function rcube_webmail() options = { predefinedText: $('#' + this.env.composebody).val() }; } + if (props.signMsg) { + options.signMsg = props.signMsg; + } + if (this.env.compose_mode == 'reply') { options.quotedMailIndent = true; options.quotedMailHeader = this.env.compose_reply_header; diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc index cd778df99..c5ab3c69b 100644 --- a/program/localization/en_US/labels.inc +++ b/program/localization/en_US/labels.inc @@ -281,6 +281,7 @@ $labels['encryptmessage'] = 'Encrypt message'; $labels['encryptmessagemailvelope'] = 'Encrypt message with Mailvelope'; $labels['importpubkeys'] = 'Import public keys'; $labels['encryptedsendialog'] = 'Sending encrypted message'; +$labels['encryptandsign'] = 'Encrypt and sign'; $labels['keyid'] = 'Key ID'; $labels['keylength'] = 'Bits'; $labels['keyexpired'] = 'Expired'; diff --git a/skins/classic/functions.js b/skins/classic/functions.js index 3e98f9286..f5a47720b 100644 --- a/skins/classic/functions.js +++ b/skins/classic/functions.js @@ -665,7 +665,11 @@ enable_command: function(p) } else if (p.command == 'compose-encrypted') { // show the toolbar button for Mailvelope - $('#messagetoolbar > a.encrypt').show(); + $('#messagetoolbar a.encrypt').parent().show(); + } + else if (p.command == 'compose-encrypted-signed') { + // enable selector for encrypt and sign + $('#encryptionmenulink').show(); } }, diff --git a/skins/classic/templates/compose.html b/skins/classic/templates/compose.html index 97b39c498..f7c5a71ca 100644 --- a/skins/classic/templates/compose.html +++ b/skins/classic/templates/compose.html @@ -39,7 +39,10 @@   -