Bug 1639683 - Fix the OpenPGP code that repairs broken messages from Exchange. r=PatrickBrunschwig
authorKai Engert <kaie@kuix.de>
Wed, 27 May 2020 22:50:05 +0200
changeset 39268 8a2e074a410b883616476d40b9a5fd0f7a6a79e4
parent 39267 f08360126dafebb18534edd9e28caf89666a2863
child 39269 d0d7797f534c718a9554e433abe61288a400b67a
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersPatrickBrunschwig
bugs1639683
Bug 1639683 - Fix the OpenPGP code that repairs broken messages from Exchange. r=PatrickBrunschwig Differential Revision: https://phabricator.services.mozilla.com/D77295
mail/base/content/msgOpenPGPKey.inc.xhtml
mail/extensions/openpgp/content/modules/fixExchangeMsg.jsm
mail/extensions/openpgp/content/strings/bond.ftl
mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js
--- a/mail/base/content/msgOpenPGPKey.inc.xhtml
+++ b/mail/base/content/msgOpenPGPKey.inc.xhtml
@@ -1,16 +1,29 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-                        <hbox id="openpgpKeyBox" hidden="true">
-                          <label id="hasKeyOpenPGP" data-l10n-id="openpgp-has-sender-key"/>
-                            <toolbarbutton id="openpgpImportButton"
-                                           data-l10n-id="openpgp-import-sender-key"
-                                           oncommand="Enigmail.msg.importAutocryptKeydata();"/>
-                        </hbox>
-                        <hbox id="signatureKeyBox" hidden="true">
-                          <label id="missingSignatureKey" data-l10n-id="openpgp-missing-signature-key"/>
-                          <toolbarbutton id="searchSignatureKeyButton"
-                                         data-l10n-id="openpgp-search-signature-key"
-                                         oncommand="Enigmail.msg.searchSignatureKey();"/>
-                        </hbox>
+  <hbox id="openpgpKeyBox" hidden="true">
+    <label id="hasKeyOpenPGP" data-l10n-id="openpgp-has-sender-key"/>
+      <toolbarbutton id="openpgpImportButton"
+                     data-l10n-id="openpgp-import-sender-key"
+                     oncommand="Enigmail.msg.importAutocryptKeydata();"/>
+  </hbox>
+  <hbox id="signatureKeyBox" hidden="true">
+    <label id="missingSignatureKey" data-l10n-id="openpgp-missing-signature-key"/>
+    <toolbarbutton id="searchSignatureKeyButton"
+                   data-l10n-id="openpgp-search-signature-key"
+                   oncommand="Enigmail.msg.searchSignatureKey();"/>
+  </hbox>
+  <vbox id="brokenExchangeBox" flex="0" hidden="true" pack="center">
+    <hbox pack="center">
+      <vbox flex="1" pack="start">
+        <description id="brokenExchangeInfo" data-l10n-id="openpgp-broken-exchange-info"/>
+      </vbox>
+      <vbox flex="0" pack="center">
+        <toolbarbutton id="brokenExchangeRepairButton"
+                       data-l10n-id="openpgp-broken-exchange-repair"
+                       oncommand="Enigmail.msg.fixBuggyExchangeMail();"/>
+        <label id="brokenExchangeWait" data-l10n-id="openpgp-broken-exchange-wait"/>
+      </vbox>
+    </hbox>
+  </vbox>
--- a/mail/extensions/openpgp/content/modules/fixExchangeMsg.jsm
+++ b/mail/extensions/openpgp/content/modules/fixExchangeMsg.jsm
@@ -106,23 +106,23 @@ var EnigmailFixExchangeMsg = {
         );
 
         if (EnigmailLog.getLogLevel() > 5) {
           EnigmailLog.DEBUG(
             "*** start data ***\n'" + data + "'\n***end data***\n"
           );
         }
 
-        let { good, errorCode, msg } = self.getRepairedMessage(data);
+        let [ good, errorCode, msg ] = self.getRepairedMessage(data);
 
         if (!good) {
           reject(errorCode);
+        } else {
+          resolve(msg);
         }
-
-        resolve(msg);
       });
 
       try {
         let channel = EnigmailStreams.createChannel(url);
         channel.asyncOpen(s, null);
       } catch (e) {
         EnigmailLog.DEBUG(
           "fixExchangeMsg.jsm: getMessageBody: exception " + e + "\n"
--- a/mail/extensions/openpgp/content/strings/bond.ftl
+++ b/mail/extensions/openpgp/content/strings/bond.ftl
@@ -23,8 +23,13 @@ openpgp-has-sender-key = This message cl
 openpgp-import-sender-key = Import…
 
 openpgp-search-keys-openpgp =
     .label = Discover OpenPGP Key
 
 openpgp-missing-signature-key = Message was signed with a key that you don't have yet
 
 openpgp-search-signature-key = Discover…
+
+# Don't translate the terms "OpenPGP" and "MS-Exchange"
+openpgp-broken-exchange-info = This is an OpenPGP message that was apparently corrupted by MS-Exchange. If the message contents aren't shown as expected, you may click the button to attempt an automatic repair.
+openpgp-broken-exchange-repair = Repair message
+openpgp-broken-exchange-wait = Please wait ...
--- a/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
+++ b/mail/extensions/openpgp/content/ui/enigmailMessengerOverlay.js
@@ -372,30 +372,19 @@ Enigmail.msg = {
       // there are situations when evealBox is not yet present
       revealBox.setAttribute("hidden", !attachmentList ? "true" : "false");
     }
   },
 
   messageCleanup() {
     EnigmailLog.DEBUG("enigmailMessengerOverlay.js: messageCleanup\n");
 
-    var enigmailBox = document.getElementById("enigmailBox");
-
-    if (enigmailBox && !enigmailBox.collapsed) {
-      enigmailBox.setAttribute("collapsed", "true");
-
-      var statusText = document.getElementById("expandedEnigmailStatusText");
-      if (statusText) {
-        statusText.value = "";
-      }
-    }
-
-    let exchBox = document.getElementById("enigmailBrokenExchangeBox");
+    let exchBox = document.getElementById("brokenExchangeBox");
     if (exchBox) {
-      exchBox.setAttribute("collapsed", "true");
+      exchBox.setAttribute("hidden", "true");
     }
 
     let b = document.getElementById("openpgpKeyBox");
     if (b) {
       b.setAttribute("hidden", true);
       b.removeAttribute("keydata");
     }
 
@@ -1897,35 +1886,23 @@ Enigmail.msg = {
    * Fix broken PGP/MIME messages from MS-Exchange by replacing the broken original
    * message with a fixed copy.
    *
    * no return
    */
   fixBuggyExchangeMail() {
     EnigmailLog.DEBUG("enigmailMessengerOverlay.js: fixBuggyExchangeMail:\n");
 
-    function hideAndResetExchangePane() {
-      document
-        .getElementById("enigmailBrokenExchangeBox")
-        .setAttribute("collapsed", "true");
-      document
-        .getElementById("enigmailFixBrokenMessageProgress")
-        .setAttribute("collapsed", "true");
-      document
-        .getElementById("enigmailFixBrokenMessageButton")
-        .removeAttribute("collapsed");
+    document.getElementById("brokenExchangeRepairButton").setAttribute("hidden", true);
+    document.getElementById("brokenExchangeWait").removeAttribute("hidden");
+
+    function hideBrokenExchangePane() {
+      document.getElementById("brokenExchangeBox").setAttribute("hidden", true);
     }
 
-    document
-      .getElementById("enigmailFixBrokenMessageButton")
-      .setAttribute("collapsed", "true");
-    document
-      .getElementById("enigmailFixBrokenMessageProgress")
-      .removeAttribute("collapsed");
-
     let msg = gFolderDisplay.messageDisplay.displayedMessage;
 
     let p = EnigmailFixExchangeMsg.fixExchangeMessage(msg, this.buggyMailType);
     p.then(function(msgKey) {
       // display message with given msgKey
 
       EnigmailLog.DEBUG(
         "enigmailMessengerOverlay.js: fixBuggyExchangeMail: _success: msgKey=" +
@@ -1937,24 +1914,24 @@ Enigmail.msg = {
         let index = gFolderDisplay.view.dbView.findIndexFromKey(msgKey, true);
         EnigmailLog.DEBUG("  ** index = " + index + "\n");
 
         EnigmailTimer.setTimeout(function() {
           gFolderDisplay.view.dbView.selectMsgByKey(msgKey);
         }, 750);
       }
 
-      hideAndResetExchangePane();
+      hideBrokenExchangePane();
     });
     p.catch(function() {
       EnigmailDialog.alert(
         window,
         EnigmailLocale.getString("fixBrokenExchangeMsg.failed")
       );
-      hideAndResetExchangePane();
+      hideBrokenExchangePane();
     });
   },
 
   /**
    * Hide attachments containing OpenPGP keys
    */
   hidePgpKeys() {
     let keys = [];
--- a/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js
+++ b/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js
@@ -1184,19 +1184,19 @@ Enigmail.hdrView = {
           encToDetails,
           null,
           mimePartNumber
         );
       }
 
       if (uriSpec && uriSpec.search(/^enigmail:message\//) === 0) {
         // display header for broken MS-Exchange message
-        // Thunderbird
-        let ebeb = document.getElementById("enigmailBrokenExchangeBox");
-        ebeb.removeAttribute("collapsed");
+        document.getElementById("brokenExchangeBox").removeAttribute("hidden");
+        document.getElementById("brokenExchangeRepairButton").removeAttribute("hidden");
+        document.getElementById("brokenExchangeWait").setAttribute("hidden", true);
       }
     },
 
     processDecryptionResult(uri, actionType, processData, mimePartNumber) {
       EnigmailLog.DEBUG(
         "enigmailMsgHdrViewOverlay.js: EnigMimeHeaderSink.processDecryptionResult:\n"
       );
       EnigmailLog.DEBUG(