interp

package
v0.0.0-...-3ee6b4a Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrComparatorMatchUnsupported = fmt.Errorf("match-comparator combination not supported")
View Source
var ErrStop = errors.New("interpreter: stop called")

Functions

func LoadSpec

func LoadSpec(s *Script, spec *Spec, pos lexer.Position, args []parser.Arg, tests []parser.Test, block []parser.Cmd) error

Types

type AddressPart

type AddressPart string
const (
	LocalPart AddressPart = "localpart"
	Domain    AddressPart = "domain"
	All       AddressPart = "all"
)

type AddressTest

type AddressTest struct {
	Comparator  Comparator
	AddressPart AddressPart
	Match       Match

	Header []string
	Key    []string
}

func (AddressTest) Check

func (a AddressTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type AllOfTest

type AllOfTest struct {
	Tests []Test
}

func (AllOfTest) Check

func (a AllOfTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type AnyOfTest

type AnyOfTest struct {
	Tests []Test
}

func (AnyOfTest) Check

func (a AnyOfTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type Callback

type Callback struct {
	RedirectAllowed func(ctx context.Context, d *RuntimeData, addr string) (bool, error)
	HeaderGet       func(value string) (string, bool, error)
}

type Cmd

type Cmd interface {
	Execute(ctx context.Context, d *RuntimeData) error
}

func LoadBlock

func LoadBlock(s *Script, cmds []parser.Cmd) ([]Cmd, error)

func LoadCmd

func LoadCmd(s *Script, cmd parser.Cmd) (Cmd, error)

type CmdDiscard

type CmdDiscard struct{}

func (CmdDiscard) Execute

func (c CmdDiscard) Execute(_ context.Context, d *RuntimeData) error

type CmdElse

type CmdElse struct {
	Block []Cmd
}

func (CmdElse) Execute

func (c CmdElse) Execute(ctx context.Context, d *RuntimeData) error

type CmdElsif

type CmdElsif struct {
	Test  Test
	Block []Cmd
}

func (CmdElsif) Execute

func (c CmdElsif) Execute(ctx context.Context, d *RuntimeData) error

type CmdFileInto

type CmdFileInto struct {
	Mailbox string
}

func (CmdFileInto) Execute

func (c CmdFileInto) Execute(ctx context.Context, d *RuntimeData) error

type CmdIf

type CmdIf struct {
	Test  Test
	Block []Cmd
}

func (CmdIf) Execute

func (c CmdIf) Execute(ctx context.Context, d *RuntimeData) error

type CmdKeep

type CmdKeep struct{}

func (CmdKeep) Execute

func (c CmdKeep) Execute(_ context.Context, d *RuntimeData) error

type CmdRedirect

type CmdRedirect struct {
	Addr string
}

func (CmdRedirect) Execute

func (c CmdRedirect) Execute(ctx context.Context, d *RuntimeData) error

type CmdStop

type CmdStop struct{}

func (CmdStop) Execute

func (c CmdStop) Execute(ctx context.Context, d *RuntimeData) error

type Comparator

type Comparator string
const (
	ComparatorOctet          Comparator = "i;octet"
	ComparatorASCIICaseMap   Comparator = "i;ascii-casemap"
	ComparatorASCIINumeric   Comparator = "i;ascii-numeric"
	ComparatorUnicodeCaseMap Comparator = "i;unicode-casemap"
)

type EnvelopeTest

type EnvelopeTest struct {
	Comparator  Comparator
	AddressPart AddressPart
	Match       Match

	Field []string
	Key   []string
}

func (EnvelopeTest) Check

func (e EnvelopeTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type ExistsTest

type ExistsTest struct {
	Fields []string
}

func (ExistsTest) Check

func (e ExistsTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type FalseTest

type FalseTest struct{}

func (FalseTest) Check

func (f FalseTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type HeaderTest

type HeaderTest struct {
	Comparator Comparator
	Match      Match

	Header []string
	Key    []string
}

func (HeaderTest) Check

func (h HeaderTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type Match

type Match string
const (
	MatchContains Match = "contains"
	MatchIs       Match = "is"
	MatchMatches  Match = "matches"
)

type NotTest

type NotTest struct {
	Test Test
}

func (NotTest) Check

func (n NotTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type Options

type Options struct {
	MaxRedirects int
}

type RuntimeData

type RuntimeData struct {
	Script      *Script
	Callback    Callback
	SMTP        SMTPEnvelope
	MessageSize int

	RedirectAddr []string
	Mailboxes    []string
	Keep         bool
	ImplicitKeep bool
	// contains filtered or unexported fields
}

func NewRuntimeData

func NewRuntimeData(s *Script, p Callback) *RuntimeData

type SMTPEnvelope

type SMTPEnvelope struct {
	From string
	To   string
}

type Script

type Script struct {
	// contains filtered or unexported fields
}

func LoadScript

func LoadScript(cmdStream []parser.Cmd, opts *Options) (*Script, error)

func (Script) Execute

func (s Script) Execute(ctx context.Context, d *RuntimeData) error

func (Script) Extensions

func (s Script) Extensions() []string

func (Script) RequiresExtension

func (s Script) RequiresExtension(name string) bool

type SizeTest

type SizeTest struct {
	Size  int
	Over  bool
	Under bool
}

func (SizeTest) Check

func (s SizeTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

type Spec

type Spec struct {
	Tags          map[string]SpecTag
	Pos           []SpecPosArg
	AddBlock      func([]Cmd)
	BlockOptional bool
	AddTest       func(Test)
	TestOptional  bool
	MultipleTests bool
}

type SpecPosArg

type SpecPosArg struct {
	Optional bool
	MatchStr func(val []string)
	MatchNum func(i int)

	// Checks for used string list.
	MinStrCount int
	MaxStrCount int
}

type SpecTag

type SpecTag struct {
	NeedsValue bool
	MatchStr   func(val []string)
	MatchNum   func(val int)
	MatchBool  func()

	// Checks for used string list.
	MinStrCount int
	MaxStrCount int
}

type Test

type Test interface {
	Check(ctx context.Context, d *RuntimeData) (bool, error)
}

func LoadTest

func LoadTest(s *Script, t parser.Test) (Test, error)

type TrueTest

type TrueTest struct{}

func (TrueTest) Check

func (t TrueTest) Check(ctx context.Context, d *RuntimeData) (bool, error)

Jump to

Keyboard shortcuts

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