imap-cleanupis a command-line tool for inspecting and cleaning up IMAP mailboxes. It reports folder sizes and account quotas, can find and delete messages by date or size, and can delete whole folders.
- Python (see version)
- uv
- An IMAP account. App-specific passwords are recommended when your provider supports them.
Clone the repository and install dependencies:
git clone https://github.com/jonlabelle/imap-cleanup.git
cd imap-cleanup
uv sync --devList all mailboxes sorted by size:
uv run imap-cleanup foldersCredentials are loaded from a
.envfile or environment variables. See Configuration for setup details.
folders— List all mailboxes sorted by size, with optional quota usage.delete— Dry-run or mark messages deleted from a mailbox by date, size, or both.delete-folder— Dry-run or delete an entire mailbox/folder, optionally including child folders.
See Examples for worked end-to-end usage.
Requires uv. Simply run uv sync --dev to install dependencies and get started.
The CLI is built on imaplib and argparse from the standard library.
Commands
uv sync --dev # Install dependencies
uv build # Build wheel distribution in dist/
uv run ruff check . # Lint
uv run ruff format --check . # Check formatting
uv run ruff format . # Format code
uv run mypy . # Type check
uv run pytest # Run testsVS Code
This repository includes VS Code tasks and launch configurations for the local uv workflow.
Useful tasks:
uv: sync— Install dependenciesuv: check all— Lint, format check, type check, and run testsuv: pytest— Run testsuv: ruff format— Format code with Ruffuv: build package— Build wheel distribution indist/imap-cleanup: folders— Run thefolderscommandimap-cleanup: folders json— Run thefolderscommand with JSON outputimap-cleanup: delete preview— Preview messages inArchivebefore2025-01-01imap-cleanup: delete preview json— Preview the same delete filter with JSON outputimap-cleanup: delete folder dry run— Check theOld Projectsfolder before deletionimap-cleanup: delete folder dry run json— Check the same folder with JSON outputimap-cleanup: delete folder recursive dry run— CheckOld Projectsand child folders before deletion
Debug launch configurations:
imap-cleanup: folders— Run thefolderscommandimap-cleanup: folders json— Run thefolderscommand with JSON outputimap-cleanup: delete preview— Preview messages inArchivebefore2025-01-01imap-cleanup: delete preview json— Preview the same delete filter with JSON outputimap-cleanup: delete folder dry run— Check theOld Projectsfolder before deletionimap-cleanup: delete folder dry run json— Check the same folder with JSON outputimap-cleanup: delete folder recursive dry run— CheckOld Projectsand child folders before deletion
The delete preview and delete-folder entries are dry-run configurations and do not pass --execute.