Bug 1610457 - Add junk and junkScore properties to message objects that are returned from APIs. r=mkmelin DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 29 Jan 2020 12:54:49 +0200
changeset 37154 66070529eac2ec0d93e3855674a3a6f87b132106
parent 37153 71a037b9e9cd27ad72740b45d5bf1f4d8c6e6d8d
child 37155 05e79793c4929689a83ccaf092ef15e026b26a6d
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1610457
Bug 1610457 - Add junk and junkScore properties to message objects that are returned from APIs. r=mkmelin DONTBUILD
mail/components/extensions/parent/ext-mail.js
mail/components/extensions/test/xpcshell/test_ext_messages.js
--- a/mail/components/extensions/parent/ext-mail.js
+++ b/mail/components/extensions/parent/ext-mail.js
@@ -1344,30 +1344,36 @@ class FolderManager {
 function convertMessage(msgHdr, extension) {
   if (!msgHdr) {
     return null;
   }
 
   let composeFields = Cc[
     "@mozilla.org/messengercompose/composefields;1"
   ].createInstance(Ci.nsIMsgCompFields);
+  let junkScore = parseInt(msgHdr.getProperty("junkscore"), 10) || 0;
+  let junkThreshold = Services.prefs.getIntPref(
+    "mail.adaptivefilters.junk_threshold"
+  );
 
   let messageObject = {
     id: messageTracker.getId(msgHdr),
     date: new Date(msgHdr.dateInSeconds * 1000),
     author: msgHdr.mime2DecodedAuthor,
     recipients: composeFields.splitRecipients(
       msgHdr.mime2DecodedRecipients,
       false
     ),
     ccList: composeFields.splitRecipients(msgHdr.ccList, false),
     bccList: composeFields.splitRecipients(msgHdr.bccList, false),
     subject: msgHdr.mime2DecodedSubject,
     read: msgHdr.isRead,
     flagged: msgHdr.isFlagged,
+    junk: junkScore >= junkThreshold,
+    junkScore,
   };
   if (extension.hasPermission("accountsRead")) {
     messageObject.folder = convertFolder(msgHdr.folder, msgHdr.accountKey);
   }
   let tags = msgHdr.getProperty("keywords");
   tags = tags ? tags.split(" ") : [];
   messageObject.tags = tags.filter(MailServices.tags.isValidKey);
   return messageObject;
--- a/mail/components/extensions/test/xpcshell/test_ext_messages.js
+++ b/mail/components/extensions/test/xpcshell/test_ext_messages.js
@@ -119,16 +119,17 @@ add_task(async function test_update() {
       let tags = await browser.messages.listTags();
       let [folder] = await awaitMessage();
       let messageList = await browser.messages.list(folder);
       browser.test.assertEq(1, messageList.messages.length);
       let message = messageList.messages[0];
       browser.test.assertFalse(message.flagged);
       browser.test.assertFalse(message.read);
       browser.test.assertFalse(message.junk);
+      browser.test.assertEq(0, message.junkScore);
       browser.test.assertEq(0, message.tags.length);
 
       // Test that setting flagged works.
       await browser.messages.update(message.id, { flagged: true });
       await awaitMessage("flagged");
 
       // Test that setting read works.
       await browser.messages.update(message.id, { read: true });
@@ -147,25 +148,41 @@ add_task(async function test_update() {
         tags: [tags[1].key, tags[2].key],
       });
       await awaitMessage("tags2");
 
       // Test that unspecified properties aren't changed.
       await browser.messages.update(message.id, {});
       await awaitMessage("empty");
 
+      message = await browser.messages.get(message.id);
+      browser.test.assertTrue(message.flagged);
+      browser.test.assertTrue(message.read);
+      browser.test.assertTrue(message.junk);
+      browser.test.assertEq(100, message.junkScore);
+      browser.test.assertEq(2, message.tags.length);
+      browser.test.assertEq(tags[1].key, message.tags[0]);
+      browser.test.assertEq(tags[2].key, message.tags[1]);
+
       // Test that clearing properties works.
       await browser.messages.update(message.id, {
         flagged: false,
         read: false,
         junk: false,
         tags: [],
       });
       await awaitMessage("clear");
 
+      message = await browser.messages.get(message.id);
+      browser.test.assertFalse(message.flagged);
+      browser.test.assertFalse(message.read);
+      browser.test.assertFalse(message.junk);
+      browser.test.assertEq(0, message.junkScore);
+      browser.test.assertEq(0, message.tags.length);
+
       browser.test.notifyPass("finished");
     },
     manifest: {
       permissions: ["messagesRead"],
     },
   });
 
   let message = [...subFolders[1].messages][0];