Documentation
¶
Index ¶
- Constants
- func DecodeBase64(raw []byte) []byte
- func DecodeCharset(data []byte, charset string) (string, bool, string)
- func DecodeEncodedWords(input string) string
- func DecodeQuotedPrintable(raw []byte) []byte
- func DecodeTransfer(raw []byte, encoding string) []byte
- func Fnv1a64(s string) string
- func GetHeader(headers []Header, name string) (string, bool)
- func Matches(spec MatchSpec, meta *PartMeta, body []byte) bool
- func NormalizeMailer(mailer string) string
- func Specificity(spec MatchSpec) float64
- func SplitMime(r io.Reader, handlers SplitHandlers)
- func UnflowFormat(text string, delsp bool) string
- type Address
- type ArrayTrace
- type Attachment
- type ByteSignature
- type Diagnostic
- type EmittedPart
- type FailureEvent
- type FailureFeatures
- type FailureSignature
- type Header
- type HeaderMatch
- type Line
- type MatchSpec
- type Message
- type Middleware
- type ParseOptions
- type Part
- type PartMeta
- type Registry
- type SignatureRollup
- type Span
- type SpanEnd
- type SpanRecord
- type SplitHandlers
- type StructuredField
- type TraceHook
Constants ¶
const LibVersion = "0.0.0"
LibVersion is the default library version embedded in a signature's features.
Variables ¶
This section is empty.
Functions ¶
func DecodeBase64 ¶
DecodeBase64 decodes a base64 body. Tolerant of whitespace and stray non-alphabet bytes.
func DecodeCharset ¶
DecodeCharset decodes bytes to a string using a charset label. Returns (text, ok, label). ok is false (with a utf-8 best-effort string) when the label is unsupported, so the caller can record a diagnostic.
func DecodeEncodedWords ¶
DecodeEncodedWords decodes RFC 2047 encoded-words. Adjacent words concatenate; whitespace strictly between two encoded words is dropped (RFC 2047 §6.2).
func DecodeQuotedPrintable ¶
DecodeQuotedPrintable decodes a quoted-printable body (RFC 2045 §6.7).
func DecodeTransfer ¶
DecodeTransfer applies a Content-Transfer-Encoding. Unknown encodings pass through (7bit/8bit/binary).
func Fnv1a64 ¶
Fnv1a64 computes an FNV-1a 64-bit hash of s and returns it as 16 lowercase hex digits. A fast, portable, non-crypto fingerprint — fine for grouping. Must match the TS/Python implementations.
func GetHeader ¶
GetHeader is a case-insensitive header lookup (first match). ok reports whether it was present.
func NormalizeMailer ¶
NormalizeMailer coarsely normalizes an X-Mailer / User-Agent into a family token (PII-free, low-cardinality).
func Specificity ¶
Specificity is a score in [0,1] — more (and more selective) conjuncts -> higher.
func SplitMime ¶
func SplitMime(r io.Reader, handlers SplitHandlers)
SplitMime drives the state machine over r, emitting node events to handlers.
func UnflowFormat ¶
UnflowFormat reflows a format=flowed text/plain body.
Types ¶
type Address ¶
Address is a parsed email address. Address is "" if unparseable; Name is RFC 2047 decoded.
func ParseAddressList ¶
ParseAddressList parses an address-list header (From/To/Cc/…). Common-case subset: `Name <addr>`, bare `addr`, comma-separated lists, quoted display names. Groups + comments are a follow-up.
func ParseSingleAddress ¶
ParseSingleAddress returns the first address of a list, or nil.
type ArrayTrace ¶
type ArrayTrace struct {
Spans []*SpanRecord
}
ArrayTrace is a simple collector — one record per invocation, in START order (parent before child).
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
MimeType string `json:"mimeType"`
Disposition string `json:"disposition"` // "attachment" | "inline" | ""
ContentID string `json:"contentId"`
Content []byte `json:"-"`
Size int `json:"size"`
}
Attachment is a decoded attachment (or inline) part.
type ByteSignature ¶
ByteSignature is a magic-number match on the decoded body's leading bytes.
type Diagnostic ¶
type Diagnostic struct {
Code string `json:"code"`
Severity string `json:"severity"` // "warn" | "error"
Scope string `json:"scope"` // "envelope" | "structure" | "part"
Detail string `json:"detail,omitempty"`
Path string `json:"path,omitempty"`
}
Diagnostic is a typed, non-fatal degradation. The parser collects these instead of erroring.
type EmittedPart ¶
EmittedPart is a part a middleware emits in place of (or in addition to) the one it received.
type FailureEvent ¶
type FailureEvent struct {
Scope string
DiagnosticCodes []string
ContentType string
Disposition string
TransferEncoding string
BodyHead []byte
HeaderNames []string
Mailer string
StructurePath string
}
FailureEvent is a failure observed by the caller, before normalization. BodyHead enables a byte-signature.
type FailureFeatures ¶
type FailureFeatures struct {
LibVersion string `json:"libVersion"`
Scope string `json:"scope"`
DiagnosticCodes []string `json:"diagnosticCodes"`
ContentType string `json:"contentType,omitempty"`
Disposition string `json:"disposition,omitempty"`
TransferEncoding string `json:"transferEncoding,omitempty"`
// ByteSignature is the hex of the offending part's leading bytes — structure, never content.
ByteSignature string `json:"byteSignature,omitempty"`
HeaderNames []string `json:"headerNames,omitempty"`
// MailerFamily is the normalized X-Mailer/User-Agent family, e.g. "outlook".
MailerFamily string `json:"mailerFamily,omitempty"`
StructurePath string `json:"structurePath,omitempty"`
}
FailureFeatures holds the PII-free structural features of a failure.
type FailureSignature ¶
type FailureSignature struct {
// Hash is the finest-granularity hash — the primary dedup key.
Hash string `json:"hash"`
Features FailureFeatures `json:"features"`
Rollup []SignatureRollup `json:"rollup"`
}
FailureSignature is the computed fingerprint of a failure.
func ComputeSignature ¶
func ComputeSignature(event FailureEvent) FailureSignature
ComputeSignature computes a deterministic signature + roll-up hashes from a failure event.
func ComputeSignatureVersioned ¶
func ComputeSignatureVersioned(event FailureEvent, libVersion string) FailureSignature
ComputeSignatureVersioned is ComputeSignature with an explicit library version.
type Header ¶
Header is one unfolded header line, in document order.
func ParseHeaderBlock ¶
ParseHeaderBlock parses a raw header block (already split from the body) into ordered, unfolded headers.
type HeaderMatch ¶
HeaderMatch matches a header value by (case-insensitive) name.
type Line ¶
Line is one physical line: content bytes (no terminator) + the terminator that followed it.
type MatchSpec ¶
type MatchSpec struct {
ContentType string
MainType string
Charset string
Disposition string // "inline" | "attachment"
Filename *regexp.Regexp
Header *HeaderMatch
ByteSignature *ByteSignature
Predicate func(meta *PartMeta, body []byte) bool
}
MatchSpec is a declarative predicate over a part's structural metadata (+ optional body byte-signature).
type Message ¶
type Message struct {
Headers []Header `json:"headers"`
From *Address `json:"from,omitempty"`
To []Address `json:"to"`
Cc []Address `json:"cc"`
Bcc []Address `json:"bcc"`
ReplyTo []Address `json:"replyTo"`
Subject *string `json:"subject"`
MessageID *string `json:"messageId"`
InReplyTo *string `json:"inReplyTo"`
Date *string `json:"date"`
Text *string `json:"text"`
HTML *string `json:"html"`
Attachments []Attachment `json:"attachments"`
Diagnostics []Diagnostic `json:"diagnostics"`
Annotations map[string]interface{} `json:"annotations"`
}
Message is the buffered result of Parse — the same shape as the TS package's Message.
func Parse ¶
func Parse(raw []byte, opts *ParseOptions) Message
Parse parses a raw MIME message into a typed Message. Never panics on malformed input — collects diagnostics. opts may be nil.
func ParseReader ¶
func ParseReader(r io.Reader, opts *ParseOptions) Message
ParseReader is Parse over an io.Reader source.
type Middleware ¶
type Middleware struct {
Name string
Phase string
Match MatchSpec
OnPart func(part *Part, next func())
}
Middleware transforms a part; call next() to continue the chain, or return to short-circuit.
type ParseOptions ¶
type ParseOptions struct {
Middleware []Middleware
Trace TraceHook
}
ParseOptions configures Parse.
type Part ¶
type Part struct {
Meta *PartMeta
Body []byte
Text *string
HTML *string
ClassifyAs string // "attachment" | "text" | "html" | ""
Emitted []EmittedPart
Context map[string]interface{}
Diagnostics []Diagnostic
}
Part is the mutable per-part handle middleware operate on.
func (*Part) AddDiagnostic ¶
func (p *Part) AddDiagnostic(d Diagnostic)
AddDiagnostic appends a diagnostic to the part.
type PartMeta ¶
type PartMeta struct {
Depth int
Headers []Header
ContentType string
MainType string
Charset string
Format string
Delsp bool
Encoding string
Disposition string // "attachment" | "inline" | ""
Filename string
ContentID string
Boundary string
IsMultipart bool
Path string
}
PartMeta is the structural metadata the core computes for every MIME node BEFORE middleware runs (Layer 0). Handlers receive *PartMeta, so identity (pointer) keys per-part collectors exactly like the TS Map<PartMeta, ...> / Python identity dict.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds and dispatches middleware.
func ToRegistry ¶
func ToRegistry(mws []Middleware) *Registry
ToRegistry normalizes middleware into a Registry, or nil when there's nothing to run.
func (*Registry) RunPart ¶
RunPart runs the matched (part, next) chain. Tolerant: a panicking middleware is contained + recovered.
func (*Registry) Use ¶
func (r *Registry) Use(mw Middleware) *Registry
Use registers a middleware and returns the registry for chaining.
type SignatureRollup ¶
type SignatureRollup struct {
// Level is the granularity label, coarse → fine.
Level string `json:"level"`
Hash string `json:"hash"`
}
SignatureRollup is one coarse-to-fine granularity level and its hash.
type Span ¶
type Span interface {
End(info SpanEnd)
}
Span is returned by TraceHook.Start; End fills in the in/out + status.
type SpanRecord ¶
SpanRecord is one recorded middleware invocation.
type SplitHandlers ¶
type SplitHandlers struct {
OnNodeStart func(meta *PartMeta) // headers complete; PartMeta computed. Fires for every node.
OnBody func(meta *PartMeta, chunk []byte) // a chunk of RAW body bytes for a leaf. May fire many.
OnNodeEnd func(meta *PartMeta) // node finished (leaf body delivered, or container closed).
OnDiagnostic func(d Diagnostic) // a non-fatal structural degradation.
}
SplitHandlers holds the callbacks the splitter fires. Any may be nil.
type StructuredField ¶
StructuredField is a parsed structured header: Value (lowercased primary) + Params (lowercased keys).
func ParseStructuredField ¶
func ParseStructuredField(raw string) StructuredField
ParseStructuredField parses a field like `multipart/mixed; boundary="x"; name*=UTF-8”%E2%82%AC`.