Skip to content

Conversation

@kingfly55
Copy link

Title: Refactor: Optimize IMAP deletions, fix server timeouts, and modernize codebase

Description:
This PR refactors the legacy AutoUnsubscriber script to address critical performance bottlenecks, server compatibility issues (specifically with Zoho/custom domains), and reliability concerns.

Key Changes:

  • Performance Optimization (Batching):

  • Implemented batch fetching (50 emails/chunk) in getEmails() to prevent socket error: EOF on large inboxes.

  • Implemented batch deletion in deleteEmails().

  • Moved EXPUNGE command outside the deletion loop to execute only once per session, significantly reducing server operations.

  • Server Compatibility:

  • Fixed search() command syntax (split arguments into a list) to comply with strict IMAP implementations (e.g., Zoho).

  • Added Manual IMAP Server Entry for custom domains that are not auto-detected.

  • Reliability & Safety:

  • Added tqdm progress bars for real-time feedback during scanning and deletion.

  • Added a strict "Type DELETE to confirm" safety check before removing any data.

  • Implemented proper logging instead of relying solely on print statements.

  • Added try/except blocks inside batch loops to prevent a single corrupt email from crashing the entire process.

Testing:

  • Tested on Zoho Mail with a custom domain.
  • Verified that "Socket/EOF" errors on large inboxes (9k+ emails) are resolved via batching.
  • Confirmed emails are correctly flagged as \Deleted and expunged.

Dependencies:

  • Added tqdm
  • Updated pyzmail to pyzmail36 (via uv instructions) for Python 3 compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants