Documentation
¶
Overview ¶
Package inbound receives mail for a workspace (M58): a connected provider's receiving or a mailbox ReputeCast polls. Replies land in Audience › Replies, mailto: unsubscribes are applied, flows can stop when someone replies, DMARC aggregate and feedback-loop reports are collected, and developers get email.replied and email.received webhooks.
Index ¶
- Constants
- Variables
- func Decode(s *linktoken.Signer, workspaceID uuid.UUID, tag string) (letter byte, messageID uuid.UUID, ok bool)
- func Encode(s *linktoken.Signer, letter byte, workspaceID, messageID uuid.UUID) string
- func Erasure() erasure.Source
- func HTMLText(src string) string
- func Register(h huma.API, s *Service)
- type Box
- type HealthArgs
- type HealthWorker
- type Hook
- type InboundAddressView
- type InboundMXRecord
- type InboundMailboxInput
- type InboundMailboxView
- type InboundProviderChoice
- type InboundProviderRef
- type InboundRouteInput
- type InboundRouteView
- type InboundSetupField
- type InboundSetupView
- type InboundTestResult
- type InboundTestView
- type MailboxArgs
- type MailboxWorker
- type NoticeArgs
- type NoticeWorker
- type Parsed
- type ProcessArgs
- type ProcessWorker
- type ReplyAttachment
- type ReplyAuth
- type ReplyContact
- type ReplyCounts
- type ReplyDetail
- type ReplyList
- type ReplyListItem
- type ReplyListParams
- type ReplyPath
- type ReplyPerson
- type ReplySource
- type ReplyStatusInput
- type ReplyStatusResult
- type ReplyUnsubscribeResult
- type Service
- func (s *Service) ContactActivity(ctx context.Context, ws *store.Workspace, contactID uuid.UUID, ...) ([]audience.ContactActivityItem, int64, error)
- func (s *Service) Health(ctx context.Context) error
- func (s *Service) Notice(ctx context.Context) error
- func (s *Service) Poll(ctx context.Context, r store.InboundRoute) (int, error)
- func (s *Service) Process(ctx context.Context, rawID uuid.UUID) error
- func (s *Service) Remove(ctx context.Context, ws *store.Workspace) error
- func (s *Service) Replies(ctx context.Context, ws *store.Workspace, p ReplyListParams) (ReplyList, error)
- func (s *Service) Reply(ctx context.Context, ws *store.Workspace, id uuid.UUID) (ReplyDetail, error)
- func (s *Service) Route(ctx context.Context, wsID uuid.UUID) (store.InboundRoute, error)
- func (s *Service) Save(ctx context.Context, ws *store.Workspace, in InboundRouteInput) (InboundRouteView, error)
- func (s *Service) SendTest(ctx context.Context, ws *store.Workspace) (InboundTestResult, error)
- func (s *Service) SetStatus(ctx context.Context, ws *store.Workspace, in ReplyStatusInput) (ReplyStatusResult, error)
- func (s *Service) Sweep(ctx context.Context) error
- func (s *Service) UnsubscribeContact(ctx context.Context, ws *store.Workspace, id uuid.UUID) (ReplyUnsubscribeResult, error)
- func (s *Service) View(ctx context.Context, ws *store.Workspace) (InboundRouteView, error)
- type State
- type SweepArgs
- type SweepWorker
Constants ¶
const ( LetterReply byte = 'r' LetterUnsubscribe byte = 'u' LetterTest byte = 't' )
Address letters: what a tagged address is for.
const ( LocalDMARC = "dmarc" LocalFBL = "fbl" )
Fixed local parts on a route's domain.
const ( KindReply = "reply" KindUnsubscribe = "unsubscribe" KindDMARCReport = "dmarc_report" KindFeedbackReport = "feedback_report" KindTest = "test" KindOther = "other" )
Kinds of received message (inbound_messages.kind).
const ( EventReplied = "email.replied" EventReceived = "email.received" )
Webhook events (G-20).
const ( ViewOpen = "open" ViewDone = "done" ViewAuto = "auto" ViewSpam = "spam" ViewOther = "other" ViewUnsubscribes = "unsubscribes" )
Reply views.
const MaxHookBody = 25 << 20
MaxHookBody is the largest request the hook accepts: a message with attachments, as a provider posts it (often base64 inside JSON).
const MaxMailboxLocal = 22
MaxMailboxLocal is the longest local part a mailbox route may have: its tagged addresses (<local>+<tag>) stay within the 64 characters RFC 5321 allows a local part.
const (
// MaxText is the most text kept of a message's body.
MaxText = 64 << 10
)
Limits of what a received message keeps.
Variables ¶
var ( ErrNotOwned = errors.New("inbound: the report is about a domain the workspace doesn't send from") ErrNotAReport = errors.New("inbound: not a DMARC aggregate report") )
ErrNotOwned is StoreDMARC's answer for a report about a domain the workspace doesn't send from; ErrNotAReport for a file that isn't one.
Functions ¶
func Decode ¶
func Decode(s *linktoken.Signer, workspaceID uuid.UUID, tag string) (letter byte, messageID uuid.UUID, ok bool)
Decode reads a tag made by Encode for the workspace, in any case: the letter and the message id when its digest holds under the instance key or a previous one.
func Encode ¶
Encode makes the tag of an address for one message of a workspace: "<letter>-" and the base32 of the message id and a keyed digest of the letter, the workspace and the message (41 characters).
func Erasure ¶
Erasure is the personal data received mail holds about contacts: the messages from them or linked to them, and what arrived for those messages (the raw request or message).
Types ¶
type Box ¶
Box is where a route receives: its domain and, for a mailbox route, the mailbox's local part (tags go after a plus).
type HealthArgs ¶
type HealthArgs struct{}
HealthArgs checks provider routes' MX records.
func (HealthArgs) InsertOpts ¶
func (HealthArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type HealthWorker ¶
type HealthWorker struct {
river.WorkerDefaults[HealthArgs]
S *Service
}
HealthWorker runs HealthArgs.
func (*HealthWorker) Work ¶
func (w *HealthWorker) Work(ctx context.Context, _ *river.Job[HealthArgs]) error
Work implements river.Worker.
type Hook ¶
type Hook struct {
S *Service
// contains filtered or unexported fields
}
Hook serves the inbound hook.
type InboundAddressView ¶
InboundAddressView are the fixed addresses on the route's domain.
type InboundMXRecord ¶
type InboundMXRecord struct {
Type string `json:"type"`
Name string `json:"name"`
Value string `json:"value"`
Status string `json:"status" enum:"found,missing,wrong_value,unknown"`
}
InboundMXRecord is one MX record the route's domain needs, with what DNS says.
type InboundMailboxInput ¶
type InboundMailboxInput struct {
Address string `json:"address" maxLength:"254"`
Protocol string `json:"protocol" enum:"imap,pop3"`
Host string `json:"host" maxLength:"253"`
Port int `json:"port,omitempty" minimum:"0" maximum:"65535"`
Security string `json:"security" enum:"tls,starttls"`
Username string `json:"username" maxLength:"254"`
Password string `json:"password,omitempty" maxLength:"500"`
}
InboundMailboxInput is a mailbox route's settings. A blank password keeps the saved one while the server and user name stay the same.
type InboundMailboxView ¶
type InboundMailboxView struct {
Address string `json:"address"`
Protocol string `json:"protocol" enum:"imap,pop3"`
Host string `json:"host"`
Port int `json:"port"`
Security string `json:"security" enum:"tls,starttls"`
Username string `json:"username"`
PasswordSet bool `json:"passwordSet"`
LastPolled *time.Time `json:"lastPolledAt,omitempty"`
}
InboundMailboxView is a mailbox route's settings, without the password.
type InboundProviderChoice ¶
type InboundProviderChoice struct {
ID string `json:"id"`
Name string `json:"name"`
Adapter string `json:"adapter"`
// Inbound is how it receives: automatic, manual, or "" when it can't
// (Reason says so).
Inbound string `json:"inbound" enum:",automatic,manual"`
Reason string `json:"reason,omitempty"`
}
InboundProviderChoice is a connected provider in the setup dialog.
type InboundProviderRef ¶
type InboundProviderRef struct {
ID string `json:"id"`
Name string `json:"name"`
Adapter string `json:"adapter"`
}
InboundProviderRef names a connected provider.
type InboundRouteInput ¶
type InboundRouteInput struct {
Kind string `json:"kind" enum:"provider,mailbox"`
ProviderID string `json:"providerId,omitempty" format:"uuid"`
// Domain is the provider route's domain (reply.news.acme.io).
Domain string `json:"domain,omitempty" maxLength:"253"`
Mailbox *InboundMailboxInput `json:"mailbox,omitempty"`
Settings map[string]string `json:"settings,omitempty"`
}
InboundRouteInput saves the route.
type InboundRouteView ¶
type InboundRouteView struct {
// Status is not_set_up until a route is saved, then pending (waiting
// for the first message), receiving or failing.
Status string `json:"status" enum:"not_set_up,pending,receiving,failing"`
StatusDetail string `json:"statusDetail"`
// StatusReason says what StatusDetail is about: the MX record moved,
// the mailbox refused the sign-in or couldn't be reached, the
// provider refused the registration, or reports were dropped.
StatusReason string `json:"statusReason,omitempty" enum:"mx,mailbox_auth,mailbox_unreachable,register,dropped_reports"`
// SetUpAt is when the route was saved.
SetUpAt *time.Time `json:"setUpAt,omitempty"`
Kind string `json:"kind,omitempty" enum:"provider,mailbox"`
// Provider is the connected provider a provider route receives
// through.
Provider *InboundProviderRef `json:"provider,omitempty"`
Domain string `json:"domain"`
// Mailbox describes a mailbox route (never its password).
Mailbox *InboundMailboxView `json:"mailbox,omitempty"`
Setup InboundSetupView `json:"setup"`
// HookURL is where the provider posts what it receives, for manual
// setups; only people who can manage domains see it (it carries the
// route's token).
HookURL string `json:"hookUrl,omitempty"`
LastReceivedAt *time.Time `json:"lastReceivedAt,omitempty"`
LastTest InboundTestView `json:"lastTest"`
Addresses InboundAddressView `json:"addresses"`
// Choices are the setup dialog's first step: each connected provider
// and whether it can receive.
Choices []InboundProviderChoice `json:"choices"`
// Suggestion is a domain to receive on (reply.<first verified sending
// domain>).
Suggestion string `json:"suggestion"`
// ReplyHandling is the Senders defaults' reply handling ("forward" or
// "inbox").
ReplyHandling string `json:"replyHandling" enum:"forward,inbox"`
CanManage bool `json:"canManage"`
Helpers []string `json:"helpers"`
}
InboundRouteView is Settings › Senders' Receiving mail card.
type InboundSetupField ¶
type InboundSetupField struct {
Key string `json:"key"`
Label string `json:"label"`
Help string `json:"help,omitempty"`
Required bool `json:"required"`
Value string `json:"value"`
}
InboundSetupField is a value a provider's route needs (an SNS topic ARN).
type InboundSetupView ¶
type InboundSetupView struct {
Automatic bool `json:"automatic"`
MX []InboundMXRecord `json:"mx"`
Steps []string `json:"steps"`
Settings []InboundSetupField `json:"settings"`
}
InboundSetupView is what setting the route up takes.
type InboundTestResult ¶
InboundTestResult is the test message just sent.
type InboundTestView ¶
type InboundTestView struct {
SentAt *time.Time `json:"sentAt,omitempty"`
ReceivedAt *time.Time `json:"receivedAt,omitempty"`
}
InboundTestView is the last test message.
type MailboxArgs ¶
type MailboxArgs struct{}
MailboxArgs reads every mailbox route.
func (MailboxArgs) InsertOpts ¶
func (MailboxArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type MailboxWorker ¶
type MailboxWorker struct {
river.WorkerDefaults[MailboxArgs]
S *Service
}
MailboxWorker runs MailboxArgs.
func (*MailboxWorker) Timeout ¶
func (w *MailboxWorker) Timeout(*river.Job[MailboxArgs]) time.Duration
Timeout bounds one round of polls.
func (*MailboxWorker) Work ¶
func (w *MailboxWorker) Work(ctx context.Context, _ *river.Job[MailboxArgs]) error
Work implements river.Worker.
type NoticeArgs ¶
type NoticeArgs struct{}
NoticeArgs tells members about new replies.
func (NoticeArgs) InsertOpts ¶
func (NoticeArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type NoticeWorker ¶
type NoticeWorker struct {
river.WorkerDefaults[NoticeArgs]
S *Service
}
NoticeWorker runs NoticeArgs.
func (*NoticeWorker) Work ¶
func (w *NoticeWorker) Work(ctx context.Context, _ *river.Job[NoticeArgs]) error
Work implements river.Worker.
type Parsed ¶
type Parsed struct {
From, FromName string
To, References []string
Subject, MessageID, InReplyTo string
Header textproto.MIMEHeader
Text string
HasHTML bool
Attachments []providers.InboundAttachment
Date time.Time
}
Parsed is a received message ReputeCast reads: its headers, its body as text and its attachments.
func FromInbound ¶
func FromInbound(m providers.InboundMessage) (Parsed, error)
FromInbound reads what an adapter parsed from its provider's payload: the raw message when the provider passed it, else the fields it filled.
type ProcessArgs ¶
ProcessArgs parses one stored arrival (inbound_raw) and applies what each message in it asks for.
func (ProcessArgs) InsertOpts ¶
func (ProcessArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type ProcessWorker ¶
type ProcessWorker struct {
river.WorkerDefaults[ProcessArgs]
S *Service
}
ProcessWorker runs ProcessArgs.
func (*ProcessWorker) Timeout ¶
func (w *ProcessWorker) Timeout(*river.Job[ProcessArgs]) time.Duration
Timeout bounds one arrival (Resend's raw message is downloaded here).
func (*ProcessWorker) Work ¶
func (w *ProcessWorker) Work(ctx context.Context, job *river.Job[ProcessArgs]) error
Work implements river.Worker.
type ReplyAttachment ¶
type ReplyAttachment struct {
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size"`
}
ReplyAttachment is an attachment as it's kept: its name, type and size.
type ReplyAuth ¶
type ReplyAuth struct {
SPF string `json:"spf,omitempty"`
DKIM string `json:"dkim,omitempty"`
DMARC string `json:"dmarc,omitempty"`
}
ReplyAuth are the receiving server's verdicts.
type ReplyContact ¶
type ReplyContact struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Status string `json:"status"`
}
ReplyContact is the contact a reply came from.
type ReplyCounts ¶
type ReplyCounts struct {
Open int64 `json:"open"`
Done int64 `json:"done"`
Auto int64 `json:"auto"`
Spam int64 `json:"spam"`
Other int64 `json:"other"`
Unsubscribes int64 `json:"unsubscribes"`
}
ReplyCounts are how many messages each view holds, with the same filters.
type ReplyDetail ¶
type ReplyDetail struct {
ReplyListItem
To string `json:"to"`
Text string `json:"text"`
HasHTML bool `json:"hasHtml"`
Attachments []ReplyAttachment `json:"attachments"`
Auth ReplyAuth `json:"auth"`
// SentAt is when the email it answers went out.
SentAt *time.Time `json:"sentAt,omitempty"`
Contact *ReplyContact `json:"contact,omitempty"`
HandledAt *time.Time `json:"handledAt,omitempty"`
CanManage bool `json:"canManage"`
// CanUnsubscribe: the caller may unsubscribe the contact (also
// subscribers:edit), with UnsubscribeReason when not.
CanUnsubscribe bool `json:"canUnsubscribe"`
UnsubscribeReason string `json:"unsubscribeReason,omitempty"`
Helpers []string `json:"helpers"`
}
ReplyDetail is one reply, opened.
type ReplyList ¶
type ReplyList struct {
Items []ReplyListItem `json:"items"`
NextCursor string `json:"nextCursor,omitempty"`
Counts ReplyCounts `json:"counts"`
// Receiving says whether the workspace has an inbound route (the empty
// state differs), and Domain where it receives ("Receiving mail is on
// at reply.news.acme.io").
Receiving bool `json:"receiving"`
Domain string `json:"domain,omitempty"`
// CanManage: the caller may mark replies and unsubscribe contacts.
CanManage bool `json:"canManage"`
}
ReplyList is one view of the replies inbox, newest first.
type ReplyListItem ¶
type ReplyListItem struct {
ID string `json:"id"`
Kind string `json:"kind" enum:"reply,unsubscribe,other"`
From ReplyPerson `json:"from"`
Subject string `json:"subject"`
Preview string `json:"preview"`
ReceivedAt time.Time `json:"receivedAt"`
Status string `json:"status" enum:"open,done"`
AutoReply bool `json:"autoReply"`
Spam bool `json:"spam"`
AsksUnsubscribe bool `json:"asksUnsubscribe"`
Source *ReplySource `json:"source,omitempty"`
ContactID string `json:"contactId,omitempty"`
}
ReplyListItem is one row of the list.
type ReplyListParams ¶
type ReplyListParams struct {
View string
CampaignID *uuid.UUID
AutomationID *uuid.UUID
Query string
Cursor string
Limit int
}
ReplyListParams filter the replies inbox.
type ReplyPath ¶
type ReplyPath struct {
api.WorkspaceInput
ID string `path:"id" format:"uuid" doc:"Reply id"`
}
ReplyPath names a reply.
type ReplyPerson ¶
ReplyPerson is who wrote.
type ReplySource ¶
type ReplySource struct {
Type string `json:"type" enum:"campaign,automation"`
ID string `json:"id"`
Name string `json:"name"`
}
ReplySource is the email a reply answers: a campaign or an automation.
type ReplyStatusInput ¶
type ReplyStatusInput struct {
IDs []string `json:"ids" minItems:"1" maxItems:"500"`
Status string `json:"status" enum:"open,done"`
}
ReplyStatusInput marks replies done or open.
type ReplyStatusResult ¶
type ReplyStatusResult struct {
Updated int `json:"updated"`
}
ReplyStatusResult is how many replies changed.
type ReplyUnsubscribeResult ¶
type ReplyUnsubscribeResult struct {
ContactID string `json:"contactId"`
Already bool `json:"already"`
}
ReplyUnsubscribeResult is the contact after Unsubscribe contact.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Box *secrets.Box
Signer *linktoken.Signer
Factory *manage.Factory
// Mail sends the setup's test message (System mail).
Mail mailer.Sender
Jobs func() *jobs.Client
// Base is the instance's public URL (the hook's address).
Base func() string
DNS dnscheck.Resolver
Log *slog.Logger
Now func() time.Time
// Audience unsubscribes contacts (mailto: unsubscribes, the inbox's
// Unsubscribe contact).
Audience *audience.Service
// MessageUnsubscribed counts an unsubscribe on an automation email's
// step (optout.Deps).
MessageUnsubscribed func(ctx context.Context, q *store.Queries, messageID uuid.UUID, at time.Time) error
// EndRunsOnReply ends the flows a reply stops (automations), inside
// the reply's transaction.
EndRunsOnReply func(ctx context.Context, tx pgx.Tx, workspaceID, automationID, contactID uuid.UUID, at time.Time) (int, error)
// StoreDMARC keeps a DMARC aggregate report that arrived by email
// (deliverability), in tx: ErrNotAReport for a file that isn't one,
// ErrNotOwned (with the report's domain) for a domain the workspace
// doesn't send from.
StoreDMARC func(ctx context.Context, tx pgx.Tx, ws *store.Workspace, data []byte) (domain string, err error)
// ApplyReport applies a feedback-loop report's complaint as an event
// of the provider that sent the message (ingest), in tx; it returns how
// many addresses it newly suppressed.
ApplyReport func(ctx context.Context, tx pgx.Tx, providerID uuid.UUID, source string, receivedAt time.Time, raw []byte, evs []providers.Event) (int, error)
// OnSuppressed is told when a report suppressed addresses (the list's
// health is recounted).
OnSuppressed func(ctx context.Context, workspaceID uuid.UUID)
// Guard dials mailbox routes' servers (hosts people enter).
Guard netguard.Policy
// OpenBox opens a mailbox (bouncebox.Open; tests replace it).
OpenBox func(ctx context.Context, c bouncebox.Config) (bouncebox.Box, error)
// contains filtered or unexported fields
}
Service receives mail for workspaces and serves the replies inbox.
func (*Service) ContactActivity ¶
func (s *Service) ContactActivity(ctx context.Context, ws *store.Workspace, contactID uuid.UUID, before *time.Time, beforeID string, limit int) ([]audience.ContactActivityItem, int64, error)
ContactActivity puts a contact's replies on their timeline (implements audience.ActivitySource): "Replied to {campaign or automation email}", with the reply's id for its Open reply link. Auto-replies, spam and other mail stay off it.
func (*Service) Health ¶
Health looks up each receiving provider route's MX records: a route whose MX no longer names its provider's host becomes failing, and the members who manage domains are told once. It receives again with the next message.
func (*Service) Notice ¶
Notice tells the members who can view replies how many people replied since they were last told, at most every 15 minutes per workspace. Only people's replies count (not auto-replies, spam or other mail).
func (*Service) Poll ¶
Poll reads up to 200 new messages from a mailbox route, stores each with its job, and marks them read (IMAP) or removes them (POP3). A mailbox that can't be read makes the route failing, with the reason.
func (*Service) Remove ¶
Remove stops receiving: the route goes (replies stay), and reply handling goes back to forwarding.
func (*Service) Replies ¶
func (s *Service) Replies(ctx context.Context, ws *store.Workspace, p ReplyListParams) (ReplyList, error)
Replies lists one view of the inbox.
func (*Service) Reply ¶
func (s *Service) Reply(ctx context.Context, ws *store.Workspace, id uuid.UUID) (ReplyDetail, error)
Reply opens one reply.
func (*Service) Save ¶
func (s *Service) Save(ctx context.Context, ws *store.Workspace, in InboundRouteInput) (InboundRouteView, error)
Save sets up or changes the workspace's route.
func (*Service) SetStatus ¶
func (s *Service) SetStatus(ctx context.Context, ws *store.Workspace, in ReplyStatusInput) (ReplyStatusResult, error)
SetStatus marks replies done or open.
func (*Service) Sweep ¶
Sweep requeues verified arrivals still waiting after two minutes, and deletes arrivals after 7 days and received messages after a year.
func (*Service) UnsubscribeContact ¶
func (s *Service) UnsubscribeContact(ctx context.Context, ws *store.Workspace, id uuid.UUID) (ReplyUnsubscribeResult, error)
UnsubscribeContact unsubscribes the contact a reply came from, as the one-click link of the email it answers would (also needs subscribers:edit).
type State ¶
type State struct {
// Route: the workspace has an inbound route.
Route bool
// Receiving: the route receives (its first message arrived and nothing
// says it stopped).
Receiving bool
// Inbox: replies stay in ReputeCast's inbox (reply handling "inbox").
Inbox bool
// Domain and Local are where the route receives: a mailbox route's
// local part, "" for a provider's.
Domain, Local string
// LastDMARC is when the last DMARC report arrived by email.
LastDMARC *time.Time
// Failing: the route stopped receiving; Detail is the sentence
// Receiving mail shows about it (an MX record that moved, a mailbox
// that refused the sign-in).
Failing bool
Detail i18n.Text
}
State is how a workspace receives mail, as the rest of ReputeCast reads it: Settings › Senders (reply handling), Send Readiness, Deliverability's DMARC card and the sending engine.
type SweepArgs ¶
type SweepArgs struct{}
SweepArgs requeues stored arrivals whose job was lost and purges old ones.
func (SweepArgs) InsertOpts ¶
func (SweepArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type SweepWorker ¶
type SweepWorker struct {
river.WorkerDefaults[SweepArgs]
S *Service
}
SweepWorker runs SweepArgs.