Files
webmail-client/backend/app/outbox/schemas.py
T
lukasandClaude Opus 5.5 609e7c58f9 Unreachable mail servers: send retries in Scheduled, real action retries, account health
Sending: a send the server could not take (unreachable, timeout, 4xx) is no
longer failed at once. It waits in Scheduled ("retrying") and is tried again
after 1, 2, 5, 10, 30 min, then hourly, for 24 hours — on the server, so it
works with the browser closed. A permanent refusal (5xx, wrong password) is
"failed" at once, with the server's reason. GET /outbox lists both;
POST /outbox/{id}/retry (Retry now) and /cancel (Edit, Delete) act on them,
and they are left out of Drafts. Mail delivered but not filed in Sent now
counts as sent, and a conditional claim keeps two jobs from sending one
message twice. The app says when a send failed and when it finally went.

Actions: arq retries a job only on Retry, never on a plain exception, so the
"retry x5, then revert" for flags and moves never happened. Flag, move,
archive, restore, delete and empty-folder jobs now raise Retry while the
server is unreachable (~24 hours of growing gaps), skip a change a later one
replaced, stop at the first connection failure instead of 20 s per message,
and delete/empty keep the rows until the server has the messages gone.

Account health: 3 failed connections in a row mark an account unreachable
(amber in the sidebar and Settings, cleared on the next success); 3 refused
sign-ins stop its syncing as auth_failed until the password is entered
again, so the provider does not lock the account. Sync loops back off 30 s
doubling to 10 min and log one line per expected failure; a refused
connection fails at once with its reason (the connect task is kept), and a
silently dead IDLE connection is noticed within ~11 min instead of ~29.

Also: the empty reading pane is clipped to its width when dragged very
narrow; tests no longer leave live accounts and outbox rows in the database.

Migration 0021: outbox attempts / next_attempt_at / retry_until, accounts
sync_error / sync_error_since.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 22:08:42 +02:00

84 lines
1.9 KiB
Python

"""Compose/draft/send request & response models (SPEC §9.1)."""
from __future__ import annotations
import uuid
from pydantic import BaseModel
class DraftPayload(BaseModel):
to: list[str] = []
cc: list[str] = []
bcc: list[str] = []
subject: str = ""
html: str = ""
text: str = ""
attachment_ids: list[uuid.UUID] = []
class DraftIn(BaseModel):
account_id: uuid.UUID
thread_id: uuid.UUID | None = None
reply_to_message_id: uuid.UUID | None = None
kind: str = "new" # reply | reply_all | forward | new
payload: DraftPayload
class DraftOut(BaseModel):
id: uuid.UUID
account_id: uuid.UUID
thread_id: uuid.UUID | None
reply_to_message_id: uuid.UUID | None
kind: str
payload: dict[str, object]
updated_at: str
class RemoteDraftOut(BaseModel):
"""A draft found in the account's IMAP Drafts folder (created on another client)."""
message_id: uuid.UUID
account_id: uuid.UUID
imap_uid: int
subject: str
to: list[str]
cc: list[str]
bcc: list[str]
snippet: str
updated_at: str
class SendRequest(BaseModel):
draft_id: uuid.UUID
class SendResponse(BaseModel):
outbox_id: uuid.UUID
undo_until: str
# The same deadline as seconds from now: the browser counts down from this,
# since its clock may be seconds off the server's.
undo_seconds: float
class OutboxStateOut(BaseModel):
outbox_id: uuid.UUID
state: str
class OutboxItemOut(BaseModel):
"""A send waiting in the Scheduled folder: being retried, or failed for good."""
outbox_id: uuid.UUID
draft_id: uuid.UUID
account_id: uuid.UUID
state: str # "retrying" | "failed"
attempts: int
error: str | None
next_attempt_at: str | None
retry_until: str | None
sent_at: str # when Send was pressed (the end of the undo window)
to: list[str]
subject: str
preview: str