Bug 1644032 - Ignore accountId from message headers when converting folders for WebExt APIs. r=darktrojan
authorJohn Bieling <john@thunderbird.net>
Wed, 25 Nov 2020 15:57:00 +0100
changeset 95748 508b9ca35fac86bb69aed35998ed4dce81b39634
parent 95747 f56bb2d0ec9843355ee36403352406533c8ce886
child 95749 f030255f85456f7fb434edc82da9d338ea011dba
child 95752 75d7bbd322cc6c229ae7744c40ea008ca433331f
child 95784 cebb5fb3c92a1e4ca7089888cc3530ed084eac39
push id12264
push userremotenonsense@gmail.com
push dateFri, 27 Nov 2020 01:30:43 +0000
treeherdertry-comm-central@723fcea4519c [default view] [failures only]
reviewersdarktrojan
bugs1644032
Bug 1644032 - Ignore accountId from message headers when converting folders for WebExt APIs. r=darktrojan Additional code comments by darktrojan.
mail/components/extensions/parent/ext-mail.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -1499,17 +1499,21 @@ const folderTypeMap = new Map([
   [Ci.nsMsgFolderFlags.Trash, "trash"],
   [Ci.nsMsgFolderFlags.Templates, "templates"],
   [Ci.nsMsgFolderFlags.Archive, "archives"],
   [Ci.nsMsgFolderFlags.Junk, "junk"],
   [Ci.nsMsgFolderFlags.Queue, "outbox"],
 ]);
 
 /**
- * Converts an nsIMsgFolder to a simple object for use in messages.
+ * Converts an nsIMsgFolder to a simple object for use in API messages.
+ *
+ * @param {nsIMsgFolder} folder - The folder to convert.
+ * @param {string} [accountId] - An optimization to avoid looking up the
+ *     account. The value from nsIMsgHdr.accountKey must not be used here.
  * @return {Object}
  */
 function convertFolder(folder, accountId) {
   if (!folder) {
     return null;
   }
   if (!accountId) {
     let server = folder.server;
@@ -1528,24 +1532,29 @@ function convertFolder(folder, accountId
       folderObject.type = typeName;
     }
   }
 
   return folderObject;
 }
 
 /**
- * Traverses a nsIMsgFolder to get all subfolders.
+ * Converts an nsIMsgFolder and all subfolders to a simple object for use in
+ * API messages.
+ *
+ * @param {nsIMsgFolder} folder - The folder to convert.
+ * @param {string} [accountId] - An optimization to avoid looking up the
+ *     account. The value from nsIMsgHdr.accountKey must not be used here.
  * @return {Array}
  */
-function traverseSubfolders(folder) {
-  let f = convertFolder(folder);
+function traverseSubfolders(folder, accountId) {
+  let f = convertFolder(folder, accountId);
   f.subFolders = [];
   for (let subFolder of fixIterator(folder.subFolders, Ci.nsIMsgFolder)) {
-    f.subFolders.push(traverseSubfolders(subFolder));
+    f.subFolders.push(traverseSubfolders(subFolder, accountId || f.accountId));
   }
   return f;
 }
 
 class FolderManager {
   constructor(extension) {
     this.extension = extension;
   }
@@ -1588,17 +1597,17 @@ function convertMessage(msgHdr, extensio
     bccList: composeFields.splitRecipients(msgHdr.bccList, false),
     subject: msgHdr.mime2DecodedSubject,
     read: msgHdr.isRead,
     flagged: msgHdr.isFlagged,
     junk: junkScore >= gJunkThreshold,
     junkScore,
   };
   if (extension.hasPermission("accountsRead")) {
-    messageObject.folder = convertFolder(msgHdr.folder, msgHdr.accountKey);
+    messageObject.folder = convertFolder(msgHdr.folder);
   }
   let tags = msgHdr.getProperty("keywords");
   tags = tags ? tags.split(" ") : [];
   messageObject.tags = tags.filter(MailServices.tags.isValidKey);
   return messageObject;
 }
 
 /**