Page:
ADR 0005 collapse workflow into mailbox pipeline
Pages
0001 deepen classification safety auditor
0002 deepen rules registry
0003 prune legacy script shims
0004 decouple rfc codecs from mailbox gateway
0005 collapse workflow into mailbox pipeline
0006 decouple gateway orchestration into pipeline
0007 incremental scan cache and progress feedback
0008 port mailsweep to synchronous rust
0009 retire python baseline and complete rust cutover
0010 automated multi platform forgejo release workflow
ADR 0001 deepen classification safety auditor
ADR 0002 deepen rules registry
ADR 0003 prune legacy script shims
ADR 0004 decouple rfc codecs from mailbox gateway
ADR 0005 collapse workflow into mailbox pipeline
ADR 0006 decouple gateway orchestration into pipeline
ADR 0007 incremental scan cache and progress feedback
ADR 0008 port mailsweep to synchronous rust
ADR 0009 retire python baseline and complete rust cutover
ADR 0010 automated multi platform forgejo release workflow
ADRs
CLI Reference
Domain Context
FAQ
Home
Internals
Python API
Rules Schema
Rust API
No results
1
ADR 0005 collapse workflow into mailbox pipeline
MailSweep Doc Bot edited this page 2026-08-24 02:23:29 +00:00
5. Collapse Workflow Coordination into Mailbox Pipeline Domain Module
Date: 2026-08-24
Status
Accepted
Context
MailSweep provides operations for scanning headers (MailboxGateway.scan), evaluating clutter heuristics (ClassificationEngine.create_plan), auditing safety tier compliance (SafetyAuditor.audit), streaming offline backups (MailboxGateway.backup / BackupArchive), and executing mailbox cleanup (MailboxGateway.execute_cleanup).
Previously, coordinating these distinct operations was delegated entirely to callers and the CLI (src/mailsweep/cli.py):
- Callers had to manually coordinate intermediate serialization files (
scan_summary.json,targets_to_delete.json) on disk to bridge data across steps. - Programmatic consumers and headless automation (cron jobs, library scripts) had to replicate 50+ lines of connection management, UIDVALIDITY verification, and error handling.
- Test suites had to orchestrate multiple distinct domain models and mock disk files to verify full-lifecycle behavior.
- Business logic (percentage metrics, safety pre-flight assertions, backup verification before deletion) leaked into CLI entrypoints.
Decision
We deepened the end-to-end lifecycle orchestration into a domain module:
-
MailboxPipeline(src/mailsweep/pipeline.py):- Encapsulates
MailboxGateway,ClassificationEngine,SafetyAuditor, andBackupArchivebehind a unified deep interface. - Accepts injected instances for in-memory testing (
MailboxPipeline(gateway, engine=None, auditor=None)). - Provides a context-managed production factory:
with MailboxPipeline.connect(config, transport=None) as pipeline:. - Offers atomic execution via
pipeline.sweep(...) -> SweepSummaryReportas well as cohesive step operations (scan(),plan(),audit(),backup(),clean()). - Supports optional disk persistence paths (
save_summary=...,save_plan=...) while keeping intermediate data flow 100% in-memory by default. - Enforces pre-flight safety gating (verifying UIDVALIDITY snapshot match and asserting clean audit or verified backup before allowing destructive cleanup).
- Encapsulates
-
SweepSummaryReport:- Pure, immutable domain model encapsulating
ScanResult,CleanupPlan,BackupArchive | None,CleanupReport,SafetyAuditReport | None, and elapsed duration. - Formats human-readable CLI outputs via
.render_text()and JSON metrics via.to_dict().
- Pure, immutable domain model encapsulating
-
CLI Integration & Console Command:
- Registered
mailsweep sweepsubcommand insrc/mailsweep/cli.pyfor one-shot automated execution. - Streamlined individual subcommands (
mailsweep scan,mailsweep plan,mailsweep backup,mailsweep clean) to delegate throughMailboxPipeline.
- Registered
-
Domain Vocabulary:
- Formally registered Mailbox Pipeline and Sweep Summary Report in
CONTEXT.md.
- Formally registered Mailbox Pipeline and Sweep Summary Report in
Consequences
- Full mailbox lifecycle can be executed in-memory or headless via a single method call.
- Zero disk round-trips required between pipeline stages.
- Pre-flight safety invariants are strictly enforced inside the domain module, preventing accidental unsafe deletions.
- Full testability with
FakeImapTransportin under 0.05 seconds with zero mock disk I/O.