AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Index your mail: Google Takeout, Thunderbird and Apple Mail mailboxes
Goal: you have a mail export on your laptop — a Google Takeout
All mail Including Spam and Trash.mbox of several gigabytes, or a Thunderbird
/ Apple Mail / mutt mailbox — and you want to search it, thread it, and let a
person or an agent find "the PDF she attached to that reply in March" without
uploading anything anywhere. This recipe indexes the export with one command,
shows the record shape you get back, and states plainly what was measured and
what was not. What does and does not leave your machine is its own section
below (Privacy) — read it before you index
somebody's mail.
Everything below was run against a live XERJ on a throwaway node with the
default lexical embedder (feature hashing — not neural, not "semantic" in
the model sense). The mailbox used for the measurements is synthetic:
generated by scripts/synthetic-takeout.py
so that every planted needle can be checked against a ground-truth file. The
Takeout layout handling has only ever seen that synthetic tree; it has not
been verified on a real Takeout export yet.
What is handled, and what is not
| Input | What happens |
|---|---|
| An mbox file, any name | Detected by content — a From <sender> <asctime date> separator followed by RFC 5322 headers — never by the .mbox extension. Split in a bounded-memory stream: a multi-GB file is never read whole. mboxo / mboxrd quoting (>From ) is undone; CRLF and LF, a leading UTF-8 byte-order mark, a missing final newline, and messages with no Date: header (the separator's date is used) are all handled. A line that merely starts with From but carries no date does not split a message (mboxcl2 writers do not quote). Not recognised as a mailbox: a file whose first line is a quoted >From line, and separators that carry an RFC 2822 date (From a@b Tue, 14 Nov 2023 22:13:20 +0000) instead of the asctime form — both are recorded as junk (exit 3, listed, never silent), though the junk reason names the family the sniffer tried last, not mail; and a file with lone-CR line endings (classic Mac OS), which is indexed as one plain-text document, headers included, not split into messages. |
A standalone .eml |
Same extractor as one mbox entry, so the records have the same shape. |
| A Google Takeout folder | Recognised by archive_browser.html in the folder (the folder name is not trusted — people rename it). That index page is skipped (default:takeout-index); a Keep note's .html twin is skipped when the .json beside it is the note (default:takeout-keep-html-twin); Keep .json notes become documents with keep_labels, keep_created, keep_edited, keep_pinned, keep_archived, keep_trashed. Both rules appear in the ignore accounting, are off under --no-default-ignores, and a !name line in .xerjignore wins. Everything else in the export is ordinary sniffing. |
| Gmail headers | X-GM-THRID → email_thread_id, converted: the export writes the id in decimal (X-GM-THRID: 2301773278856733157) and the field holds the same number in lower-case hex (1ff18a9a0fbde1e5) — filtering on the decimal you see in the mbox finds nothing. Convert with printf '%x\n' 2301773278856733157. Hex is the form the Gmail web interface and API use: Google's IMAP extensions page says the decimal X-GM-THRID "is the decimal equivalent for the ID hex string used in the web interface and the Gmail API" (Google's statement; we have not checked it against a live account); it is stored as a string because a 19-digit decimal is inferred as a number and two ids past 2^63 would collapse into one. X-Gmail-Labels → email_labels. |
A .zip, .tgz, .7z, .rar, .xz |
Not opened. Recorded as junk with the reason unextracted zip archive: autoindex does not open archives — extract it first (unzip <file>), then run autoindex on the extracted folder, naming the right command per kind. The run prints that line under its summary (not indexed — archives are never opened; …) and carries it in the --json summary as unextracted_archives, so a folder that holds only the download says why it indexed nothing. |
| Outlook PST / OST, Maildir, IMAP | Not supported. Convert to mbox first with a tool of your choice. We have not run or tested any converter, so none is recommended here. |
Inside a message:
- 8-bit bodies and headers. A declared charset is honoured. An undeclared
8-bit
text/plainbody is tried as UTF-8 and otherwise read as Windows-1252 — the same rule autoindex applies to undeclared text files — and so is a header block with raw 8-bit bytes and no RFC 2047 encoded-word (Subject: Grüßewritten as Latin-1). Undeclared Cyrillic or CJK legacy encodings are not detected; that is a known limit. - Attachments. A PDF goes through the isolated PDF worker and yields one record per page; a text attachment is sectioned like a document; anything else gets a name/type/size card so it is findable by name. Attachments over 24 MB get the card only; a message with more than 256 parts is cut there and the file is reported as truncated.
- Oversized or broken entries. One message is capped at 64 MB (the head
is parsed, and the run names the file in a "cut short" note that lists the
caps that can cause it). An entry the MIME parser
refuses outright is indexed as raw text under the title
(unparseable message)— its words are still in your mailbox and still worth finding. An entry with no text at all is junk, never an empty(no subject)document. - Panic safety. The crate builds with
panic = "abort", so a byte-slice into a&stron Arabic or Chinese input would take the whole run down. Splitting works on bytes throughout; every cut point in this path has a multi-byte test.
Run it
# 1. start a local node (data dir OUTSIDE the folder you will index).
# --insecure = NO authentication on 127.0.0.1:9200: every local process and
# every user on this machine can read the mailbox. Fine on your own laptop;
# on a shared machine drop the flag and send the key from ~/xerj-data/admin.key
# (see "Privacy" below).
xerj --insecure --data-dir ~/xerj-data
# 2. unzip the Takeout download first — autoindex does not open archives
unzip takeout-20260101T000000Z-001.zip -d ~/mail-export
# 3. index it. --prefix keeps the mail out of the shared ax-* wildcard.
xerj autoindex ~/mail-export --url http://127.0.0.1:9200 --prefix mail --progress plain
The progress bar moves inside the mailbox — each record carries the byte
offset of its message, so a one-file corpus no longer sits at 0.0% with
eta unknown for the whole run. Messages are parsed on a pool of --workers
threads (shared by every mailbox in the tree); the splitter itself is serial
and cheap. The raw bytes of messages in flight are bounded at 256 MB for the
whole process (one larger message runs alone); on top of that, each mailbox
being read holds the one message it is assembling (at most 64 MB), and the
parser needs working memory for the attachment it is decoding. So the client
figure depends on the tree: 296 MiB for the one-mailbox 1 GB Takeout
below, and ~0.9 GiB (897 and 906 MiB in two runs) for twelve mailboxes
whose every message carries a 20 MB attachment — 1.25–1.35 GiB before the
budget was made process-wide
(result).
Re-running is safe: every record's _id is derived from the file and the
message's byte offset in it, so an incremental run overwrites rather than
duplicates, and a run killed half-way resumes from its journal. Reply edges
keep up with that: a run that re-reads only the mailbox that changed loads
the message nodes of the mail files it did not re-read back from the
index, resolves replies over all of them, and invalidates an edge whose
parent moved or left — so a reply in Inbox to a message in an untouched
Sent survives, and an edge into a compacted mailbox follows its parent to
its new id. Edges are bi-temporal: a superseded edge is kept with
invalid_at set, not deleted (see the edge query below).
What you get
One dataset (index mail-docs for a Takeout — the slug is inferred) with
these extractor fields on every message record:
email_from, email_to, email_cc, email_subject, email_date,
email_message_id, email_in_reply_to, email_references,
email_thread_id, email_labels, plus title, body, ax_path,
ax_locator, ax_format (mbox or eml).
Two things about those fields decide whether a query works:
- Filter people by
email_from_address/email_to_address/email_cc_address, not byemail_from.email_fromis the header as a person reads it —Alice Anders <[email protected]>— and it is a keyword, sotermon the bare address matches nothing. The*_addressfields hold the bare addresses, lower-cased, one value per address (at most 1,024 per header). - Search subject words in
body.titleandemail_subjecthold the whole subject but are usually mapped as keywords on a mailbox (the mapping is inferred from the data), and a keyword only matches whole. So the subject is also the first paragraph of the message's firstbodysection (up to 512 characters of it);xerj searchandmatchonbodyfind it.
Attachment records add attachment_name, attachment_content_type,
attachment_bytes, and carry the parent's email_message_id,
email_subject, email_from and email_from_address so a page of an
attached PDF is one filter away from the mail it arrived in. A page of an
attached PDF is titled with the attachment's name.
A long body is cut into sections that overlap by a paragraph, so a phrase
that straddles a cut is still found whole — and a word in the shared
paragraph is found in two sections of the same message. Collapse on
email_message_id when you want messages rather than sections.
Locators are positional and stable: m<offset>-msg-s0 is a message's first
section, m<offset>-att2-p7-s0 is page 7 of its third attachment,
m<offset>-att0-card is the name card of an attachment that was not indexed
by content. A standalone .eml uses the same shapes without the m<offset>-
prefix.
# every message from one sender, newest first (the bare address, lower-case)
curl -s -XPOST http://127.0.0.1:9200/mail-*/_search -H 'content-type: application/json' -d '{
"query": {"term": {"email_from_address": "[email protected]"}},
"sort": [{"email_date": "desc"}], "_source": ["email_subject","email_date","ax_locator"]}'
# the whole Gmail thread of one message — the id in HEX: printf '%x\n' <X-GM-THRID>
curl -s -XPOST http://127.0.0.1:9200/mail-*/_search -H 'content-type: application/json' -d '{
"query": {"term": {"email_thread_id": "18cf06223648b478"}}, "sort": [{"email_date": "asc"}]}'
# a word that is only in a Subject line
curl -s -XPOST http://127.0.0.1:9200/mail-*/_search -H 'content-type: application/json' -d '{
"query": {"match": {"body": "Rechnung"}}, "_source": ["email_subject","email_from","ax_locator"]}'
# pages of attached PDFs that mention an invoice number
curl -s -XPOST http://127.0.0.1:9200/mail-*/_search -H 'content-type: application/json' -d '{
"query": {"bool": {"filter": [{"term": {"attachment_content_type": "application/pdf"}}],
"must": [{"match_phrase": {"body": "INV-2024-0117"}}]}},
"_source": ["attachment_name","email_subject","email_from","ax_locator"]}'
The rest of a Takeout (Drive documents, notes) is indexed by ordinary
sniffing, and a line-oriented text file carries its words in text, not
body. To search the whole export rather than the mail, ask both:
{"multi_match": {"query": "…", "fields": ["body", "text"]}}.
The thread graph: email-thread@1
Mail carries the one relationship no filesystem detector can see: a reply is
a document about another document, and the sender said so in a header. The
email-thread@1 detector writes two edge types into the run's brain
(.xerj-memory-<brain>-edges; the brain name defaults to the folder's
basename, --brain <name> sets it, --no-graph turns it off):
replies_to— reply → parent, fromIn-Reply-To, or from the nearest resolvable ancestor inReferenceswhenIn-Reply-Tois missing or names a message that is not in the corpus. Weight 0.9, confidence 0.95; the evidence quotes the header and says which one it came from.attachment_of— attachment record → the message that carried it, one edge per attachment record (page 7 of the PDF is one hop from the email). Confidence 0.99: the MIME parser found the part inside the message; nothing was inferred.
Resolution happens at the end of the run, after every message is known —
including the messages of mail files an incremental run did not re-read,
which are loaded back from the index — so "the parent I have seen so far" is
never a fact about thread scheduling or about which files changed; a
duplicated Message-ID resolves to the numerically smallest node id, a
function of the corpus. A parent that is not in the corpus is counted as
unresolved and never invented. Subject-line threading (Re: with no ids) is
deliberately absent — it is a guess.
# what does this message reply to? LIVE edges only: the brain is bi-temporal, and
# after an incremental run a superseded edge is still stored, with invalid_at set.
curl -s -XPOST 'http://127.0.0.1:9200/.xerj-memory-mail-export-edges/_search' -H 'content-type: application/json' -d '{
"query": {"bool": {"filter": [{"term": {"type": "replies_to"}},
{"term": {"src": "<node id of the reply>"}}],
"must_not": [{"exists": {"field": "invalid_at"}}]}}}'
Without the must_not, the same query returns history too — one edge per
generation of the file that taught it. That is what as_of time travel reads
(SECOND_BRAIN.md); it is not a duplicate.
What was measured
On a synthetic 1 GB Takeout (40,799 mbox entries, 12 Keep notes, Drive
documents, two unextracted archives), default xerj autoindex settings, the
default lexical embedder, a 32-thread desktop-class machine. The full table,
the machine, every result file and the exact commands are in
benchmarks/mbox-ingest/README.md.
Memory figures are MiB / GiB (VmHWM kB ÷ 1024), sizes on disk are in
bytes; the two are not mixed in one ratio.
- Client. 279 s wall for 106,581 documents (382 docs/s over the whole
run, a third of which is the final count phase);
xerj autoindexpeaked at 296 MiB of RSS. The whole mailbox was staged 39 s in. - Correctness. All 2,530 planted needles — in bodies, in 8-bit bodies,
after an unquoted
Fromparagraph, on pages of attached PDFs, in text attachments, in Keep notes — were found in the right message and nowhere else. 2,529 came back as exactly one document; one came back as two, which are two overlapping sections of the same long message (sections share a paragraph by design). The run itself checked the first 60 needles of each kind (354); all 2,530 were checked afterwards against a copy of that index (result).replies_to: 21,544 of 21,544 resolvable replies.attachment_of: 39,619 of 39,619 attachment records. No empty documents. - Index on disk. 760,436,960 bytes for the 1,073,777,879-byte mailbox (0.71×), once merges settled.
- Server memory — the limit you would hit, fixed by PR #1002
(v1.0.0-rc.76). Before #1002 (2026-09), that complete run needed the
node's process cap lifted (
XERJ_MAX_PROCESS_MEMORY_MB=off) and took the server to 66.9 GiB of peak RSS (68,528 MiB). Under the default cap on the same 119 GiB machine (16 GiB), the server sat at its memory watermark from 87 % of the mailbox on and the run aborted after ten minutes of waiting, with 82,422 documents indexed and 25.9 GiB of peak RSS (26,529 MiB) — the engine's ingest memory, not the extractor's, filed as #948 and closed by #1002. After #1002, a 1 GB synthetic mailbox completes in 407.7 s with the default 16 GiB cap in force — the abort above is gone, and every needle and edge was verified — and at-rest retention after a 100k-doc ingest fell ~677 MB → ~108 MB. One caveat remains: the fixed 1 GB run's peak is still 21,405.3 MiB, 1.3× that 16 GiB cap, because three per-segment caches (stored_value_cache,dv_cache,id_pos_cache) stay unbounded until a merge retires their segment; that is open issue #1032, filed 2026-09-26. - At a laptop's cap: 300 MB now fits — before #1002 it did not. Before PR #1002, a 300 MB synthetic mailbox (11,478 entries, 30,403 documents) against a node capped at 8 GiB — the default on a 16 GiB machine — on the same 119 GiB box, twice: both runs completed (exit 3, 89–91 s), all 735 needles were found in the right message, and the edges equal the truth. But the server's peak resident memory was 18.2 GiB and 19.9 GiB, 2.3–2.5× its own cap and more than a 16 GiB laptop has — on an actual laptop that meant swapping or an out-of-memory kill: the memory breaker stops admitting work at the watermark, and work already admitted keeps growing (run 1, run 2). After #1002, a 300 MB mailbox fits an 8 GiB cap at 7,963.6 MiB. What is still not measured is the laptop itself: we have not run one, and the fixed 1 GB run's peak (21,405.3 MiB, above) is more than a 16 GiB machine has. Treat a multi-GB export on a laptop-class node as unmeasured rather than promised or ruled out.
- Searching after a restart — the second limit. The correctness figures above come from a warm node. The same 1 GB index reopened by a fresh node answers a first-time question in either under 50 ms or several seconds. Under the default cap, 16 and 17 of 40 sampled single-term queries took over a second in the first pass (slowest 8.7 s and 16.6 s in two separate measurements), and 8 of 40 different queries did again in a second pass. With the cap lifted, 4 of 40 were slow in the first pass and 1 of 40 in the second. Every answer was correct, and the server log puts the time in its segment loop. The box was shared (1-minute load 13–50 across the measurements), so the seconds are upper bounds; the two-speed shape is the finding. Raw lines and the script: restart-query-latency. Engine-side; not profiled. It was reported on #948, since closed by #1002; the memory work still open is #1032 (2026-09-26).
Privacy: what leaves the machine
- Message text does not leave it with the default configuration. The default embedder is the built-in lexical feature hasher and runs inside the node; autoindex talks only to the node URL you give it.
--embed-mode proxychanges that: the node then sends the text it embeds — everybodysection — to the embedding endpoint you configured. Do not combine it with private mail unless that endpoint is yours.- The field report is public. llms.txt asks an
agent to file a field report after using XERJ, and
xerj feedbackpre-fills it with the absolute path of the indexed folder and the record count, then prints thegit push/gh pr createcommands that publish it in the public repository. For a private mailbox, write that line yourself —xerj feedback --pointed-at "a private mailbox" …— or draft offline with--no-autofill, or do not file one.xerj feedback --dry-runshows exactly what would be published before anything is. --insecuremeans no authentication on127.0.0.1:9200. Any local process, and any other user of the same machine, can read the whole mailbox over HTTP while the node runs. On a shared machine start the node without the flag. It writes an admin key to<data-dir>/admin.key; pass it to autoindex withXERJ_API_KEY="$(cat ~/xerj-data/admin.key)" xerj autoindex …(autoindex looks for a key on its own only in a few fixed places, such as./xerj-data/admin.keyrelative to the directory you run it from), and add-H "Authorization: ApiKey $(cat ~/xerj-data/admin.key)"to everycurlabove.
Verification
engine/crates/xerj-autoindex/src/detect/e2e_mail.rsruns the real indexer against a mock endpoint over a committed synthetic Takeout (tests/fixtures/takeout-small/) and checks every count against the generator's ground-truth file, not against numbers typed into the test.benchmarks/mbox-ingest/verify.pyruns read-only against a live node and checks that every planted needle comes back from the right message and no other — including needles that sit on a page inside a PDF inside a base64 part inside the mbox, the chain a unit test cannot exercise — that the livereplies_toandattachment_ofedge counts equal the truth, that atermfilter onemail_from_addressfinds what the display-form header holds, and that sampled subjects are found bymatch_phraseonbody. It reports a needle found in two overlapping sections of one message apart from a real duplicate, and the latency of every request it made.detect/e2e_mail.rsalso covers the runs that do not re-read every mailbox: a reply acrossInboxandSentsurviving an incremental run, and a reply into a compacted mailbox following its parent to its new id.- The generator writes, on purpose, everything that breaks naive mbox
readers:
>Fromand>>Fromlines, an unquotedFrom what I understand…paragraph, declared ISO-8859-1 and undeclared Windows-1252 bodies, RFC 2047 subjects, a truncated multipart, a broken encoded-word, a 300 KB line, a separator with nothing after it, a duplicated Message-ID, and a final message with no trailing newline. Python's ownmailboxmodule splits that file one message too many; this extractor does not.