# Mbox Claims Correspondence Timeline Extractor (`armourylabs/mbox-claims-correspondence-timeline-extractor`) Actor

Parses a .mbox email export into a threaded, chronological claims correspondence timeline. Structured JSON records plus CSV and HTML compliance artifacts. Deterministic parsing, no AI. Zero outbound network - your mbox never leaves your Apify account. Priced per correspondence item.

- **URL**: https://apify.com/armourylabs/mbox-claims-correspondence-timeline-extractor.md
- **Developed by:** [Christopher Smith](https://apify.com/armourylabs) (community)
- **Categories:** Automation, Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $50.00 / 1,000 correspondence-items

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Mbox Claims Correspondence Timeline Extractor

Parse Gmail/Outlook `.mbox` email exports into a **threaded, chronological correspondence timeline** ready for insurance claim audits, disputes, and court submissions.

### What It Does

- Reads any standard `.mbox` file (Gmail Takeout, Outlook export, Thunderbird, Apple Mail, etc.)
- Extracts every email's metadata: date, sender, recipients, CC, subject, body snippet
- Groups emails into **reply threads** using `In-Reply-To` and `References` headers
- Filters emails by **claim keywords** (e.g. `"claim"`, `"policy"`, `"loss"`) — or include all
- Produces:
  - **Structured records** (chronological, thread-annotated JSON)
  - **CSV artifact** — importable into Excel, case management systems
  - **HTML report** — printable, shareable compliance document

### Who Buys This

| Buyer | Use case |
|---|---|
| Insurance claims managers | Reconstruct correspondence history for disputed claims |
| Insurance lawyers / solicitors | Prepare chronological evidence bundles for litigation |
| Loss adjusters | Audit email trails for fraud detection or subrogation |
| Compliance teams | Evidence packs for FCA/FOS/court submissions |

### Scope & Limitations

- **Input**: local `.mbox` file only — no live mailbox, no IMAP/POP, no OAuth, no credentials, no network access
- **Threading**: resolved via standard email headers (`Message-ID`, `In-Reply-To`, `References`)
- **Body**: plain-text snippet only (first 300 chars); no PDF/attachment reading
- **Volume**: processes up to `max_emails` messages (default 5,000) as a safety cap
- Deterministic, reproducible output from the same input file

### Local Demo

```bash
## 1. Export your mailbox to .mbox format (Gmail Takeout / Outlook / Thunderbird)

## 2. Run — no install needed, pure Python 3.10+ stdlib
python3 main.py '{
  "mbox_path": "/path/to/your/export.mbox",
  "claim_keywords": ["claim", "policy", "loss", "settlement"],
  "max_emails": 5000
}'

## 3. Full output including CSV and HTML artifacts
python3 - <<'EOF'
import json
from main import run
result = run({
    "mbox_path": "/path/to/your/export.mbox",
    "claim_keywords": ["claim"],
    "max_emails": 5000
})
print(f"Emails: {result['stats']['total_emails']}")
print(f"Threads: {result['stats']['total_threads']}")
with open("timeline.csv", "w") as f:
    f.write(result["csv_artifact"])
with open("timeline.html", "w") as f:
    f.write(result["html_artifact"])
print("Saved timeline.csv and timeline.html")
EOF
```

### Test Command

```bash
pytest tests/ -v
```

### Supplying your mailbox (on the Apify platform)

A local file path means nothing in a cloud run — your mailbox isn't on the actor's
filesystem. Supply your `.mbox` export one of two private ways:

1. **Key-value store (most private)** — upload your export to this run's key-value
   store and pass its key as `mbox_kvs_key`. **Recommended for sensitive claims
   correspondence.**
2. **Paste** — paste the raw export into `mbox_text` (best for small mailboxes;
   stays in your run input).

**Your mbox never leaves your Apify account** — this actor makes **zero outbound
network calls**. It never uploads, forwards, or fetches your correspondence from
anywhere. (URL ingestion for very large mailboxes is a planned future option.)

The default run uses a **bundled DEMO sample** so you can see the output shape
immediately, before supplying real data.

### Input Schema

| Field | Type | Required | Description |
|---|---|---|---|
| `mbox_kvs_key` | string | ❌ | Key of an mbox record you uploaded to this run's key-value store (most private) |
| `mbox_text` | string | ❌ | Raw `.mbox` content pasted directly (small exports) |
| `mbox_path` | string | ❌ | Local filesystem path; defaults to the bundled DEMO sample. For local runs only — meaningless on the platform |
| `claim_keywords` | array of strings | ❌ | Filter to emails containing any keyword (empty = all emails) |
| `max_emails` | integer | ❌ | Maximum emails to process (default: 5000) |

Supply one mbox source. If none is given, the run uses the bundled DEMO sample.
The chosen source is recorded in the run's `SUMMARY` (never silent).

### Output

| Field | Description |
|---|---|
| `records` | List of email dicts, chronological, thread-annotated |
| `threads` | Dict of `thread_id` → list of `message_id`s |
| `stats` | Summary: total emails, threads, date range |
| `csv_artifact` | CSV text of the full timeline |
| `html_artifact` | Standalone HTML report for printing/sharing |

On the Apify platform these map to:

- **Dataset** — one row per email on the timeline (chronological, thread-annotated). This is the billable unit.
- **Key-value store** — `SUMMARY` (stats + thread index), `TIMELINE_HTML` (the shareable report), `TIMELINE_CSV` (the full timeline as CSV).

A run that matches no correspondence fails loudly with a clear message and is **not** billed — never a silent empty result.

### Pricing (pay-per-event)

| Event | Price |
|---|---|
| Actor start | USD $0.10 per run |
| Correspondence item | USD $0.05 per email placed on the timeline (one dataset row each) |

You pay only for what you time-line. A typical claim file of ~40 emails works out to about **USD $2.10** per timeline (start + 40 items) — costs scale honestly with the size of the correspondence, no flat fee for a two-email dispute. No subscription, no unused-seat waste.

# Actor input Schema

## `mbox_kvs_key` (type: `string`):

Key of a record you uploaded to THIS run's default key-value store containing your raw .mbox export. Your data stays inside your Apify account - it is never fetched over the public internet. Recommended for sensitive claims correspondence.

## `mbox_text` (type: `string`):

Paste the raw contents of a small .mbox export directly. Stays inside your run input (private to your account). Best for small exports; use the key-value store or a signed URL for large mailboxes.

## `mbox_path` (type: `string`):

Path to a .mbox file on the actor's own filesystem. Defaults to the bundled DEMO sample so the actor always has a valid default run. On the Apify platform your real mailbox is NOT on this filesystem - use the key-value store, paste, or signed-URL options above instead.

## `claim_keywords` (type: `array`):

Only include emails whose subject, body snippet, or sender contains at least one of these keywords. Leave empty to include all emails. Examples: \["claim", "policy", "loss", "settlement", "subrogation"].

## `max_emails` (type: `integer`):

Safety cap on the number of emails to read from the mbox. Increase for large mailboxes. Default is 5000.

## Actor input object example

```json
{
  "mbox_path": "sample_data/demo-claims.mbox",
  "claim_keywords": [],
  "max_emails": 5000
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "mbox_path": "sample_data/demo-claims.mbox"
};

// Run the Actor and wait for it to finish
const run = await client.actor("armourylabs/mbox-claims-correspondence-timeline-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "mbox_path": "sample_data/demo-claims.mbox" }

# Run the Actor and wait for it to finish
run = client.actor("armourylabs/mbox-claims-correspondence-timeline-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "mbox_path": "sample_data/demo-claims.mbox"
}' |
apify call armourylabs/mbox-claims-correspondence-timeline-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,armourylabs/mbox-claims-correspondence-timeline-extractor"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/s87F9d9tOlk9JbRyi/builds/1430nz2GgrifTMdW9/openapi.json
