Bug 1657497 - Allow opening the OpenPGP Key Manager without a default identity. r=mkmelin a=wsmwk
authorAlessandro Castellani <alessandro@thunderbird.net>
Fri, 07 Aug 2020 17:43:59 -0700
changeset 39666 1343440396c9378e525d969a92bd07ea0a15bdb1
parent 39665 007ff301665916576f7ab6556848de8284db0bea
child 39667 d45cbd67f0767ec936eca772ac89627ab6ffff9e
push id37
push userkaie@kuix.de
push dateTue, 11 Aug 2020 21:30:33 +0000
treeherdercomm-esr78@8bbe9af4c6f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, wsmwk
bugs1657497
Bug 1657497 - Allow opening the OpenPGP Key Manager without a default identity. r=mkmelin a=wsmwk
mail/extensions/am-e2e/am-e2e.js
mail/extensions/openpgp/content/ui/enigmailKeyManager.js
mail/extensions/openpgp/content/ui/keyWizard.js
mailnews/base/prefs/content/accountUtils.js
--- a/mail/extensions/am-e2e/am-e2e.js
+++ b/mail/extensions/am-e2e/am-e2e.js
@@ -574,17 +574,16 @@ function openKeyManager() {
   // Bug 1638153: The rootTreeItem object has been removed after 78. We need to
   // the availability of "browsingContext" to use the right DOM window in 79+.
   let w =
     "browsingContext" in window
       ? window.browsingContext.topChromeWindow
       : window.docShell.rootTreeItem.domWindow;
 
   let args = {
-    identity: gIdentity,
     cancelCallback: reloadOpenPgpUI,
     okCallback: reloadOpenPgpUI,
   };
 
   w.openDialog(
     "chrome://openpgp/content/ui/enigmailKeyManager.xhtml",
     "enigmail:KeyManager",
     "dialog,centerscreen,resizable",
--- a/mail/extensions/openpgp/content/ui/enigmailKeyManager.js
+++ b/mail/extensions/openpgp/content/ui/enigmailKeyManager.js
@@ -16,16 +16,19 @@
 /* global ENIG_KEY_DISABLED: false, ENIG_KEY_NOT_VALID: false, ENIG_LOCAL_FILE_CONTRACTID: false */
 /* global PgpSqliteDb2: false */
 
 // imported packages
 /* global EnigmailLog: false, EnigmailEvents: false, EnigmailKeyRing: false, EnigmailKeyEditor: false */
 /* global EnigmailKey: false, EnigmailLocale: false, EnigmailPrefs: false, EnigmailConstants: false */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+var { MailServices } = ChromeUtils.import(
+  "resource:///modules/MailServices.jsm"
+);
 
 var { EnigmailCore } = ChromeUtils.import(
   "chrome://openpgp/content/modules/core.jsm"
 );
 var { EnigmailStreams } = ChromeUtils.import(
   "chrome://openpgp/content/modules/streams.jsm"
 );
 var { EnigmailClipboard } = ChromeUtils.import(
@@ -62,17 +65,16 @@ var { uidHelper } = ChromeUtils.import(
   "chrome://openpgp/content/modules/uidHelper.jsm"
 );
 
 var l10n = new Localization(["messenger/openpgp/openpgp.ftl"], true);
 
 const INPUT = 0;
 const RESULT = 1;
 
-var gIdentity;
 var gUserList;
 var gKeyList;
 var gEnigLastSelectedKeys = null;
 var gKeySortList = null;
 var gSearchInput = null;
 var gTreeChildren = null;
 var gShowInvalidKeys = null;
 var gShowOthersKeys = null;
@@ -83,20 +85,16 @@ function enigmailKeyManagerLoad() {
   EnigmailLog.DEBUG("enigmailKeyManager.js: enigmailKeyManagerLoad\n");
 
   // Close the key manager if GnuPG is not available
   if (!EnigmailCore.getService(window)) {
     window.close();
     return;
   }
 
-  if (window.arguments[0]) {
-    gIdentity = window.arguments[0].identity || null;
-  }
-
   gUserList = document.getElementById("pgpKeyList");
   gSearchInput = document.getElementById("filterKey");
   gShowInvalidKeys = document.getElementById("showInvalidKeys");
   gShowOthersKeys = document.getElementById("showOthersKeys");
   gTreeFuncs = EnigmailCompat.getTreeCompatibleFuncs(gUserList, gKeyListView);
 
   window.addEventListener("reload-keycache", reloadKeys);
   EnigmailSearchCallback.setup(gSearchInput, gTimeoutId, applyFilter, 200);
@@ -274,16 +272,21 @@ function enigmailKeyMenu() {
     if (keyList.length === 0) {
       document.getElementById("bcNoKey").setAttribute("disabled", "true");
     } else {
       document.getElementById("bcNoKey").removeAttribute("disabled");
     }
     document.getElementById("bcOneKey").setAttribute("disabled", "true");
     document.getElementById("bcDeleteKey").setAttribute("disabled", "true");
   }
+
+  // Disable the "Generate key" menu item if no mail account is available.
+  document
+    .getElementById("genKey")
+    .setAttribute("disabled", MailServices.accounts.defaultAccount == null);
 }
 
 function onListClick(event) {
   if (event.detail > 2) {
     return;
   }
 
   if (event.type === "click") {
@@ -1323,17 +1326,16 @@ function openKeyWizard(isImport = false)
   // Bug 1638153: The rootTreeItem object has been removed after 78. We need to
   // the availability of "browsingContext" to use the right DOM window in 79+.
   let w =
     "browsingContext" in window
       ? window.browsingContext.topChromeWindow
       : window.docShell.rootTreeItem.domWindow;
 
   let args = {
-    identity: gIdentity,
     gSubDialog: null,
     cancelCallback: clearKeyCache,
     okCallback: clearKeyCache,
     okImportCallback: clearKeyCache,
     okExternalCallback: clearKeyCache,
     keyDetailsDialog: enigmailKeyDetails,
     isCreate: !isImport,
     isImport,
--- a/mail/extensions/openpgp/content/ui/keyWizard.js
+++ b/mail/extensions/openpgp/content/ui/keyWizard.js
@@ -78,17 +78,17 @@ document.addEventListener("dialogaccept"
 document.addEventListener("dialoghelp", goBack);
 document.addEventListener("dialogcancel", onClose);
 
 /**
  * Initialize the keyWizard dialog.
  */
 async function init() {
   gSubDialog = window.arguments[0].gSubDialog;
-  gIdentity = window.arguments[0].identity;
+  gIdentity = window.arguments[0].identity || null;
   gIdentityList = document.getElementById("userIdentity");
 
   kStartSection = document.getElementById("wizardStart");
   kDialog = document.querySelector("dialog");
 
   await initIdentity();
 
   // Show the GnuPG radio selection if the pref is enabled.
--- a/mailnews/base/prefs/content/accountUtils.js
+++ b/mailnews/base/prefs/content/accountUtils.js
@@ -6,17 +6,16 @@
 /* import-globals-from AccountManager.js */
 /* globals SelectFolder */ // From messageWindow.js or msgMail3PaneWindow.js.
 /* globals MsgGetMessage */ // From mailWindowOverlay.js.
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { MailServices } = ChromeUtils.import(
   "resource:///modules/MailServices.jsm"
 );
-var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 
 var gAnyValidIdentity = false; // If there are no valid identities for any account
 // returns the first account with an invalid server or identity
 
 var gNewAccountToLoad = null; // used to load new messages if we come from the mail3pane
 
 function getInvalidAccounts(accounts) {
   let invalidAccounts = [];
@@ -546,42 +545,24 @@ function updateMailPaneUI() {
   mail3Pane.document.getElementById("folderPaneBox").collapsed = false;
   mail3Pane.document.getElementById("folderpane_splitter").collapsed = false;
 }
 
 /**
  * Open the OpenPGP Key Manager from outside the Account Settings.
  */
 function openKeyManager() {
-  // Try to get the current identity based on the currently selected folder.
-  // This is necessary in case the user wants to generate a new key from within
-  // the Key Manager.
-  let identity;
-  if (typeof window.GetSelectedMsgFolders === "function") {
-    let folders = window.GetSelectedMsgFolders();
-    if (folders.length > 0) {
-      identity = MailUtils.getIdentityForServer(folders[0].server);
-    }
-  }
-  if (!identity && typeof window.GetDefaultAccountRootFolder === "function") {
-    let folder = window.GetDefaultAccountRootFolder();
-    if (folder instanceof Ci.nsIMsgFolder) {
-      identity = MailUtils.getIdentityForServer(folder.server);
-    }
-  }
-
   // Bug 1638153: The rootTreeItem object has been removed after 78. We need to
   // the availability of "browsingContext" to use the right DOM window in 79+.
   let w =
     "browsingContext" in window
       ? window.browsingContext.topChromeWindow
       : window.docShell.rootTreeItem.domWindow;
 
   let args = {
-    identity: identity[0],
     cancelCallback: null,
     okCallback: null,
   };
 
   w.openDialog(
     "chrome://openpgp/content/ui/enigmailKeyManager.xhtml",
     "enigmail:KeyManager",
     "dialog,centerscreen,resizable",