1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2026-10-29 05:32:31 +00:00
Files
go-inbucket/pkg/extension/event/events.go
T
James Hillyerd bd4cc4b842 feat(luahost): Lua-controlled settings and decoded header access (#630)
* feat(luahost): capture config settings set by Lua scripts

Add inbucket.config, a Lua-settable settings namespace, with its first
field decode_headers registering additional message headers for Inbucket
to decode.  Values are captured once at startup from the first pooled
LState and exposed to the assembly via Host.ScriptConfig().

Settings that only have value to the Lua script belong here rather than
in env config.  No consumers of decode_headers yet; that follows.

* feat(message): expose decoded headers to extensions

StoreManager gains ExtraDecodeHeaders, passed through to
enmime.DecodeHeaders, and the decoded header set (defaults plus any
registered extras) is attached to the InboundMessage event as
Headers (net/textproto.MIMEHeader).

Lua scripts access it via the read-only inbound_message.header field,
added with the new inbound_header binding.  Lookups are exact-then-
case-insensitive, since enmime canonicalizes keys with email-specific
rules that differ from net/textproto.

FullAssembly wires ScriptConfig().DecodeHeaders into StoreManager.

Part of #627.

* docs(extension): document shared and untrusted header semantics

Reviewer note: BeforeMessageStored listeners receive the same decoded
header map, so a Go listener's mutations are visible to later listeners.
Also record that sender-supplied header values (Authentication-Results,
X-Spam-Status) are untrusted unless the deployment controls provenance.

Part of #627.

---------

Co-authored-by: hillyerd-bot <hillyerd-bot@users.noreply.github.com>
2026-10-23 15:38:37 -07:00

68 lines
1.9 KiB
Go

package event
import (
"net/mail"
"net/textproto"
"time"
)
const (
// ActionDefer defers decision to built-in Inbucket logic.
ActionDefer = iota
// ActionAllow explicitly allows this event.
ActionAllow
// ActionDeny explicitly deny this event, typically with specified SMTP error.
ActionDeny
)
// AddressParts contains the local and domain parts of an email address.
type AddressParts struct {
Local string
Domain string
}
// InboundMessage contains the basic header and mailbox data for a message being received.
type InboundMessage struct {
Mailboxes []string
From *mail.Address
To []*mail.Address
Subject string
Size int64
// Headers contains the decoded message headers: the default set (Date,
// Subject, Sender, From, To, CC, BCC) plus any additional names registered
// by a Lua script via inbucket.config.decode_headers.
//
// The same map is shared with every BeforeMessageStored listener; mutations
// made by a Go listener are visible to listeners that run after it. Sender
// supplied values are untrusted: headers such as Authentication-Results and
// X-Spam-Status should only drive decisions when the deployment controls
// their provenance.
Headers textproto.MIMEHeader
}
// MessageMetadata contains the basic header data for a message event.
type MessageMetadata struct {
Mailbox string
ID string
From *mail.Address
To []*mail.Address
Date time.Time
Subject string
Size int64
Seen bool
}
// SMTPResponse describes the response to an SMTP policy check.
type SMTPResponse struct {
Action int // ActionDefer, ActionAllow, etc.
ErrorCode int // SMTP error code to respond with on deny.
ErrorMsg string // SMTP error message to respond with on deny.
}
// SMTPSession captures SMTP `MAIL FROM` & `RCPT TO` values prior to mail DATA being received.
type SMTPSession struct {
From *mail.Address
To []*mail.Address
RemoteAddr string
}