An asyncio IMAP proxy that sits transparently in front of Dovecot and intercepts SEARCH / UID SEARCH commands, routing natural-language queries to a vector embedding search API and returning standard IMAP results — so any IMAP client (FairEmail, Gmail app, Thunderbird, Apple Mail, …) gets semantic search without modification.
Semantic (vector) search over email works beautifully at the web-app layer: a Roundcube plugin hooks imap_search_before, calls a local embedding API, and returns scored (folder, uid) pointers. But native IMAP clients speak RFC 3501 — a fixed protocol with no hook for vector search. This proxy adds that hook at the protocol level.
IMAP client
│ port 993 (TLS)
▼
imap-semantic-proxy ← this project
│ intercepts SEARCH commands with a ~ prefix
│ all other traffic is forwarded transparently
├─► semantic API (127.0.0.1:8095) → scored (folder, uid) pairs
└─► Dovecot (127.0.0.1:10143) → standard IMAP for everything else
A query like ~papal encyclicals on work sent from FairEmail is caught by the proxy, stripped of the ~, embedded, and searched against the pgvector index. The resulting UIDs are returned as a standard * SEARCH response — the client never knows anything unusual happened.
Same convention as the Roundcube plugin: prefix the search query with ~ to invoke semantic search. Everything else passes through to Dovecot unchanged.
SEARCH TEXT "~documents about the common good" → semantic
SEARCH FROM "alice@example.com" → Dovecot (unchanged)
FairEmail lets you set a default search prefix per account; other clients can type the prefix manually.
proxy/— asyncio TCP/TLS proxy core; connection and session managementimap/— IMAP command parser (RFC 3501 SEARCH grammar, literals, pipelining)semantic/— HTTP client for the vector search API; result mapper (folder × uid → IMAP UIDs)config/— YAML config: upstream Dovecot address, semantic API endpoint + token, TLS cert paths
| # | Name | Scope |
|---|---|---|
| 1 | Transparent proxy | asyncio skeleton; TLS both sides; all traffic forwarded unchanged; tested with FairEmail + Thunderbird |
| 2 | SEARCH interception | Parse SEARCH grammar; detect ~; call semantic API; map results to UIDs for the selected folder; fall through for non-semantic |
| 3 | Cross-folder search | ESEARCH (RFC 4731) across all folders; virtual result mapping |
| 4 | XSEMANTICSEARCH capability |
Custom IMAP capability + command for future client-native integration |
| 5 | Production deploy | systemd service; Plesk/Dovecot integration; TLS cert sharing; monitoring |
This proxy is a client of the mail-semantic-search API — it does not embed or index mail itself. The indexing pipeline, pgvector schema, and embedding services live there.
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Run against a local Dovecot or test IMAP server
cp config/config.example.yaml config/config.yaml
# edit: upstream_host, semantic_api_url, semantic_api_token
python -m imap_semantic_proxyThe proxy will ship as a systemd service (imap-semantic-proxy.service) listening on port 993, with Dovecot moved to 127.0.0.1:10143. TLS certificates are shared from the existing Let's Encrypt chain managed by Plesk/acme.sh.
MIT