oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// Package coordinatormail contains offline policy groundwork, not a mail
2// adapter. Nothing here provisions a mailbox, sends mail or authorizes actions.
3package coordinatormail
4
5import (
6 "errors"
7 "net/mail"
8 "strings"
9)
10
11var ErrPolicy = errors.New("coordinator mail: policy refused")
12
13// Scope is resolved from trusted Equipo storage, never from email headers.
14// Address must be the authenticated person's currently verified bare address.
15type Scope struct {
16 Team, Person, Address, Coordinator, Project, Task, Thread string
17}
18
19func (s Scope) valid() bool {
20 return s.Team != "" && s.Person != "" && bareAddress(s.Address) &&
21 s.Coordinator != "" && s.Project != "" && s.Task != "" && s.Thread != ""
22}
23
24func bareAddress(s string) bool {
25 if strings.ContainsAny(s, "\r\n") {
26 return false
27 }
28 a, err := mail.ParseAddress(s)
29 return err == nil && a.Name == "" && a.Address == s
30}
31
32// Outbound is a policy snapshot. Re-resolve it immediately before dispatch.
33// Recipient is singular by design: no Cc, Bcc, arbitrary recipients or aliases.
34type Outbound struct {
35 Scope
36 Recipient, Sender, SenderLabel string
37 Configured, Authorized bool
38 Verified, Active, OptedIn bool
39 Suppressed bool
40}
41
42func CheckOutbound(o Outbound) error {
43 if !o.Scope.valid() || !o.Configured || !o.Authorized || !o.Verified ||
44 !o.Active || !o.OptedIn || o.Suppressed || o.Recipient != o.Address ||
45 !bareAddress(o.Sender) || o.Sender == o.Address ||
46 o.SenderLabel != "Equipo coordinator" {
47 return ErrPolicy
48 }
49 return nil
50}
51
52// Reply contains ONLY server-resolved facts. An adapter must authenticate the
53// transport and verify the sender binding before constructing it. These flags
54// are not evidence by themselves and must never be decoded from an HTTP body.
55// A signed delivery webhook proves delivery, not the author's identity.
56type Reply struct {
57 Expected, Bound Scope
58 EventID string
59 TransportVerified, SenderBound, RouteVerified bool
60 Active, Automated, FromCoordinator bool
61}
62
63// CheckReply permits importing untrusted discussion into an existing thread.
64// It never permits creating tasks, routing instructions or approving actions.
65// Quoted text, forwarding and attachments cannot alter the resolved scope.
66func CheckReply(r Reply) error {
67 if !r.Expected.valid() || r.Expected != r.Bound || r.EventID == "" ||
68 !r.TransportVerified || !r.SenderBound || !r.RouteVerified ||
69 !r.Active || r.Automated || r.FromCoordinator {
70 return ErrPolicy
71 }
72 return nil
73}
74