Documentation
¶
Overview ¶
Package api owns the HTTP layer: the chi router, the JSON wire types, and the handlers. Wire format is snake_case throughout to align with the conventions used across the rest of the Mailtrap toolchain (sandbox API, Mailtrap CLI).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttachmentSummary ¶
type AttachmentSummary struct {
PartID string `json:"part_id"`
FileName string `json:"file_name"`
ContentType string `json:"content_type"`
ContentID string `json:"content_id"`
Size int64 `json:"size"`
Checksums Checksums `json:"checksums"`
}
AttachmentSummary is the metadata shape — bytes are fetched separately via /message/:id/part/:part_id.
type Checksums ¶
type Checksums struct {
MD5 string `json:"md5"`
SHA1 string `json:"sha1"`
SHA256 string `json:"sha256"`
}
Checksums is the trio of content fingerprints stored alongside each attachment.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse is the plain JSON error shape used everywhere.
type ListUnsubscribe ¶
type ListUnsubscribe struct {
Header string `json:"header"`
Links []string `json:"links"`
Errors string `json:"errors"`
HeaderPost string `json:"header_post"`
}
ListUnsubscribe mirrors the parsed `List-Unsubscribe` header.
type MessageDetail ¶
type MessageDetail struct {
ID string `json:"id"`
MessageID string `json:"message_id"`
From Address `json:"from"`
To []Address `json:"to"`
Cc []Address `json:"cc"`
Bcc []Address `json:"bcc"`
ReplyTo []Address `json:"reply_to"`
ReturnPath string `json:"return_path"`
Subject string `json:"subject"`
ListUnsubscribe ListUnsubscribe `json:"list_unsubscribe"`
Date string `json:"date"`
Tags []string `json:"tags"`
Username string `json:"username"`
Text string `json:"text"`
HTML string `json:"html"`
Size int64 `json:"size"`
Inline []AttachmentSummary `json:"inline"`
Attachments []AttachmentSummary `json:"attachments"`
// mailtrap-local extensions (safely ignored by clients that don't
// know them).
EnvelopeFrom string `json:"envelope_from"`
EnvelopeTo []string `json:"envelope_to"`
}
MessageDetail is the full shape from `GET /message/:id`. Includes `envelope_from` / `envelope_to` extensions surfaced in the Tech Info tab; clients that don't recognise them ignore them.
func WireDetail ¶
func WireDetail(m *store.Message, inline, attachments []store.Part) MessageDetail
WireDetail is the package-public wrapper around toWireDetail.
type MessageSummary ¶
type MessageSummary struct {
ID string `json:"id"`
MessageID string `json:"message_id"`
Read bool `json:"read"`
From Address `json:"from"`
To []Address `json:"to"`
Cc []Address `json:"cc"`
Bcc []Address `json:"bcc"`
ReplyTo []Address `json:"reply_to"`
Subject string `json:"subject"`
Created string `json:"created"`
Username string `json:"username"`
Tags []string `json:"tags"`
Size int64 `json:"size"`
Attachments int `json:"attachments"`
Snippet string `json:"snippet"`
}
MessageSummary is a list-row in `GET /messages` and `GET /search`.
func WireSummary ¶
func WireSummary(m *store.Message, attachmentsCount int) MessageSummary
WireSummary is the package-public wrapper around toWireSummary so other packages (e.g. main.go's broadcast helper) can produce the exact same JSON the list endpoint emits.
type MessagesResponse ¶
type MessagesResponse struct {
Total int `json:"total"`
Unread int `json:"unread"`
Count int `json:"count"`
MessagesCount int `json:"messages_count"`
MessagesUnread int `json:"messages_unread"`
Start int `json:"start"`
Tags []string `json:"tags"`
Messages []MessageSummary `json:"messages"`
}
MessagesResponse is the envelope for `GET /messages` and `GET /search`.
type Server ¶
type Server struct {
Store *store.Store
Hub *live.Hub
Relay *relay.Client
Webhook *webhook.Client
Config *config.Loader
Frontend fs.FS // production: embedded SPA dist; dev: nil (Vite serves it)
OpenAPI []byte
Build BuildInfo
// OnIngest fires after a successful POST /api/v1/ingest. Wired by
// main.go to trigger the dispatcher (cloud mirror / relay mirror /
// webhook delivery / retention / live broadcast).
OnIngest func(msgID string)
}
Server is the HTTP layer. Holds every dependency the handlers reach for, so handlers stay pure functions of the request.
type VersionResponse ¶
type VersionResponse struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildDate string `json:"build_date"`
}
VersionResponse is the wire shape for GET /api/v1/version.