Bug 1598332 - Extend messages.update API function to mark messages as junk or not junk. r=darktrojan DONTBUILD
authorhermar <hermar05@web.de>
Tue, 26 Nov 2019 14:49:13 +0100
changeset 28302 e1257b911bd102b9983595dd3d0fd93ca999bbb9
parent 28301 19b64e4885d44150e8d098872d15e359a9acbbe4
child 28303 375496910e9269c869326127e20186740d4a4259
push id16755
push usergeoff@darktrojan.net
push dateTue, 03 Dec 2019 09:17:40 +0000
treeherdercomm-central@e1257b911bd1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdarktrojan
bugs1598332
Bug 1598332 - Extend messages.update API function to mark messages as junk or not junk. r=darktrojan DONTBUILD
mail/components/extensions/parent/ext-messages.js
mail/components/extensions/schemas/messages.json
mail/components/extensions/test/xpcshell/test_ext_messages.js
--- a/mail/components/extensions/parent/ext-messages.js
+++ b/mail/components/extensions/parent/ext-messages.js
@@ -267,16 +267,26 @@ this.messages = class extends ExtensionA
             return;
           }
           if (newProperties.read !== null) {
             msgHdr.markRead(newProperties.read);
           }
           if (newProperties.flagged !== null) {
             msgHdr.markFlagged(newProperties.flagged);
           }
+          if (newProperties.junk !== null) {
+            let messages = Cc["@mozilla.org/array;1"].createInstance(
+              Ci.nsIMutableArray
+            );
+            let score = newProperties.junk
+              ? Ci.nsIJunkMailPlugin.IS_SPAM_SCORE
+              : Ci.nsIJunkMailPlugin.IS_HAM_SCORE;
+            messages.appendElement(msgHdr);
+            msgHdr.folder.setJunkScoreForMessages(messages, score);
+          }
           if (Array.isArray(newProperties.tags)) {
             newProperties.tags = newProperties.tags.filter(
               MailServices.tags.isValidKey
             );
             msgHdr.setProperty("keywords", newProperties.tags.join(" "));
             for (let window of Services.wm.getEnumerator("mail:3pane")) {
               window.OnTagsChange();
             }
--- a/mail/components/extensions/schemas/messages.json
+++ b/mail/components/extensions/schemas/messages.json
@@ -171,16 +171,21 @@
             "name": "newProperties",
             "type": "object",
             "properties": {
               "read": {
                 "type": "boolean",
                 "description": "Marks the message as read or unread.",
                 "optional": true
               },
+              "junk": {
+                "type": "boolean",
+                "optional": true,
+                "description": "Marks the message as junk or not junk."
+              },
               "flagged": {
                 "type": "boolean",
                 "description": "Marks the message as flagged or unflagged.",
                 "optional": true
               },
               "tags": {
                 "type": "array",
                 "description": "Sets the tags on the message. For a list of available tags, call the listTags method.",
--- a/mail/components/extensions/test/xpcshell/test_ext_messages.js
+++ b/mail/components/extensions/test/xpcshell/test_ext_messages.js
@@ -109,26 +109,31 @@ 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.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 });
       await awaitMessage("read");
 
+      // Test that setting junk works.
+      await browser.messages.update(message.id, { junk: true });
+      await awaitMessage("junk");
+
       // Test that setting one tag works.
       await browser.messages.update(message.id, { tags: [tags[0].key] });
       await awaitMessage("tags1");
 
       // Test that setting two tags works.
       await browser.messages.update(message.id, {
         tags: [tags[1].key, tags[2].key],
       });
@@ -137,16 +142,17 @@ add_task(async function test_update() {
       // Test that unspecified properties aren't changed.
       await browser.messages.update(message.id, {});
       await awaitMessage("empty");
 
       // Test that clearing properties works.
       await browser.messages.update(message.id, {
         flagged: false,
         read: false,
+        junk: false,
         tags: [],
       });
       await awaitMessage("clear");
 
       browser.test.notifyPass("finished");
     },
     manifest: {
       permissions: ["messagesRead"],
@@ -164,16 +170,20 @@ add_task(async function test_update() {
   await extension.awaitMessage("flagged");
   ok(message.isFlagged);
   extension.sendMessage();
 
   await extension.awaitMessage("read");
   ok(message.isRead);
   extension.sendMessage();
 
+  await extension.awaitMessage("junk");
+  equal(message.getStringProperty("junkscore"), 100);
+  extension.sendMessage();
+
   await extension.awaitMessage("tags1");
   equal(message.getProperty("keywords"), "$label1");
   extension.sendMessage();
 
   await extension.awaitMessage("tags2");
   equal(message.getProperty("keywords"), "$label2 $label3");
   extension.sendMessage();
 
@@ -181,16 +191,17 @@ add_task(async function test_update() {
   ok(message.isFlagged);
   ok(message.isRead);
   equal(message.getProperty("keywords"), "$label2 $label3");
   extension.sendMessage();
 
   await extension.awaitMessage("clear");
   ok(!message.isFlagged);
   ok(!message.isRead);
+  equal(message.getStringProperty("junkscore"), 0);
   equal(message.getProperty("keywords"), "");
   extension.sendMessage();
 
   await extension.awaitFinish("finished");
   await extension.unload();
 });
 
 add_task(async function test_move_copy_delete() {