package postcard import ( "context" "fmt" "log/slog" netmail "net/mail" "strings" "sync" "time" "git.golem15.com/golem15/summercms/modules/backpack" "git.golem15.com/golem15/summercms/modules/compass" "git.golem15.com/golem15/summercms/modules/diary" "git.golem15.com/golem15/summercms/modules/pact" ) // moduleLog is postcard's logger: records carry component=postcard and follow // log.components.postcard (diary). var moduleLog = diary.For("postcard") // Message is the Send contract for plugin callers. type Message struct { Template string To []string Cc []string Bcc []string ReplyTo string Vars map[string]any Subject string } // Mailer sends a registered template through the configured driver. type Mailer interface { Send(ctx context.Context, msg Message) error } // Options configure an app-scoped mailer. type Options struct { From string CSS string BrandCSS string // Overrides, when set, is asked once per Send for the database // overrides of the template being sent. Nil sends the file versions. Overrides OverrideSource } type mailer struct { catalog *Catalog driver Driver opts Options // source supplies database overrides; nil means files only. source OverrideSource // log receives override warnings and failures; nil means moduleLog. log *slog.Logger warned warnGate } // NewMailer returns a mailer that renders from cat and delivers through // driver. opts.Overrides, when set, supplies database overrides per send. func NewMailer(cat *Catalog, driver Driver, opts Options) Mailer { if cat == nil { cat = NewCatalog() } return &mailer{catalog: cat, driver: driver, opts: opts, source: opts.Overrides} } // Send renders msg.Template and delivers it. It picks no locale: the caller // passes the full dotted name, including any -en suffix. A