Files
docs/mail-intake/wiki/01_overview/index.html
Vishesh 'ironeagle' Bangotra b1447fb72b feat: collect mail-intake wiki; register wiki kind; refresh lib and mcp artifacts
Adds the mail-intake wiki to the hub alongside lib and mcp and picks up
the regenerated flat lib reference and standardized MCP modules.
2026-09-16 20:02:55 +05:30

752 lines
22 KiB
HTML

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="..">
<link rel="next" href="../02_how_to_use/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
<title>Overview - Mail Intake Documentation</title>
<link rel="stylesheet" href="../assets/stylesheets/main.84d31ad4.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"JetBrains Mono"}</style>
<link rel="stylesheet" href="https://unpkg.com/dracula-prism/dist/css/dracula-prism.css">
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="slate" data-md-color-primary="blue-grey" data-md-color-accent="teal">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#overview" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Mail Intake Documentation" class="md-header__button md-logo" aria-label="Mail Intake Documentation" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 15h-4a3 3 0 0 1-3 3 3 3 0 0 1-3-3H5V5h14m0-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Mail Intake Documentation
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Overview
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91s2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08"/></svg>
</a>
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
<div class="md-search__suggest" data-md-component="search-suggest"></div>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
<div class="md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item">
<a href=".." class="md-tabs__link">
Home
</a>
</li>
<li class="md-tabs__item md-tabs__item--active">
<a href="./" class="md-tabs__link">
Overview
</a>
</li>
<li class="md-tabs__item">
<a href="../02_how_to_use/" class="md-tabs__link">
How to Use
</a>
</li>
<li class="md-tabs__item">
<a href="../03_extending/" class="md-tabs__link">
Extending Mail Intake
</a>
</li>
<li class="md-tabs__item">
<a href="../04_development/" class="md-tabs__link">
Development
</a>
</li>
</ul>
</div>
</nav>
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Mail Intake Documentation" class="md-nav__button md-logo" aria-label="Mail Intake Documentation" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 15h-4a3 3 0 0 1-3 3 3 3 0 0 1-3-3H5V5h14m0-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2"/></svg>
</a>
Mail Intake Documentation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Overview
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Overview
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#architecture" class="md-nav__link">
<span class="md-ellipsis">
🏗️ Architecture
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#domain-models" class="md-nav__link">
<span class="md-ellipsis">
📦 Domain models
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#design-guarantees" class="md-nav__link">
<span class="md-ellipsis">
🔒 Design guarantees
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#read-next" class="md-nav__link">
<span class="md-ellipsis">
📚 Read Next
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../02_how_to_use/" class="md-nav__link">
<span class="md-ellipsis">
How to Use
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../03_extending/" class="md-nav__link">
<span class="md-ellipsis">
Extending Mail Intake
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../04_development/" class="md-nav__link">
<span class="md-ellipsis">
Development
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="overview">🧱 Overview</h1>
<p>Mail Intake is a <strong>contract-first ingestion pipeline</strong>. Adapters handle
transport to a provider, parsers normalize provider payloads, and the reader
orchestrates the whole flow into canonical domain models.</p>
<hr />
<h2 id="architecture">🏗️ Architecture</h2>
<div class="language-text highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span></span><span class="normal"><a href="#__codelineno-0-1"> 1</a></span>
<span class="normal"><a href="#__codelineno-0-2"> 2</a></span>
<span class="normal"><a href="#__codelineno-0-3"> 3</a></span>
<span class="normal"><a href="#__codelineno-0-4"> 4</a></span>
<span class="normal"><a href="#__codelineno-0-5"> 5</a></span>
<span class="normal"><a href="#__codelineno-0-6"> 6</a></span>
<span class="normal"><a href="#__codelineno-0-7"> 7</a></span>
<span class="normal"><a href="#__codelineno-0-8"> 8</a></span>
<span class="normal"><a href="#__codelineno-0-9"> 9</a></span>
<span class="normal"><a href="#__codelineno-0-10">10</a></span>
<span class="normal"><a href="#__codelineno-0-11">11</a></span>
<span class="normal"><a href="#__codelineno-0-12">12</a></span>
<span class="normal"><a href="#__codelineno-0-13">13</a></span>
<span class="normal"><a href="#__codelineno-0-14">14</a></span>
<span class="normal"><a href="#__codelineno-0-15">15</a></span>
<span class="normal"><a href="#__codelineno-0-16">16</a></span>
<span class="normal"><a href="#__codelineno-0-17">17</a></span>
<span class="normal"><a href="#__codelineno-0-18">18</a></span>
<span class="normal"><a href="#__codelineno-0-19">19</a></span></pre></div></td><td class="code"><div><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1"></a> ┌─────────────────────────────────────────┐
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2"></a> │ External Provider (e.g. Gmail API) │
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3"></a> └─────────────────────┬───────────────────┘
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4"></a>
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5"></a> ┌─────────────────▼──────────────────┐
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6"></a> │ MailIntakeAdapter (transport) │ provider API calls
</span><span id="__span-0-7"><a id="__codelineno-0-7" name="__codelineno-0-7"></a> └─────────────────┬──────────────────┘
</span><span id="__span-0-8"><a id="__codelineno-0-8" name="__codelineno-0-8"></a> │ provider-native payloads
</span><span id="__span-0-9"><a id="__codelineno-0-9" name="__codelineno-0-9"></a> ┌─────────────────▼──────────────────┐
</span><span id="__span-0-10"><a id="__codelineno-0-10" name="__codelineno-0-10"></a> │ Parsers (normalization) │ headers, body, subject
</span><span id="__span-0-11"><a id="__codelineno-0-11" name="__codelineno-0-11"></a> └─────────────────┬──────────────────┘
</span><span id="__span-0-12"><a id="__codelineno-0-12" name="__codelineno-0-12"></a> │ composed
</span><span id="__span-0-13"><a id="__codelineno-0-13" name="__codelineno-0-13"></a> ┌─────────────────▼──────────────────┐
</span><span id="__span-0-14"><a id="__codelineno-0-14" name="__codelineno-0-14"></a> │ MailIntakeReader (orchestration) │ iter_messages / iter_threads
</span><span id="__span-0-15"><a id="__codelineno-0-15" name="__codelineno-0-15"></a> └─────────────────┬──────────────────┘
</span><span id="__span-0-16"><a id="__codelineno-0-16" name="__codelineno-0-16"></a>
</span><span id="__span-0-17"><a id="__codelineno-0-17" name="__codelineno-0-17"></a> ┌─────────────────▼──────────────────┐
</span><span id="__span-0-18"><a id="__codelineno-0-18" name="__codelineno-0-18"></a> │ MailIntakeMessage / Thread │ canonical domain models
</span><span id="__span-0-19"><a id="__codelineno-0-19" name="__codelineno-0-19"></a> └────────────────────────────────────┘
</span></code></pre></div></td></tr></table></div>
<p>Layers:</p>
<ol>
<li><strong>Adapters</strong> (<code>mail_intake.adapters</code>) — provider-specific, read-only
transport. Return provider-native payloads; never interpret them.</li>
<li><strong>Auth</strong> (<code>mail_intake.auth</code>) — credential acquisition and lifecycle
management, decoupled from adapters.</li>
<li><strong>Credentials</strong> (<code>mail_intake.credentials</code>) — persistence of auth tokens;
<code>PickleCredentialStore</code> locally, <code>RedisCredentialStore</code> for production.</li>
<li><strong>Parsers</strong> (<code>mail_intake.parsers</code>) — extract headers, body text, sender,
and normalized subjects from provider payloads.</li>
<li><strong>Ingestion</strong> (<code>mail_intake.ingestion</code>) — <code>MailIntakeReader</code> wires an
adapter + parsers into iterators over canonical models.</li>
<li><strong>Models</strong> (<code>mail_intake.models</code>) — provider-agnostic <code>MailIntakeMessage</code>
and <code>MailIntakeThread</code>.</li>
</ol>
<hr />
<h2 id="domain-models">📦 Domain models</h2>
<p><code>MailIntakeMessage</code>:</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>message_id</code></td>
<td><code>str</code></td>
<td>Provider message id</td>
</tr>
<tr>
<td><code>thread_id</code></td>
<td><code>str</code></td>
<td>Conversation thread id</td>
</tr>
<tr>
<td><code>timestamp</code></td>
<td><code>datetime</code></td>
<td>Message timestamp</td>
</tr>
<tr>
<td><code>from_email</code></td>
<td><code>str</code></td>
<td>Sender email</td>
</tr>
<tr>
<td><code>from_name</code></td>
<td><code>str \| None</code></td>
<td>Sender display name</td>
</tr>
<tr>
<td><code>subject</code></td>
<td><code>str</code></td>
<td>Message subject</td>
</tr>
<tr>
<td><code>body_text</code></td>
<td><code>str</code></td>
<td>Extracted plain-text body</td>
</tr>
<tr>
<td><code>snippet</code></td>
<td><code>str</code></td>
<td>Provider snippet</td>
</tr>
<tr>
<td><code>raw_headers</code></td>
<td><code>dict[str, str]</code></td>
<td>Unmodified headers</td>
</tr>
</tbody>
</table>
<p><code>MailIntakeThread</code>:</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>thread_id</code></td>
<td><code>str</code></td>
<td>Conversation id</td>
</tr>
<tr>
<td><code>normalized_subject</code></td>
<td><code>str</code></td>
<td>Normalized subject (threads share one)</td>
</tr>
<tr>
<td><code>participants</code></td>
<td><code>set[str]</code></td>
<td>Distinct senders</td>
</tr>
<tr>
<td><code>messages</code></td>
<td><code>list[MailIntakeMessage]</code></td>
<td>Ordered messages</td>
</tr>
<tr>
<td><code>last_activity_at</code></td>
<td><code>datetime \| None</code></td>
<td>Latest message time</td>
</tr>
</tbody>
</table>
<hr />
<h2 id="design-guarantees">🔒 Design guarantees</h2>
<ul>
<li>Read-only access — no mutation of provider state.</li>
<li>Provider-agnostic domain models.</li>
<li>Explicit configuration and dependency injection (no implicit env reads).</li>
<li>Extensible via public contracts; built-in adapters are reference
implementations and may change internally.</li>
</ul>
<hr />
<h2 id="read-next">📚 Read Next</h2>
<ul>
<li><a href="../02_how_to_use/">How to Use</a> — the Gmail ingestion flow.</li>
<li><a href="../03_extending/">Extending Mail Intake</a> — custom adapters and stores.</li>
</ul>
</article>
</div>
<script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
Back to top
</button>
</main>
<footer class="md-footer">
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": ["navigation.sections", "navigation.expand", "navigation.top", "navigation.instant", "navigation.tracking", "navigation.indexes", "content.code.copy", "content.code.annotate", "content.tabs.link", "content.action.edit", "search.highlight", "search.share", "search.suggest", "navigation.tabs", "toc.integrate", "header.autohide", "announce.dismiss", "footer.social", "content.code.select", "content.code.line_numbers", "content.tooltips"], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
<script src="../assets/javascripts/bundle.f55a23d4.min.js"></script>
</body>
</html>