feat(inbound): AttachmentDownloader for provider-hosted attachments#29
Open
mpge wants to merge 1 commit intofeat/inbound-email-orchestrationfrom
Open
feat(inbound): AttachmentDownloader for provider-hosted attachments#29mpge wants to merge 1 commit intofeat/inbound-email-orchestrationfrom
mpge wants to merge 1 commit intofeat/inbound-email-orchestrationfrom
Conversation
Ports the Go reference (escalated-go#35) to .NET. Closes the last
gap in the Phase-5 inbound pipeline: host apps now have a ready-to-wire
worker for Mailgun-style provider-hosted attachments surfaced in
ProcessResult.PendingAttachmentDownloads.
AttachmentDownloader
- DownloadAsync(pending, ticketId, replyId?) → HTTP GET + persist
via IAttachmentStorage + Attachment row on the EF Core context.
- DownloadAllAsync continues past per-attachment failures so a bad
URL doesn't block the rest; returns AttachmentDownloadResult per
input (Persisted or Error set).
- AttachmentDownloaderOptions controls MaxBytes size cap (rejects
with AttachmentTooLargeException sentinel) + optional BasicAuth
credentials for providers that gate URLs by API key (Mailgun).
- SafeFilename uses Path.GetFileName so "../../etc/passwd" becomes
"passwd" — crafted attachment names can't escape the storage root.
- Response Content-Type fallback when the PendingAttachment's own
ContentType is empty.
IAttachmentStorage
- Minimal contract (Name + PutAsync). Host apps with S3/Azure/GCS
wire their own adapter; the reference LocalFileAttachmentStorage
writes to local disk with timestamp+ticks filename prefixing
so concurrent uploads with the same original name don't collide.
12 xUnit tests cover: happy path (both ticket + reply attachable
targets), 404 → throw + no persist, oversize → AttachmentTooLarge +
no persist, basic auth header encoding, missing URL guard, response
Content-Type fallback, SafeFilename Theory with path-traversal +
edge-case inputs, DownloadAllAsync partial-failure handling, and
LocalFileAttachmentStorage write / empty-root rejection / unique
path per call.
This was referenced Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ports the Go reference (escalated-go#35) to .NET. Host apps now have a ready-to-wire worker for the Mailgun-style provider-hosted attachments surfaced in `ProcessResult.PendingAttachmentDownloads` — before this PR those URLs were returned but never fetched.
Design
`AttachmentDownloader`
`IAttachmentStorage`
Tests
12 xUnit cases:
Stacked PR
Based on `feat/inbound-email-orchestration` (#26) so `PendingAttachment` + `ProcessResult` are available. Merge order: #23 → #24 → #25 → #26 → this PR.