I realize there are a number of libraries to access IMAP, from Java, Python, etc. But what I want to do is very specific, and is counter to most imap examples.
The easy parts:
- Given an IMAP server, login, and specific folder name
- Nuke all messages in that folder (Or Nuke the folder, if that's easier or more efficient?)
The atypical parts:
- Do an expunge after every N deletes
- Include some retry and batch size logic so that busy servers - even deleting and expunging 100 messages per session would be a help.
- DON'T download all the headers!
That last point is a problem. Every email client I've tried chokes on downloading the 20,000 email headers - which I don't need to see.
With POP3 scripting I've just given sequential IDs, 1, 2, 3 ...
But every IMAP example I've seen appears to use some field that it got from the headers. So maybe deleting IMAP messages requires an ID that you can't guess at? (and can only get by doing a query?)
If I did need to get headers, can this at least be made as compact as possible? Or let me do just 100 at a time?
Alternatively, I've tried to delete an entire folder via email client UI's, but this doesn't seem to work. I think it's trying to move all the headers to the trash first, and fails at that, so never gets to the expunge part. So I'm not sure that deleting a folder is actually more efficient than deleting its contents.
Any thoughts appreciated. I usually work in Java or Python, but I'm flexible. I think this is a protocol issue, not a library issue.