$ show s1t5/mail-archiver
Mail-Archiver is a production-grade ASP.NET Core 10 web application for archiving emails from IMAP, Microsoft 365 (Graph), and local imports (MBOX, EML). It provides a full MVC UI for searching, viewing, exporting, restoring, and managing archived emails, alongside a read-only REST API (v1) and a Model Context Protocol (MCP) server for AI agent integration. The system features background job processing for sync, batch operations, deduplication, retention policies, and audit exports, all backed by PostgreSQL with full-text search. Authentication supports local password (PBKDF2), OpenID Connect, and API keys, with two-factor authentication and role-based access control. The codebase is well-structured with clear separation of concerns: provider-specific services (IMAP, Graph, Mbox), shared utilities, and a core service layer. Extensive unit and integration tests (xUnit) cover critical paths, and Docker Compose provides a reproducible test environment. While some technical debt exists (raw SQL in core services, in-memory job tracking, German comments in places), the overall architecture is solid and the reusable components (static helpers, deduplication strategies, background job patterns) demonstrate high craftsmanship.
The LLM identified 4 files worth highlighting for reuse:
A pure static class providing email content manipulation: Message-ID normalization, fallback generation (for missing headers), body cleaning (HTML truncation, plain text extraction), and date extraction. Used across IMAP, Graph, and import pipelines. Easily extractable into any email processing project; thoroughly unit-tested.
Generates stable 64-bit FNV-1a hash keys for email deduplication based on Message-ID and fingerprint (From/To/Subject/Date with 2-second tolerance). Used for cross-pipeline duplicate detection (sync, import, offload). Self-contained, no external dependencies beyond standard .NET, and tested for collision resistance and edge cases.
A custom Kiota parse node factory that sanitizes invalid UTF-8 bytes and unpaired surrogate escapes in Graph API JSON responses. Demonstrates deep understanding of the Graph SDK internals and a practical workaround for Exchange Online data corruption. Extracted standalone, it could protect any Kiota-based client from malformed responses.
A static utility to extract iCalendar (text/calendar) parts from archived emails, handling line unfolding, timezone localization, and structured event extraction. Rescues meeting invitations that Outlook/M365 embed as attachments. Self-contained and testable without database or network dependencies.