Parsers
mail_intake.parsers
Summary
Message parsing utilities for Mail Intake.
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
extract_bodyparse_headersextract_sendernormalize_subject
Functions
extract_body
Extract the best-effort message body from a Gmail payload.
Priority:
text/plaintext/html(stripped to text)- Single-part body
- Empty string (if nothing usable found)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload |
Dict[str, Any]
|
Provider-native message payload dictionary. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
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 |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, Optional[str]]
|
Tuple[str, Optional[str]]:
A tuple |
Notes
Responsibilities:
1 2 | |
Example
Typical values:
"John Doe <john@example.com>"->("john@example.com", "John Doe")"john@example.com"->("john@example.com", None)
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 2 | |
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 3 4 | |