Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mailtrap/models/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class InboundThreadMessageDelivery:
status: Literal["delivered", "not_delivered", "enqueued", "opted_out"]
delivered_at: Optional[str] = None
bounced_at: Optional[str] = None
rejected_at: Optional[str] = None


class InboundThreadMessage(BaseModel):
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/api/inbound/test_inbound_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_get_by_id_should_return_thread_with_messages(
"status": "delivered",
"delivered_at": "2026-05-08T11:40:05.000Z",
"bounced_at": None,
"rejected_at": None,
},
},
{"visibility_status": "placeholder", "direction": "inbound"},
Expand All @@ -168,10 +169,50 @@ def test_get_by_id_should_return_thread_with_messages(
assert outbound.delivery.status == "delivered"
assert outbound.delivery.delivered_at == "2026-05-08T11:40:05.000Z"
assert outbound.delivery.bounced_at is None
assert outbound.delivery.rejected_at is None

assert placeholder.delivery is None
assert placeholder.forwards is None

@responses.activate
def test_get_by_id_should_map_rejected_at_on_delivery(
self, threads_api: InboundThreadsApi
) -> None:
responses.get(
f"{BASE_URL}/{THREAD_ID}",
json={
"id": THREAD_ID,
"subject": "Billing",
"message_count": 1,
"size": 0,
"first_message_at": "2026-01-15T10:00:00Z",
"last_activity_at": "2026-01-15T10:00:00Z",
"messages": [
{
"visibility_status": "available",
"direction": "outbound",
"from": "support@inbound-mailtrap.io",
"delivery": {
"to": "suppressed@example.com",
"status": "not_delivered",
"delivered_at": None,
"bounced_at": None,
"rejected_at": "2026-01-15T10:00:01.000Z",
},
},
],
},
status=200,
)

thread = threads_api.get_by_id(INBOX_ID, THREAD_ID)

delivery = thread.messages[0].delivery
assert isinstance(delivery, InboundThreadMessageDelivery)
assert delivery.status == "not_delivered"
assert delivery.bounced_at is None
assert delivery.rejected_at == "2026-01-15T10:00:01.000Z"

@pytest.mark.parametrize(
"status_code,response_json,expected_error_message",
[
Expand Down
Loading