{
  "id": 20299361,
  "title": "Quality IMAP, Part 1: Your Mailbox Is A Database",
  "url": "https://urgent.news/2026/11/16/quality-imap-part-1-your-mailbox-is-a-database",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-16T16:25:38.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://aerogramme.deuxfleurs.fr/blog/2026-quality-imap-part-1/"
  },
  "original_language": "en",
  "account": "During the past year, Aerogramme's team has made substantial progress in enhancing the reliability and accuracy of the IMAP implementation for their experimental email server. This article, the first in a series, delves into the complexities of implementing IMAP correctly and the techniques used to achieve high-quality code. Here, the focus shifts to the challenge of fine-grained retrieval and querying of emails within Aerogramme.\n\nAerogramme is designed to be geo-distributed, hosted on refurbished hardware, and reliable even in the face of network issues and hardware failures. Built on top of Garage, the server shares the same philosophy as Garage. Notably, Aerogramme is AI-free, with a focus on meticulous craftsmanship and community-building.\n\nIMAP, an old protocol with a rich feature-set, presents challenges due to its complexity and the fact that IMAP and email are often defined in vague documents, with real-world implementations not always adhering to specifications. This article will explore Aerogramme's efforts in improving IMAP access, emphasizing the difficulty of correctly implementing fine-grained retrieval and querying of email contents and concurrent access from multiple clients and sessions.\n\nOne of the challenges in IMAP specification is the rich feature-set it provides for retrieving mailbox and email contents. While a mailbox may seem like a directory containing plain email files, from the perspective of an IMAP server (or client), it resembles a database accessed using a dedicated query language. For instance, mobile clients benefit from fine-grained querying to update lists of emails without downloading attachments or syncing entire mailboxes.\n\nTo support efficient querying, IMAP specifies two key mechanisms: SEARCH and FETCH. These features necessitate IMAP servers parsing emails, interpreting queries, and supporting data architectures that enable efficient searching and querying. Aerogramme's implementation of SEARCH and FETCH relies on three components: an interpreter for SEARCH and FETCH commands, an email parsing library (eml-codec), and an internal data architecture separating mailbox state, email metadata, and email contents.\n\nThe eml-codec library parses emails into a structured Abstract Syntax Tree (AST) while providing access to raw input slices for FETCH functionality. Aerogramme's metadata storage uses Garage K2V for storing mailbox state and email metadata, while email contents are stored in blob storage using Garage S3. This architecture enables SEARCH to efficiently read pre-computed information from metadata storage.\n\nTo ensure the correctness of SEARCH and FETCH, Aerogramme's implementation underwent rigorous testing using ImapTest, a testing tool for IMAP servers maintained by the Dovecot developers. The ImapTest suite, which includes hand-crafted test scenarios for subtle or interesting aspects of the IMAP specification, helped identify bugs in SEARCH, primarily in edge cases. However, it was discovered that Aerogramme's initial implementation of the BODY[section] subcommand in FETCH was conceptually wrong in many cases. This subcommand retrieves a sub-part of an email by following IMAP-specific rules.\n\nThese components work together to provide Aerogramme with a robust, high-quality IMAP implementation, making the mailbox function as a database while accommodating complex querying and retrieval requirements.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}