Parsers
mail_intake.parsers
Message parsing utilities for Mail Intake.
Summary
This package contains provider-aware but adapter-agnostic parsing helpers used to extract and normalize structured information from raw mail payloads.
Parsers in this package are responsible for: - Interpreting provider-native message structures - Extracting meaningful fields such as headers, body text, and subjects - Normalizing data into consistent internal representations
This package does not: - Perform network or IO operations - Contain provider API logic - Construct domain models directly
Parsing functions are designed to be composable and are orchestrated by the ingestion layer.
Public API
1 2 3 4 | |
Functions
extract_body
Extract the best-effort message body from a Gmail payload.
Priority: 1. text/plain 2. text/html (stripped to text) 3. Single-part body 4. empty string (if nothing usable found)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload |
Dict[str, Any]
|
Provider-native message payload dictionary. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Extracted plain-text message body. |
extract_sender
Extract sender email and optional display name from headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers |
Dict[str, str]
|
Normalized header dictionary as returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, Optional[str]]
|
Tuple[str, Optional[str]]:
A tuple |
Notes
Responsibilities:
1 | |
Example
Typical values:
1 2 | |
normalize_subject
Normalize an email subject for thread-level comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject |
str
|
Raw subject line from a message header. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Normalized subject string suitable for thread grouping. |
Notes
Responsibilities:
1 2 3 4 | |
Guarantees:
1 | |
parse_headers
Convert a list of Gmail-style headers into a normalized dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_headers |
List[Dict[str, str]]
|
List of header dictionaries, each containing |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict[str, str]: Dictionary mapping lowercase header names to stripped values. |
Notes
Guarantees:
1 2 | |
Example
Typical usage:
1 2 3 4 5 6 7 8 9 10 11 | |