postalsys / imapflow

IMAP Client library for EmailEngine Email API (https://emailengine.app)
https://imapflow.com
Other
353 stars 59 forks source link

Are fetch() results cached in some way? #156

Closed ahaberbosch closed 8 months ago

ahaberbosch commented 9 months ago

I'm trying to narrow down the cause for a problem that only seems to manifest when a fetch request is sent first thing in the morning, around 6 a.m. local time. It seems that a fetch() for emails not long after the email is received in gmail doesn't return any result. I've used a for loop to keep trying the fetch every 5 seconds, and it still sometimes never finds it, but the same email clearly arrives in gmail not long afterward. When i try to reproduce the problem later in the day, it never appears to be an issue. I never see any errors or exceptions. I'm fairly certain it's not timezone issue because I have other code that will resend and, connect, reopen and retry again, and it will almost always work the 2nd time.

Could any improvement be made to the inner loop to close and reopen the inbox, or connect and reconnect between tries? Seems heavy-handed but i can't find anything obvious. I replaced imap-simple with imapFlow and never saw these types of issues so I think it's something particular to imapFlow.

andris9 commented 8 months ago

You need to refresh the result set by using idle, noop, or select. ImapFlow usually uses idle automatically if you open a folder and do not close it. This is not ImapFlow specific, but how IMAP works.