2

Since the filtering is not the best I wanted to implement my own filter.

browser.messages.onNewMailReceived.addListener(function(folder, messageList) {

if(folder.accountId == "account1") {
    if(folder.path == "/INBOX") {

        console.log("Folder", typeof folder, folder);
        console.log("MessageList", typeof messageList, messageList);

        let messages = messageList.messages;

        for(let i = 0; i < messages.length; i++) {
            
            let message = messages[i];

            console.log("Message", typeof message, message);
            message.flagged = true;
        }

        messageList.messages = [];
    } else {    
        // Ignored not in inbox
    }
} else {
    // Ignored
}
});

I Expected that everytime I recieve a new message, the 'messageList' only contains new messages. But it will also contain messages from previous events. Is it a normal behaviour, do I need to mark the message as "was processd by this handler" or something like that, is it an error in the API?

dark_982
  • 171
  • 2
  • 13
  • 1
    The doc isn't explicit, but for what it's worth, my understanding is that you should get new messages only. Maybe a bug, have you considered searching for relevant bugs or reporting it [on Bugzilla](https://bugzilla.mozilla.org/enter_bug.cgi?product=Thunderbird)? – Qeole Dec 02 '20 at 14:36
  • 1
    @Qeole good idea but first short search for "onNewMailReceived" only returns one result, I will look into it more later by ty – dark_982 Dec 02 '20 at 18:05
  • 1
    Not the issue here, but watch out: browser.messages.onNewMailReceived is undefined if the permissions "messagesRead" and "accountsRead" are not both set in the manifest. – David Spector Jul 28 '22 at 00:47

0 Answers0