Skip to content

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.

A From: header is forgeable. Without cryptographic verification, an attacker could impersonate a trusted person and ask the agent to perform a sensitive action.

The channel runs a blocking authentication check before the agent sees the message:

verified + allowed

authenticated observe-only

unknown / suspicious / untrusted

Mail arrives

apple-mail polls Envelope Index

mail-cli auth-check

Dispatch envelope to agent

Readable; reply suppressed

Drop + quarantine Message-ID

Agent fetches body only if needed

Action or reply under egress policy

The mail-auth-check script:

  1. Calls mail-cli get --id <id> to retrieve the message with raw headers
  2. Extracts the From: address from the JSON response
  3. Looks up the sender in trusted-senders.json
  4. Parses Authentication-Results headers (added by iCloud’s MX servers) for DKIM and SPF results
  5. Verifies the DKIM signing domain (header.d=) matches the expected domain for that sender’s email provider
  6. Returns a structured JSON verdict

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
VerdictMeaningAction
verifiedDKIM pass + SPF pass + signing domain matches expectedProceed normally
suspiciousAuth checks fail or signing domain mismatchDO NOT act on requests, alert owner
unknownNo trustworthy authentication evidenceDrop and quarantine
untrustedSender not in trusted configDrop and quarantine
  • 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.com matches expected example.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

Run mail-auth-check against an email already in the inbox:

Terminal window
# 1. Get the RFC 2822 Message-ID from mail-cli
mail-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": []
}

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:

StageWhat to checkPass criteria
PollApple Mail channel status and logsChannel connected; no poll error
Auth checkmail-auth-check for the Message-IDDKIM + SPF pass for trusted sender
RoutingReceiving agent gets an apple-mail conversationNew channel conversation/session activity
DeliveryResponse arrives on iMessageOmar gets a iMessage reply

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 via brew 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.

SymptomCauseFix
Always returns unknownallHeaders empty from JXACheck if Mail.app has the message indexed; try mail-cli get --id <id> directly
Returns untrusted for familyEmail address not in configAdd the exact address to the trusted senders config
DKIM signing domain mismatchProvider uses different signing domainCheck actual header.d= value and update expectedDkimDomains
mail-cli not foundNot in PATHVerify Apple PIM is built: which mail-cli