Page:
0004 decouple rfc codecs from mailbox gateway
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
0004 decouple rfc codecs from mailbox gateway
MailSweep Doc Bot edited this page 2026-08-24 02:23:29 +00:00
Table of Contents
4. Decouple RFC Codecs & Envelopes from MailboxGateway
Date: 2026-08-24
Status
Accepted
Context
MailSweep performs MIME header decoding (RFC 2047), Modified UTF-7 IMAP folder name encoding/decoding (RFC 3501), List-Unsubscribe extraction (RFC 2369 / RFC 8058), and zero-dependency .env configuration parsing.
Previously, these codec functions lived inside src/mailsweep/gateway.py alongside the active IMAP network connection logic and protocol commands (MailboxGateway). This introduced architectural friction:
- Offline modules (
BackupArchive,SafetyAuditor,UnsubscribeHub,cli.py) had to import fromgateway.pymerely to decode MIME strings or folder names, coupling offline file inspection to network gateway code. gateway.pymaintained circular import guards (TYPE_CHECKINGand lazy inside-function imports ofBackupArchiveandCleanupPlan).gateway.pybecame bloated (>1,000 lines) with mixed responsibilities.
Decision
We decoupled all pure RFC text transformations and configuration parsing into a dedicated domain module:
-
src/mailsweep/codecs.py(RFC Codecs & Envelopes):decode_mime_header(s: str) -> str: Multi-pass RFC 2047 MIME decoder.decode_imap_utf7(s: str) -> str: RFC 3501 Modified UTF-7 folder name decoder.parse_unsubscribe_header(header_val: str) -> str: RFC 2369 / RFC 8058 unsubscription URL extractor.load_env(env_path: Path | str) -> dict[str, str]: Zero-dependency.envparser.
-
Clean Seams Across Modules:
archive.py,audit.py,unsubscribe.py, andcli.pyimport directly frommailsweep.codecswithout touchinggateway.py.gateway.pyimports codecs frommailsweep.codecsand focuses strictly on IMAP connection lifecycles, protocol commands, and mailbox operations.- Re-exported codec functions via
src/mailsweep/__init__.py.
-
Domain Vocabulary:
- Formally registered RFC Codecs & Envelopes in
CONTEXT.md.
- Formally registered RFC Codecs & Envelopes in
Consequences
- Offline tools (archive inspection, safety audits, local brand aggregation) operate completely independently of IMAP network gateway code.
- Pure in-memory unit testing for all codecs with zero mocks or network abstractions.
- Clean module boundaries and elimination of circular import workarounds.