Skip to content

feat(inbound): MailgunInboundParser#45

Merged
mpge merged 4 commits intomasterfrom
feat/mailgun-inbound-parser
Apr 27, 2026
Merged

feat(inbound): MailgunInboundParser#45
mpge merged 4 commits intomasterfrom
feat/mailgun-inbound-parser

Conversation

@mpge
Copy link
Copy Markdown
Member

@mpge mpge commented Apr 27, 2026

Recovers auto-closed #32. Rebased onto current master.

mpge added 4 commits April 26, 2026 22:01
…Router

Greenfield inbound-email foundation for Symfony. Transport-agnostic
InboundMessage + InboundAttachment DTOs, InboundEmailParser
interface, and InboundRouter that resolves an inbound email to an
existing ticket via canonical Message-ID parsing + signed Reply-To
verification.

Completes the 5-framework greenfield inbound set. Mirrors the NestJS
reference, the 5 per-framework inbound-verify PRs (Laravel, Rails,
Django, Adonis, WordPress), and the .NET / Spring / Go / Phoenix
greenfield routers.

Resolution order (first match wins):
  1. In-Reply-To parsed via MessageIdUtil — cold-start path.
  2. References parsed via MessageIdUtil, each id in order.
  3. Signed Reply-To on toEmail verified via MessageIdUtil. Survives
     clients that strip threading headers; forged signatures are
     rejected via hash_equals (timing-safe).
  4. Subject-line reference tag [{PREFIX}-...].

10 PHPUnit tests verify every branch, the forged-signature rejection,
the blank-secret skip, the ordering helper, and the InboundMessage
body() text/html preference logic.
Closes the core inbound webhook for Symfony end-to-end (stacked on
#30's router foundation). Completes the 5-framework greenfield
inbound set — .NET #24, Spring #27, Go #30, Phoenix #36, Symfony.

- PostmarkInboundParser: normalizes Postmark's JSON webhook payload
  (FromFull / ToFull / Headers / Attachments) into InboundMessage.
  Extracts threading headers from the Headers array. Decodes base64
  attachment content inline via base64_decode with strict=true;
  falls back gracefully to null when decoding fails.

- InboundEmailController (#[Route] -attributed): POST
  /escalated/webhook/email/inbound
  - Dispatches to the matching parser by ?adapter=... query or
    X-Escalated-Adapter header. Parsers are injected via
    #[TaggedIterator('escalated.inbound_parser')] so host apps can
    register additional providers just by tagging their service.
  - Signature-guarded by X-Escalated-Inbound-Secret (constant-time
    hash_equals compare). Same secret that signs Reply-To —
    symmetric.
  - Returns 202 Accepted with { status, ticket_id } on success,
    401 on secret mismatch, 400 on unknown adapter / invalid
    payload.

5 parser tests cover field extraction, threading header parsing,
base64 attachment decoding, minimal-payload path, and the adapter
name contract — all pass locally.
Adds Mailgun as the second supported inbound provider alongside
Postmark (from #31). Completes Mailgun parity across all 5
greenfield frameworks — .NET #25, Spring #28, Go #31, Phoenix #37,
Symfony.

Register the service with the escalated.inbound_parser tag and the
controller picks it up via TaggedIterator alongside PostmarkParser.

Notes:
- from: typically 'Name <email>' — extractFromName pulls the
  display portion, strips surrounding quotes. Falls back to sender
  field for the email.
- Mailgun hosts attachment content behind a URL; we carry the URL
  in downloadUrl. A follow-up worker fetches + persists out-of-band.
- Malformed attachments JSON degrades gracefully (empty list).

8 PHPUnit tests verified locally (8 tests, 19 assertions, OK).
@mpge mpge merged commit 0ad2bda into master Apr 27, 2026
1 check passed
@mpge mpge deleted the feat/mailgun-inbound-parser branch April 27, 2026 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant