Email Sender Authentication
The apple-mail channel polls Apple Mail, verifies sender identity before dispatch,
and quarantines refused Message-IDs. The former Mail.app rule, AppleScript trigger,
and classifier agent are retired.
Email Sender Authentication (DKIM/SPF)
Section titled “Email Sender Authentication (DKIM/SPF)”A From: header is forgeable. Without cryptographic verification, an attacker could impersonate a trusted person and ask the agent to perform a sensitive action.
How It Works
Section titled “How It Works”The channel runs a blocking authentication check before the agent sees the message:
The mail-auth-check script:
- Calls
mail-cli get --id <id>to retrieve the message with raw headers - Extracts the
From:address from the JSON response - Looks up the sender in
trusted-senders.json - Parses
Authentication-Resultsheaders (added by iCloud’s MX servers) for DKIM and SPF results - Verifies the DKIM signing domain (
header.d=) matches the expected domain for that sender’s email provider - Returns a structured JSON verdict
Configuration
Section titled “Configuration”Trusted senders are defined in a JSON config file:
{ "trustedSenders": [ { "name": "Owner", "emails": ["owner@example.com"], "expectedDkimDomains": ["example.com"], "requireDkim": true, "requireSpf": true }, { "name": "Partner", "emails": ["partner@gmail.com"], "expectedDkimDomains": ["gmail.com"], "requireDkim": true, "requireSpf": true } ]}Each entry maps a person to:
- Their email addresses
- The DKIM signing domains expected from their email provider (e.g., Fastmail signs as the custom domain, Gmail signs as
gmail.com) - Whether DKIM and SPF are required for verification
Verdict Values
Section titled “Verdict Values”| Verdict | Meaning | Action |
|---|---|---|
verified | DKIM pass + SPF pass + signing domain matches expected | Proceed normally |
suspicious | Auth checks fail or signing domain mismatch | DO NOT act on requests, alert owner |
unknown | No trustworthy authentication evidence | Drop and quarantine |
untrusted | Sender not in trusted config | Drop and quarantine |
Implementation Details
Section titled “Implementation Details”- Handles dual DKIM signatures (e.g., Fastmail signs with both the custom domain and infrastructure domain). Parser collects all DKIM results and checks if any match expected domains.
- Supports subdomain matching (
mail.example.commatches expectedexample.com) - Fails closed when headers are absent or unreadable; the standalone checker returns
unknown, and the channel refuses dispatch - Message ID must be an RFC 2822 Message-ID (e.g.,
ABC123@shahine.com), not an Apple Mail numeric ID - Message IDs are validated for safe characters to prevent shell injection
Testing
Section titled “Testing”Quick check: mail-auth-check standalone
Section titled “Quick check: mail-auth-check standalone”Run mail-auth-check against an email already in the inbox:
# 1. Get the RFC 2822 Message-ID from mail-climail-cli messages --account iCloud --mailbox INBOX --limit 5 --format json \ | python3 -c "import json,sys; [print(f'{m[\"messageId\"]} {m[\"subject\"][:60]}') for m in json.load(sys.stdin)]"
# 2. Run auth check with the Message-ID (NOT the numeric Apple Mail ID)mail-auth-check "ABC123-DEF456@shahine.com"Expected output for a legitimate email:
{ "verdict": "verified", "sender": "owner@example.com", "matchedContact": "Owner", "checks": { "dkim": { "result": "pass", "signingDomain": "example.com", "expected": ["example.com"], "match": true }, "spf": { "result": "pass", "match": true } }, "warnings": []}Smoke test: full channel pipeline
Section titled “Smoke test: full channel pipeline”This tests the complete path: email delivery → channel poll → auth check → direct agent dispatch → requested action.
Step 1 — Send a test email from a trusted sender (e.g., Omar’s Fastmail) to lobster.claw@icloud.com. Include a clear instruction so you can verify Lobster acts on it:
Subject: Smoke test Body: If you get this, post a message on Omar’s iMessage confirming you received it.
Step 2 — Wait for processing. The poll interval is normally 60 seconds. Check channel status, logs, and the receiving agent session within two minutes.
Step 3 — Verify each stage:
| Stage | What to check | Pass criteria |
|---|---|---|
| Poll | Apple Mail channel status and logs | Channel connected; no poll error |
| Auth check | mail-auth-check for the Message-ID | DKIM + SPF pass for trusted sender |
| Routing | Receiving agent gets an apple-mail conversation | New channel conversation/session activity |
| Delivery | Response arrives on iMessage | Omar gets a iMessage reply |
Spoofing test
Section titled “Spoofing test”Send a forged email to verify mail-auth-check returns suspicious. Port 25 is typically blocked on residential networks, so use one of:
swaks(install viabrew install swaks) from a server or network that allows outbound SMTP:Terminal window swaks --to lobster.claw@icloud.com --from "omar@shahine.com" \--header "Subject: SPOOF TEST" \--body "Forged sender test." \--server mx01.mail.icloud.com- Web-based anonymous mailer — search for “anonymous email sender” and send with a forged
From:header - A VPS with port 25 open (most cloud providers allow it on dedicated servers)
After the spoofed email arrives, run mail-auth-check against it and verify the verdict is suspicious with warnings about DKIM/SPF failure.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
Always returns unknown | allHeaders empty from JXA | Check if Mail.app has the message indexed; try mail-cli get --id <id> directly |
Returns untrusted for family | Email address not in config | Add the exact address to the trusted senders config |
| DKIM signing domain mismatch | Provider uses different signing domain | Check actual header.d= value and update expectedDkimDomains |
mail-cli not found | Not in PATH | Verify Apple PIM is built: which mail-cli |