There is method to subscribe to an inbox [0], but it's unclear to me what this will accomplish. I have a use case for monitoring an inbox and parsing mail based on various headers/content (eg: bounced, auto reply, abuse report). Does subscribe subscribe to new email events? Currently using node-imap [1] for these events.
Good question. People dealing with IMAP often get it wrong. Subscription in IMAP-lingo means if a mailbox folder is visible or not. Unsubscribe a folder - it is not visible in the folder listing. Subscribe to a folder - the folder is included in the folder listing. That's about it. As any new mailbox folder you create will be automatically subscribed to, you will never have to use the subscribe/unsubscribe commands for anything.
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.
[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.