// Package coordinatormail contains offline policy groundwork, not a mail // adapter. Nothing here provisions a mailbox, sends mail or authorizes actions. package coordinatormail import ( "errors" "net/mail" "strings" ) var ErrPolicy = errors.New("coordinator mail: policy refused") // Scope is resolved from trusted Equipo storage, never from email headers. // Address must be the authenticated person's currently verified bare address. type Scope struct { Team, Person, Address, Coordinator, Project, Task, Thread string } func (s Scope) valid() bool { return s.Team != "" && s.Person != "" && bareAddress(s.Address) && s.Coordinator != "" && s.Project != "" && s.Task != "" && s.Thread != "" } func bareAddress(s string) bool { if strings.ContainsAny(s, "\r\n") { return false } a, err := mail.ParseAddress(s) return err == nil && a.Name == "" && a.Address == s } // Outbound is a policy snapshot. Re-resolve it immediately before dispatch. // Recipient is singular by design: no Cc, Bcc, arbitrary recipients or aliases. type Outbound struct { Scope Recipient, Sender, SenderLabel string Configured, Authorized bool Verified, Active, OptedIn bool Suppressed bool } func CheckOutbound(o Outbound) error { if !o.Scope.valid() || !o.Configured || !o.Authorized || !o.Verified || !o.Active || !o.OptedIn || o.Suppressed || o.Recipient != o.Address || !bareAddress(o.Sender) || o.Sender == o.Address || o.SenderLabel != "Equipo coordinator" { return ErrPolicy } return nil } // Reply contains ONLY server-resolved facts. An adapter must authenticate the // transport and verify the sender binding before constructing it. These flags // are not evidence by themselves and must never be decoded from an HTTP body. // A signed delivery webhook proves delivery, not the author's identity. type Reply struct { Expected, Bound Scope EventID string TransportVerified, SenderBound, RouteVerified bool Active, Automated, FromCoordinator bool } // CheckReply permits importing untrusted discussion into an existing thread. // It never permits creating tasks, routing instructions or approving actions. // Quoted text, forwarding and attachments cannot alter the resolved scope. func CheckReply(r Reply) error { if !r.Expected.valid() || r.Expected != r.Bound || r.EventID == "" || !r.TransportVerified || !r.SenderBound || !r.RouteVerified || !r.Active || r.Automated || r.FromCoordinator { return ErrPolicy } return nil }