Open Bug 1850289 Opened 2 years ago Updated 2 months ago

onNewMailReceived listener unreliable

Categories

(Thunderbird :: Add-Ons: Extensions API, defect, P2)

Thunderbird 115

Tracking

(Not tracked)

REOPENED
137 Branch

People

(Reporter: 52qtuqm9, Assigned: TbSync)

References

Details

Attachments

(2 files)

I add a listener with messenger.messages.onNewMailReceived.addListener in my add-on when it loads. Then after adding the listener I scan all the messages currently in the user's inbox to catch any that were there before I added the listener. Nonetheless, I subsequently discovered that there are messages in the user's inbox that my add-on never saw, because they didn't show up in the scan of all messages in the folder and my listener was never called about them.

Jury's still out on whether the listener is unreliable in general or just during this startup period.

See Also: → 1824889

More data about this. I received an email at 17:57 tonight. It went into my inbox. Remote Content By Folder (my add-on) should have received a listener call about it. It never did.

My guess is that the message came in while my laptop was sleeping and for some reason the listener isn't being called on messages that come in when Thunderbird is "catching up" after being offline for a while. This may be the same reason why the listener isn't being called for messages that come in right when Thunderbird starts up.

(In reply to Jonathan Kamens from comment #1)

My guess is that the message came in while my laptop was sleeping and for some reason the listener isn't being called on messages that come in when Thunderbird is "catching up" after being offline for a while. This may be the same reason why the listener isn't being called for messages that come in right when Thunderbird starts up.

This could be related to bug 1850679.

See Also: → 1850679

@Jonathan: Are you using an OAUTH IMAP account (like GMAIL)? Are you able to reproduce this with a normal non-OAUTH IMAP account?

This is happening with a regular username/password IMAP account. On a Cyrus IMAPd server, specifically.

Every workaround I've tried for this problem has failed. It doesn't seem to be restricted to startup and offline -> online transitions. For whatever reason, I am frequently not getting notifications for all new messages that come into my inbox. The next theory I'm going to test when I have a few minutes to code it is that sometimes when multiple emails come in at the same time the notification doesn't include all of them. If that's the case then the workaround is going to be to rescan at least my entire inbox every time I get a notification.

Depends on: 1850679

Any news on solid steps to reproduce this issue? Is it also happening when the laptop was not sleeping?

Summary: onNewMailReceived listener unreliable → onNewMailReceived listener unreliable when
Summary: onNewMailReceived listener unreliable when → onNewMailReceived listener unreliable

I don't know anything more about why this is happening or how to reproduce it. All I can tell you is it seems to happen pretty often. I eventually gave up on relying on the events and coded my extension to scan folders regularly looking for messages it didn't get notified about.

As far as I can tell, the event is fired only if messages land in the Inbox folder, i.e. when messages aren't moved to other folders by filters.
According to the api docs this is not the expected behaviour

https://webextension-api.thunderbird.net/en/latest/messages.html#onnewmailreceived

Fired when a new message is received, and has been through junk classification and message filters.

As far as I can tell, the event is fired only if messages land in the Inbox folder

That's bug 1848787, which is different from this bug.

(In reply to Jonathan Kamens from comment #8)

As far as I can tell, the event is fired only if messages land in the Inbox folder

That's bug 1848787, which is different from this bug.

Hi Jonathan, no it isn't. That bug is about special folders other than Inbox. My complaint is about the reliability of onNewMailReceived for normal folders (i.e. subfolders of Inbox).
Why is the event not triggered if an email is received and a filter moves it to a subfolder of Inbox?

Well, if you don't think it's bug 1848787, fine, but it's not this bug. This bug is specifically about emails that absolutely should have been notified about, that don't fall into the filter problem you're mentioning, but notifications still weren't received.

If you're reliably seeing messages moved by filters not getting notified about, that's a different bug. I suggest you open a new bug for it.

(In reply to Jonathan Kamens from comment #10)

Well, if you don't think it's bug 1848787, fine, but it's not this bug. This bug is specifically about emails that absolutely should have been notified about, that don't fall into the filter problem you're mentioning, but notifications still weren't received.

If you're reliably seeing messages moved by filters not getting notified about, that's a different bug. I suggest you open a new bug for it.

Jonathan I see your point. I have followed your advice and opened a new bug 1864870.

Priority: -- → P2

I tested this with 128.6.1esr and 135.0b4.
It seems that the problem occurs when the new mail notification is not displayed.
I identified two cases, thought there may be others (such as the one mentioned in comment 1):

  1. The "Show an alert" option in "When new messages arrive" is unchecked.
  2. Clicking on the "Get new messages" button

I was able to reproduce the issue consistently.

You can find the full thread in the add-on dev room.

The BiffState approach turned out to be cumbersome, specifically if
filters are involved. Instead of using the BiffState property, we now
simply report new messages which have the new flag set.

We keep the original behavior to bunch up multiple new message events
per folder.

Assignee: nobody → john
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attached file onNewMailReceived.xpi

This add-on includes an Experiment which uses the same mechanism as the new implementation introduced in D237936. It can be installed in Thunderbird 128 ESR to try out if any messages are still missed, without having to wait for the patch to be backported from Thunderbird Daily to Thunderbird 128 ESR.

Testing is appreciated, thanks!

The add-on will print an entry for each received message to the console.

I attempted to plug the experiment into Remote Content By Folder but it appears that the event listener is getting passed an array of message subjects instead of a MessageList? Given that I don't think I can test this in real-world conditions.

I wanted to go the extra mile and provide a self-contained technology demonstrator, which cannot do any harm and can be easily tested. I cannot provide a drop-in replacement, as that needs extensive testing and may introduce unwanted side effects if used in real add-ons.

To allow real-world testing with your add-on, I started a try-run where you could pull executables of the patched build:
https://treeherder.mozilla.org/jobs?repo=try-comm-central&revision=d9eef29dbe3f543118c8b493ceab2126f68dd04a

Removing the dependency from Bug 1850679, as we no longer depend on BiffState information: A BiffState event only gives us the original folder, "inbox" for example, but if the message is moved by filters into a different folders (not being a sub-folder of the original folder), before junk classification, the current system does not know where the message is and cannot report it.

No longer depends on: 1850679

(In reply to John Bieling (:TbSync) from comment #16)

I wanted to go the extra mile and provide a self-contained technology demonstrator, which cannot do any harm and can be easily tested. I cannot provide a drop-in replacement, as that needs extensive testing and may introduce unwanted side effects if used in real add-ons.

To allow real-world testing with your add-on, I started a try-run where you could pull executables of the patched build:
https://treeherder.mozilla.org/jobs?repo=try-comm-central&revision=d9eef29dbe3f543118c8b493ceab2126f68dd04a

Thanks! I will test for a week and report back.

Attachment #9465786 - Attachment description: Bug 1850289 - Change implementation of messages.onNewMailReceived event to no longer use BiffState. r=#thunderbird-reviewers → Bug 1850289 - Change implementation of messages.onNewMailReceived event to no longer use BiffState. r=mkmelin
Target Milestone: --- → 137 Branch

Pushed by john@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/73ba995def58
Change implementation of messages.onNewMailReceived event to no longer use BiffState. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED

Reopening because I am still not receiving notifications for all new messages.

For example, this morning when I launched Thunderbird (the try version you gave me to test) I received two emails one right after the other, as indicated by the IMAP Order Received column. I have two different extensions installed that use onNewMailReceived. As far as I can tell, both of these extensions were only notified about one of those two messages.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: