[0] https://imapflow.com/module-imapflow-ImapFlow.html#mailboxSu...
[1] https://github.com/mscdex/node-imap
PS: Thanks for your work on nodemailer, using it in production for years now.
Another issue - new email events. These are triggered only for the currently selected folder. Anything that happens before or after you select a folder will not be informed about. You can overcome this by storing the largest UID value you have encountered so far, so if you select a folder and see that there are emails with larger UID values than the one you know about, these are all new emails. It gets trickier if you want similar information about deleted emails or flag changes, as there is no easy way to detect this information. The server does send you deleted emails and flag update events, but only for the currently selected folder. So any event that happens while the connection is closed (network error, app restart, IMAP server kicks the session due to AOuth2 token expiration) or you have selected a different mailbox folder will go under the radar. This is the main selling point of https://EmailEngine.app, as it keeps an index to detect changes on any folder and will send webhooks about these.
About the email events, that sounds like a great value prop for a third party service to abstract away. Will have a look at EmailEngine.