Bug 1697075 - Handle null result from MsgHdrToMimeMessage in messages API. r=john.bieling
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 09 Mar 2021 15:32:11 +1300
changeset 31887 4181feb3184df5c85fca77ba2c10cb36aef1891c
parent 31886 4127a04a72f374808f1deb1feaf80ff04463bcfa
child 31888 183cfa8604828b2b1f10440f20f4e9db5ba24761
push id18541
push usergeoff@darktrojan.net
push dateTue, 09 Mar 2021 09:54:53 +0000
treeherdercomm-central@4181feb3184d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohn.bieling
bugs1697075
Bug 1697075 - Handle null result from MsgHdrToMimeMessage in messages API. r=john.bieling This brings the result of MsgHdrToMimeMessage out to the main function and throws if it's null. It should prevent convertMessagePart failing but if it does the failure will at least be returned to the extension. Differential Revision: https://phabricator.services.mozilla.com/D107593
mail/components/extensions/parent/ext-messages.js
--- a/mail/components/extensions/parent/ext-messages.js
+++ b/mail/components/extensions/parent/ext-messages.js
@@ -202,28 +202,32 @@ this.messages = class extends ExtensionA
         },
         async get(messageId) {
           return convertMessage(
             messageTracker.getMessage(messageId),
             context.extension
           );
         },
         async getFull(messageId) {
-          return new Promise(resolve => {
+          let mimeMsg = await new Promise(resolve => {
             let msgHdr = messageTracker.getMessage(messageId);
             MsgHdrToMimeMessage(
               msgHdr,
               null,
               (_msgHdr, mimeMsg) => {
-                resolve(convertMessagePart(mimeMsg));
+                resolve(mimeMsg);
               },
               null,
               { examineEncryptedParts: true }
             );
           });
+          if (!mimeMsg) {
+            throw new ExtensionError(`Error reading message ${messageId}`);
+          }
+          return convertMessagePart(mimeMsg);
         },
         async getRaw(messageId) {
           let messenger = Cc["@mozilla.org/messenger;1"].createInstance(
             Ci.nsIMessenger
           );
           let msgHdr = messageTracker.getMessage(messageId);
           let msgUri = msgHdr.folder.generateMessageURI(msgHdr.messageKey);
           let service = messenger.messageServiceFromURI(msgUri);