Email Before AI: MIME, Canonical Text, Multilingual Processing, and Privacy
On this page23
A beginner-first tutorial following email from MIME bytes through canonical text, language detection, translation, Unicode offsets, PII detection, redaction, and safe model input.
Article details
- Status
- Building Publicly
- Subcategory
- Thunderbird AI
- Last reviewed
- 3 Sept 2026
- Prerequisites
- No email-format or machine-learning knowledge required
1. The five objects people casually call “the email”
| Representation | What it contains | What it is good for |
|---|---|---|
| Wire source | Original headers, boundaries and encoded bodies | Authentication and forensic evidence |
| MIME tree | The parser’s structural interpretation | Choosing bodies and attachments |
| Decoded source text | Human-readable characters | Exact quotations and citations |
| Analysis text | Relevant body with segments labelled or excluded | Classification, extraction and retrieval |
| Policy-safe text | Redacted, bounded text permitted for a model | Endpoint inference |
2. Start with bytes, not meaning
From: Aster Bank <alerts@asterbank.test>
Subject: Book Nook transaction
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
INR 805.00 was debited at Book Nook.
3. MIME is a tree
multipart/mixed
├── multipart/alternative
│ ├── text/plain
│ └── text/html
└── application/pdf; name="receipt.pdf"
Recursive MIME interpretation
The multipart subtype determines whether children are alternatives, independent parts, signed content, or related resources.
4. HTML is presentation plus text
<p>Paid <strong>INR 805</strong> at Book Nook.</p>
<style>.amount { color: green }</style>
5. Quoted replies are real source text with a different role
The release is Friday.
On Monday, Daniel wrote:
> The release is Thursday.
body → The release is Friday.
quoted → The release is Thursday.
6. Source maps prevent cleaned text from becoming invented text
decoded source: [0.....................96]
analysis text: [0......22]
source range: [0......22]
Offset mapping
The mapping lets an extracted amount highlight the original decoded characters instead of trusting a rewritten copy.
7. Canonical text and model text have different jobs
decoded source
├── canonical source + offsets authoritative
├── analysis body derived
├── English translation derived aid
├── redacted endpoint text policy-safe derivative
└── embedding / summary model artifact
8. Translation must protect exact tokens
Aprobar INV-2026-42 por INR 805
↓ protect
Aprobar ⟦P0⟧ por ⟦P1⟧
↓ translate
Approve ⟦P0⟧ for ⟦P1⟧
↓ restore
Approve INV-2026-42 for INR 805
9. Complete dry run
Hello team,
The launch is Friday. Reference INV-2026-42.
--
Maya
On Monday Daniel wrote:
> The launch was Thursday.
10. The actual synthetic run
11. Experiments worth trying
A model never receives “the email.” It receives one engineered representation of the email. Correctness begins by naming that representation and keeping its route back to source.
12. Multilingual processing without losing the evidence
Aprobar INV-2026-42 por INR 805.
Please approve INV-2026-42 for INR 805.
कृपया INR 805 वाला INV-2026-42 स्वीकृत करें।
12.1 Translate into one pivot language
source language → local translation → English classifier/embedder/model
12.2 Use multilingual models directly
source language → multilingual classifier/embedder/model
13. Language detection is a prediction too
OK
Gracias
Invoice INV-42 ready
14. Protect exact tokens before translation
Aprobar INV-2026-42 por INR 805.
15. Unicode has several coordinate systems
Cross-runtime span contract
Exact equality catches offset drift before a model hint is stored or highlighted.
16. Translation boundaries and code switching
Kal meeting hai, please review INV-42 before 5 PM.
Translation coverage
Coverage does not measure translation quality; it prevents partial output being presented as complete.
17. PII policy and redaction
18. Pattern recognizers, validation and overlap
Luhn decision
A valid checksum means plausible shape, not a real active card or proof of ownership.
19. Run the policy, including the failure
20. Severity, destination and provenance
source: Contact maya@example.test about INV-42
redacted: Contact <EMAIL> about INV-42
21. Evaluate the complete input boundary
Primary references
- RFC 5322: Internet Message Format
- RFC 2045: MIME message bodies
- RFC 2046: MIME media types and multipart bodies
- XLM-R: Unsupervised Cross-lingual Representation Learning
- Unicode Standard: latest published version
- W3C Character Model for the World Wide Web
- NIST SP 800-122: Protecting Personally Identifiable Information
- GLiNER: Generalist Model for Named Entity Recognition