rfcmessageid

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package rfcmessageid parses and canonicalizes RFC 5322 message identifiers.

Parsing is deliberately bounded. A header value may contain at most MaxInputBytes bytes and an individual bracketed identifier may contain at most MaxIdentifierBytes bytes. The parser is iterative (including for nested comments), and the number and total size of returned identifiers are therefore also bounded by MaxInputBytes.

Index

Constants

View Source
const (
	// MaxInputBytes is the largest Message-ID, In-Reply-To, or References
	// field value Parse will inspect. It is generous enough for long folded
	// References chains while placing a fixed bound on parser work and output.
	MaxInputBytes = 64 << 10

	// MaxIdentifierBytes is the largest individual msg-id, including its
	// angle brackets. A msg-id cannot fold internally, so RFC 5322's maximum
	// physical line length provides a conservative wire-format bound.
	MaxIdentifierBytes = 998

	// MaxTokens is the maximum number of nearest, distinct identifiers returned
	// from one field. The byte bound protects parsing; this independent count
	// bound protects downstream exact-anchor resolution from turning one long
	// References field into thousands of database probes.
	MaxTokens = 32
)

Variables

View Source
var (
	// ErrInvalidSyntax reports a value that does not contain a valid sequence
	// of bracketed RFC message identifiers (optionally surrounded by obsolete
	// reply-header phrase syntax).
	ErrInvalidSyntax = errors.New("invalid RFC message-id syntax")

	// ErrInputTooLarge reports a header value or individual identifier that
	// exceeds the documented parser bounds.
	ErrInputTooLarge = errors.New("RFC message-id input too large")
)

Functions

func Canonicalize

func Canonicalize(value string) (string, error)

Canonicalize validates a field value containing exactly one msg-id token, with optional surrounding comments or folding whitespace, and returns its canonical bracketed form. It is intended for callers such as outbound adapters that have one provider-qualified wire identifier rather than a References chain.

func Parse

func Parse(value string) ([]string, error)

Parse extracts canonical msg-id tokens from an In-Reply-To or References-style field value, including obsolete phrase wrappers.

Tokens are returned with angle brackets, in wire order. The identifier-left bytes are preserved exactly and ASCII uppercase bytes in the identifier-right are lowercased. Duplicate canonical tokens are removed by keeping their last occurrence, so iterating the result right-to-left retains RFC resolution precedence. Empty and CFWS-only values return nil, nil.

Types

type Token

type Token struct {
	Original  string
	Canonical string
}

Token contains both representations of one parsed msg-id. Original is the exact bracketed byte sequence from the field value. Canonical preserves the identifier-left bytes and lowercases ASCII bytes only in identifier-right.

func ParseTokens

func ParseTokens(value string) ([]Token, error)

ParseTokens extracts msg-id tokens while retaining each exact bracketed token alongside its canonical lookup form. Duplicate identity is determined by Canonical, and the Token from the last occurrence is retained in wire order. At most MaxTokens nearest (rightmost) distinct tokens are returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL