Skip to content

fix(inbound): accept email replies only from the ticket's requester - #95

Merged
mpge merged 2 commits into
mainfrom
fix/inbound-reply-sender-check
Oct 3, 2026
Merged

mpge merged 2 commits into
mainfrom
fix/inbound-reply-sender-check

Conversation

@mpge

@mpge mpge commented Oct 3, 2026

Copy link
Copy Markdown
Member

Ports escalated-laravel #220 and the updated domain-model/email-threading.md rule.

Change

  • InboundEmailRouter: with escalated.email.inbound-secret set, only the signed Reply-To address (reply+{id}.{hmac8}@domain) resolves a ticket. In-Reply-To / References / subject reference are used only when no secret is configured. (The webhook itself already requires the secret, so in practice the signed address is the only link.)
  • InboundEmailService: a matched message becomes a reply only when From equals the ticket's requester_email (trimmed, case-insensitive). The reply is posted with the ticket's requester name/email, never the From values, and reopens a RESOLVED/CLOSED ticket. Any other sender (including an agent's address) gets a new ticket; the matched ticket is not modified. Mail is never dropped.
  • README inbound section and CHANGELOG updated.

No tenancy layer exists in this port, so none to respect.

Tests

New InboundEmailServiceTest:

  • stranger quoting [ESC-…] in the subject -> new ticket, no reply
  • stranger threading onto a closed ticket -> new ticket, no status change
  • agent address in From with a valid signed Reply-To -> not posted as the agent, new ticket
  • requester reply (From in different case) -> reply posted as the requester, ticket reopened
  • requester reply to an open ticket -> no status change
  • secret set, unsigned recipient with valid headers + subject -> new ticket

InboundEmailRouterTest: headers/subject ignored once a secret is configured; signed Reply-To wins over headers.

The five scenario tests failed on main before the fix.

Local runs

  • ./gradlew test (H2): 363 tests, 0 failures, 9 skipped
  • ./gradlew checkstyleMain checkstyleTest: no findings in touched files
  • PostgreSQL/MySQL legs: left to CI (no schema or query changes; new tests are Mockito unit tests)

mpge added 2 commits October 3, 2026 11:21
A thread match (In-Reply-To, References, subject reference) was posted as
a reply from whoever sent the message, under the From name and address.
A matched message now becomes a reply only when From equals the ticket's
requester email (case-insensitive), is posted as the requester, and
reopens a resolved or closed ticket. Other senders get a new ticket and
the matched ticket is left untouched.

With an inbound secret configured, only the signed Reply-To address links
a message to a ticket; the guessable headers and subject reference are
used only when no secret is set.
@mpge
mpge merged commit 91d448e into main Oct 3, 2026
4 checks passed
@mpge mpge mentioned this pull request Oct 8, 2026
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