Add Inbound Email API support - #73
Conversation
CreateInboundFolder, UpdateInboundFolder, CreateInboundInbox (optional domain_id), and UpdateInboundInbox — RequestInterface DTOs whose toArray() produces the flat inbound API payloads.
Move getPayload() and its address/attachment/header helpers into a reusable trait so the inbound reply/forward API can map a Symfony Mime Email to the Mailtrap payload the same way the send API does. Pure refactor — no behavior change (send/batch tests unchanged).
|
Warning Review limit reached
Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (22)
📝 WalkthroughWalkthroughThe PR adds inbound folder, inbox, message, and thread APIs. It adds shared email payload serialization, inbound-receiving webhook support, client wiring, tests, documentation, and PHP examples. ChangesInbound Email API
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Application
participant MailtrapClient
participant MailtrapInboundClient
participant InboundResource
participant MailtrapAPI
Application->>MailtrapClient: Select inbound()
MailtrapClient->>MailtrapInboundClient: Create inbound client
Application->>InboundResource: Call folder, inbox, message, or thread operation
InboundResource->>MailtrapAPI: Send token-scoped request
MailtrapAPI-->>InboundResource: Return response
InboundResource-->>Application: Return handled response
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/README.md`:
- Around line 41-76: Insert one blank line between each affected section heading
and its following table in the README: Inbound Email, Contact Management,
Templates & Domains, General API, and Framework Bridges. Preserve the table
contents and existing formatting.
In `@src/Api/Inbound/Message.php`:
- Around line 53-88: The forward method must require at least one recipient in
the email’s “to” field, rejecting cc-only or bcc-only payloads. Add validation
in reply and replyAll to reject emails missing both text and html before
invoking httpPost, while preserving their existing request flow for valid
bodies.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e2297fb9-984f-44b4-86d6-eeccc9fda7e3
📒 Files selected for processing (28)
README.mdexamples/README.mdexamples/inbound/folders.phpexamples/inbound/inboxes.phpexamples/inbound/messages.phpexamples/inbound/threads.phpsrc/Api/AbstractEmails.phpsrc/Api/EmailPayloadTrait.phpsrc/Api/Inbound/Folder.phpsrc/Api/Inbound/InboundInterface.phpsrc/Api/Inbound/Inbox.phpsrc/Api/Inbound/Message.phpsrc/Api/Inbound/Thread.phpsrc/DTO/Request/Inbound/CreateInboundFolder.phpsrc/DTO/Request/Inbound/CreateInboundInbox.phpsrc/DTO/Request/Inbound/UpdateInboundFolder.phpsrc/DTO/Request/Inbound/UpdateInboundInbox.phpsrc/DTO/Request/Webhook/CreateWebhook.phpsrc/DTO/Request/Webhook/UpdateWebhook.phpsrc/DTO/Request/Webhook/Webhook.phpsrc/MailtrapClient.phpsrc/MailtrapInboundClient.phptests/Api/Inbound/FolderTest.phptests/Api/Inbound/InboxTest.phptests/Api/Inbound/MessageTest.phptests/Api/Inbound/ThreadTest.phptests/Api/Sending/WebhookTest.phptests/MailtrapInboundClientTest.php
Token-scoped Folder, Inbox, Message, and Thread endpoint classes under /api/inbound, exposed via a new MailtrapInboundClient layer (client->inbound()). Message reply/replyAll/forward accept a Symfony Mime Email and reuse EmailPayloadTrait; forward requires a recipient.
PHPUnit coverage for the inbound Folder, Inbox, Message, and Thread APIs (token-scoped URLs, flat request bodies, last_id pagination, Email-to-payload mapping for reply/reply_all/forward, forward recipient guard) plus the MailtrapInboundClient layer.
Support inbound_receiving webhooks: add the TYPE_INBOUND_RECEIVING constant and an optional inbound_inbox_id field to CreateWebhook and UpdateWebhook (omit to apply the webhook to all inboxes).
Per-resource runnable examples under examples/inbound/ — folders.php, inboxes.php, messages.php (reply/reply_all/forward), and threads.php — plus Inbound Email entries in README.md and examples/README.md. Also drop the numeric prefixes from the examples index headings so new sections no longer require renumbering.
Summary
Adds Inbound Email API support to the PHP SDK, matching the other Mailtrap SDKs. Exposed as a new token-scoped
inbound()layer (no account id required):folders():getList/getById/create/update/deleteinboxes($folderId): folder-scoped CRUD (createtakes an optional domain id)messages($inboxId):getList(cursor vialast_id) /getById/delete+reply/replyAll/forward(send real email)threads($inboxId):getList/getById/deleteNotes
/api/inbound/...; theinbound()layer and its endpoint classes take only path ids, mirroring theGeneral\Accountprecedent.reply/replyAll/forwardaccept aSymfony\Component\Mime\Email— exactly like the send API. To reuse the existingEmail→ payload mapping,getPayload()and its helpers were extracted fromAbstractEmailsinto a newEmailPayloadTrait(pure refactor, no behavior change).forwardrequires at least one recipient.inbound_inbox_idto the webhook DTOs (CreateWebhook/UpdateWebhook) and aTYPE_INBOUND_RECEIVINGconstant, forinbound_receivingwebhooks.inbound_inbox_idis optional (omit to apply to all inboxes).ResponseHelper::toArray), so those keys already flow through.Summary by CodeRabbit
New Features
Refactor
Documentation