Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:50:35+00:00 2026-06-08T15:50:35+00:00

I realize there are a number of libraries to access IMAP, from Java, Python,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:50:39+00:00Added an answer on June 8, 2026 at 3:50 pm

    Assuming you’re not using an atypical server (like gmail which is quite atypical) you can do these commands, after LOGIN, and SELECT [folder]:

    A001 STORE 1:N +FLAGS (\Deleted)
    A002 EXPUNGE
    A003 STORE 1:N +FLAGS (\Deleted)
    A004 EXPUNGE
    

    And so on, where you replace N with your batch size. This will not use the trash folder (unless your IMAP server has special logic, like Gmail: for gmail, tweak your IMAP access settings).

    You should be able to do this:

    A001 STORE 1:* +FLAGS (\Deleted)
    A002 EXPUNGE
    

    That may take a while though.

    In fact, you can use a tool like socat to login and speak the protocol yourself:

    socat READLINE: OPENSSL:[server]:993,noverify,crlf
    a LOGIN [user] "[password]"
    b SELECT [folder]
    

    And then the store and expunge commands from above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize there is a very interesting technique, to get Context in Android in
I realize there are similar questions on this topic, but I still cannot find
I realize there are similar posts to this out there, but rest assured, this
I want to store short arrays in a field. (I realize there are reasons
I realize that there are many similar questions, but most involve scaling down the
According the decoder sample in Windows SDK, I realize myself decoder MFT, but there
So I realize this is a possible duplicate question, as there a number of
I realize that each browser would implement it differently, but are there any references
I realize there have already been a number of posts on n-tier design and
I would like to quickly send email from the command line. I realize there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.