parser

package
v0.0.0-...-8a2ee14 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSingleLabel    = errors.New("domain must have at least two labels")
	ErrEmptyLabel     = errors.New("domain has empty label")
	ErrLabelTooLong   = errors.New("domain label exceeds 63 octets")
	ErrDomainTooLong  = errors.New("domain exceeds 255 octets")
	ErrIDNAConversion = errors.New("IDNA ToASCII failed")
)

Errors returned by ValidateDomain. Each corresponds to one of the syntax checks described in RFC 7208 section 4.3.

View Source
var ErrNotModifier = errors.New("-not-modifier")

Functions

func ValidateDomain

func ValidateDomain(raw string) (string, error)

ValidateDomain normalises and validates a raw domain name, according to RFC 7208, section 4.3. Validation steps:

  1. Remove one trailing dot because domains are implicitly absolute.

  2. Convert the name to its Punycode A-label form with idna.Lookup.ToASCII.

  3. Apply SPF pre-evaluation checks:

    * Overall length must not exceed 255 octets. * The domain must contain at least two labels (must include a dot). * No empty label may appear except the implicit root. * Each label must be 1–63 octets long. * Labels may contain only lower-case letters, digits, and hyphens. * A hyphen may not appear at the start or end of any label.

On success the function returns the ASCII (lower-case) domain and nil. On failure, it returns an empty string along with a sentinel error.

Types

type Mechanism

type Mechanism struct {
	Qual   Qualifier
	Kind   string     // "all", "ipv4"
	Net    *net.IPNet // only ipv4/ipv6 set this
	Domain string     // only a, mx, include, exists use this
	Mask4  int        // only a/mx when dual CIDR present
	Mask6  int
	Macro  bool // only exists and later exp uses this
}

Mechanism describes one mechanism term in an SPF record. The fields are populated according to the specific mechanism type as defined in RFC 7208 section 5.

type Modifier

type Modifier struct {
	Name  string // "redirect" / "exp" / anything-else
	Value string // raw RHS (may contain macros)
	Macro bool   // used by redirect rfc 7208 section 6.1
}

Modifier represents a key=value term such as "redirect" or "exp" from RFC 7208 section 6. The value may contain macros which are expanded during evaluation.

type Qualifier

type Qualifier rune

Qualifier represents the prefix modifier for a mechanism as defined in RFC 7208 section 4.6. It controls how a match affects the overall result.

const (
	QPlus  Qualifier = '+' // pass
	QMinus Qualifier = '-' // fail
	QTilde Qualifier = '~' // softfail
	QMark  Qualifier = '?' // neutral
)

type Record

type Record struct {
	Mechs    []Mechanism
	Redirect *Modifier // nil or the modifier
	Exp      *Modifier
	Unknown  []Modifier
}

Record holds a parsed SPF record.

func Parse

func Parse(rawTXT string) (*Record, error)

Jump to

Keyboard shortcuts

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