Page:
Internals
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
4
Internals
MailSweep Doc Bot edited this page 2026-08-30 16:44:17 +00:00
Table of Contents
MailSweep Architecture, Internals & Performance
This document describes performance optimizations, memory streaming, cryptographic validation, and security design in MailSweep.
1. Performance Optimizations
1.1 IMAP Header PEEK Batching
- Non-Destructive Fetching: MailSweep fetches email metadata with the
BODY.PEEKcommand:
TheBODY.PEEK[HEADER.FIELDS (SUBJECT FROM TO DATE MESSAGE-ID IN-REPLY-TO REFERENCES LIST-UNSUBSCRIBE CONTENT-TYPE)]BODY.PEEKcommand does not modify server\Seenmessage flags. Unread messages remain unread. - Chunked Paging: MailSweep queries UIDs in batches of 100 messages. This avoids protocol timeouts and buffer errors on high-volume IMAP servers. The scanner indexes more than 7,500 headers in under four seconds over standard SSL connections.
1.2 Parallel Link Health Verification
- Scoped Worker Threads: The Unsubscribe Hub uses worker threads to validate unsubscription URLs in parallel.
- DNS and Socket Pre-Checks: Each URL candidate undergoes a socket resolution pre-check. Strict 3-second connect and read timeouts prevent threads from hanging on unresponsive domains.
1.3 Streaming Backup Archiving
- Direct-to-ZIP Streaming: MailSweep writes raw RFC 822 message streams directly into an open
zip::ZipWriterstream while simultaneously updating SHA-256 digest computation. - Low Memory Footprint: The archiver processes email bodies message by message. It does not load large mailboxes into system memory.
1.4 Precompiled Regex Rules
- One-Time Initialization: MailSweep pre-compiles keyword patterns and regexes for all 13 European languages with
std::sync::LazyLockandregex::Regex. - Zero-Allocation Matching: Header classification matches pre-compiled patterns directly. It does not recompile regular expressions during scan loops.
1.5 Google Protocol Extensions & Deduplication
- Protocol Extension Negotiation: MailSweep detects server
X-GM-EXT-1capability during connection. It requestsX-GM-MSGIDandX-GM-LABELSin header fetch commands. - Message Deduplication: MailSweep identifies duplicate messages across virtual folders and categories using
dedup_key. It deduplicates messages byX-GM-MSGIDor RFC 5322Message-ID. - Label Enrichment: When a message appears in multiple folders, MailSweep merges its labels into an immutable
EmailHeaderinstance. - BODYSTRUCTURE Inspection: MailSweep inspects
BODYSTRUCTUREtokens to detect PDF attachments and calendar invites without downloading email bodies.
2. Security & Privacy Model
- Local Execution: MailSweep processes all email headers, message contents, metadata, and credentials on the local host. No data leaves the local machine.
- Self-Contained Native Binary: MailSweep compiles to a single, static native executable with zero external runtime interpreters or Python dependencies.
- SHA-256 Checksums: Every backup archive includes a companion
.sha256checksum file. MailSweep verifies the archive hash before restore operations. - Standard Storage Formats: Backup archives use standard ZIP containers with raw RFC 822
.emlfiles. Users can open and recover messages with standard email clients.
3. RFC Standards & Protocol Compliance
| Protocol Standard | Domain Role | Implementation in MailSweep |
|---|---|---|
| RFC 6154 | IMAP SPECIAL-USE Attributes | Auto-discovers server \Trash, \Sent, and \Drafts folder flags without guessing. |
| RFC 8058 | One-Click List-Unsubscribe | Parses List-Unsubscribe-Post: List-Unsubscribe=One-Click headers. |
| RFC 2369 | List Header Meta-Syntax | Extracts HTTPS URLs and mailto: endpoints from List-Unsubscribe headers. |
| RFC 3501 | Modified UTF-7 Folders | Decodes international folder names like Roskakori, Skickat, and Lähetetyt. |
| RFC 2047 | MIME Message Header Extensions | Decodes multi-pass RFC 2047 encoded words in Subject and From headers. |
| RFC 3834 | Automatic Responses | Detects automated Auto-Submitted robot headers. |
| RFC 5322 | Internet Message Format | Inspects In-Reply-To and References for conversation thread immunity. |
| RFC 5545 | iCalendar Transport | Detects .ics calendar invites and appointment updates. |
| X-GM-EXT-1 | Google IMAP Extensions | Extracts X-GM-MSGID and X-GM-LABELS for deduplication and category classification. |