From 89d99387f7b72b5f629266c61c733974014cfdea Mon Sep 17 00:00:00 2001 From: Sukhbir Singh Date: Sat, 13 Jan 2018 00:44:14 -0500 Subject: [feat] Display encryption status when viewing a message Display a notification bar in the message pane if the message was encrypted for messages in the "Inbox" folder. For messages in the "Sent" folder, we have placeholder code for displaying the message state and for adding custom headers if required. However, we need to understand how to handle the case for multiple recipients with different encryption states since it's possible to send encrypted messages to recipients with known keys but the same message will be send unencrypted to recipients whose keys are not known. In such a case we can display the message status per-recipient. --- .../accountWizard/bitmaskMessengerOverlay.js | 62 +++++++++++++++++++--- .../accountWizard/bitmaskMessengerOverlay.xul | 12 +++-- chrome/content/bitmask.js | 13 +++++ chrome/content/messengercompose.js | 29 ++++++++++ .../en-US/bitmaskMessengerOverlay.properties | 2 + chrome/skin/accountWizard.css | 5 ++ 6 files changed, 113 insertions(+), 10 deletions(-) diff --git a/chrome/content/accountWizard/bitmaskMessengerOverlay.js b/chrome/content/accountWizard/bitmaskMessengerOverlay.js index 148290c..31e7887 100644 --- a/chrome/content/accountWizard/bitmaskMessengerOverlay.js +++ b/chrome/content/accountWizard/bitmaskMessengerOverlay.js @@ -1,10 +1,50 @@ -window.addEventListener("load", function() { - overlayStartup(); -}, false); +var { interfaces: Ci, utils: Cu, classes: Cc } = Components; -window.setInterval(function() { - overlayStartup(); -}, 3000); +Cu.import("resource:///modules/imServices.jsm"); +Cu.import("resource:///modules/imXPCOMUtils.jsm"); + +XPCOMUtils.defineLazyGetter(this, "_", () => + l10nHelper("chrome://bitmask/locale/bitmaskMessengerOverlay.properties") +); + +var notificationBar = { + onStartHeaders: function() { + let currentFolder = gFolderDisplay.displayedFolder.name; + if (currentFolder === "Inbox") { + let promise = bitmask.mail.msg_status(gFolderDisplay.displayedFolder.username, + currentFolder.toUpperCase(), + gFolderDisplay.selectedMessage.messageId); + promise.then(function(data) { + // If the message was encrypted, display the notification bar. + let result = data["secured"]; + if (result === true) { + document.getElementById("msgNotificationBar").collapsed = false; + document.getElementById("bitmaskDescription").value = _("bitmaskMsgEncrypted"); + } else { + document.getElementById("msgNotificationBar").collapsed = true; + } + }, function(error) { + // Something went wrong, like the message was not found. + document.getElementById("msgNotificationBar").collapsed = true; + }); + } + }, + + onEndHeaders: function() { + }, + + load: function() { + // Update the notification bar when the selected message changes. + gMessageListeners.push(notificationBar); + // This is borrowed from Lightning so that we can hide the notification + // bar in case the folder is changed. + notificationBar.tbHideMessageHeaderPane = HideMessageHeaderPane; + HideMessageHeaderPane = function() { + document.getElementById("msgNotificationBar").collapsed = true; + notificationBar.tbHideMessageHeaderPane.apply(null, arguments); + }; + } +} function overlayStartup() { let myPanel = document.getElementById("bitmaskStatusBarPanel"); @@ -14,7 +54,7 @@ function overlayStartup() { // authorize with it using the token from bitmask.js let promise = bitmask.core.status(); promise.then(function(data) { - myPanel.label = strBundle.getFormattedString("bitmaskStatusOn", [ data["mail"] ]); + myPanel.label = _("bitmaskStatusOn", data["mail"]); myPanel.style.color = "green"; myPanel.src = "chrome://bitmask/skin/on.png"; }, function(error) { @@ -24,3 +64,11 @@ function overlayStartup() { console.log(error); }); } + +window.addEventListener("load", function() { + overlayStartup(); +}, false); + +window.setInterval(function() { overlayStartup(); }, 3000); + +window.addEventListener("messagepane-loaded", notificationBar.load, true); diff --git a/chrome/content/accountWizard/bitmaskMessengerOverlay.xul b/chrome/content/accountWizard/bitmaskMessengerOverlay.xul index da906f6..57967e3 100644 --- a/chrome/content/accountWizard/bitmaskMessengerOverlay.xul +++ b/chrome/content/accountWizard/bitmaskMessengerOverlay.xul @@ -1,5 +1,9 @@ + + + +