You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whenever I attempt to open [Gmail]/All Mail, after having opened either [Gmail]/Spam or [Gmail]/Trash I am getting a 'mail' event emitted by the connection object.
This is the sequence of events:
-> Open box `[Gmail]/Trash`
-> `[Gmail]/Trash` is opened
-> Open box `[Gmail]/All Mail`
-> ***'mail' event is emitted for `[Gmail]/Trash`*** (why?)
-> `[Gmail]/All Mail` is opened
I can work around this in my own code, but it would be great to have this fixed
It looks like before emitting the 'mail' event we are checking if the new message count is greater than the previous message count, and if it is, we will emit the event. However, this code is not taking into account when we are opening a new box, in which case its comparing the message count of the old box against the new box, instead of ensuring to compare the message counts within the same box.
In my case specifically, All Mail always has more messages than Trash or Spam, so if the current box is Spam or Trash, and I switch to All Mail, it will parse the EXISTS message and think that because the new count is greater than the last one it should emit the 'mail' event, when in fact it shouldn't because the new count corresponds to a different mailbox.
This seems like it would be a straightforward fix, but I am hesitant to try to submit a PR because I might be unaware of other constraints or assumptions in the code. I'd be happy to if you point me in the right direction.
The text was updated successfully, but these errors were encountered:
jstejada
changed the title
'mail' event fires when attempting to open [Gmail]/All Mail box after having opened another box
'mail' event fires when attempting to open box box after having opened another box
Jan 12, 2017
Whenever I attempt to open
[Gmail]/All Mail
, after having opened either[Gmail]/Spam
or[Gmail]/Trash
I am getting a'mail'
event emitted by the connection object.This is the sequence of events:
I can work around this in my own code, but it would be great to have this fixed
Here's the debug output
1. Opening
[Gmail]/Trash
2. Opening
[Gmail]/All Mail
After some more digging, the problem seems to be caused here: https://github.com/mscdex/node-imap/blob/master/lib/Connection.js#L1285
It looks like before emitting the
'mail'
event we are checking if the new message count is greater than the previous message count, and if it is, we will emit the event. However, this code is not taking into account when we are opening a new box, in which case its comparing the message count of the old box against the new box, instead of ensuring to compare the message counts within the same box.In my case specifically,
All Mail
always has more messages thanTrash
orSpam
, so if the current box isSpam
orTrash
, and I switch toAll Mail
, it will parse theEXISTS
message and think that because the new count is greater than the last one it should emit the'mail'
event, when in fact it shouldn't because the new count corresponds to a different mailbox.This seems like it would be a straightforward fix, but I am hesitant to try to submit a PR because I might be unaware of other constraints or assumptions in the code. I'd be happy to if you point me in the right direction.
Thanks @mscdex !
The text was updated successfully, but these errors were encountered: