interp

package
v0.0.0-...-72d6b00 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const DovecotTestExtension = "vnd.dovecot.testsuite"

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, position 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 {
	AddressPart AddressPart
	Header      []string
	// contains filtered or unexported fields
}

func (AddressTest) Check

func (a AddressTest) Check(_ 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 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 CmdAddFlag

type CmdAddFlag struct {
	Flags Flags
}

func (CmdAddFlag) Execute

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

type CmdDiscard

type CmdDiscard struct{}

func (CmdDiscard) Execute

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

type CmdDovecotConfigSet

type CmdDovecotConfigSet struct {
	Unset bool
	Key   string
	Value string
}

func (CmdDovecotConfigSet) Execute

type CmdDovecotTest

type CmdDovecotTest struct {
	TestName string
	Cmds     []Cmd
}

func (CmdDovecotTest) Execute

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

type CmdDovecotTestFail

type CmdDovecotTestFail struct {
	At      lexer.Position
	Message string
}

func (CmdDovecotTestFail) Execute

type CmdDovecotTestSet

type CmdDovecotTestSet struct {
	VariableName  string
	VariableValue string
}

func (CmdDovecotTestSet) Execute

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
	Flags   Flags
}

func (CmdFileInto) Execute

func (c CmdFileInto) Execute(_ 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 {
	Flags Flags
}

func (CmdKeep) Execute

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

type CmdNoop

type CmdNoop struct{}

func (CmdNoop) Execute

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

type CmdRedirect

type CmdRedirect struct {
	Addr string
}

func (CmdRedirect) Execute

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

type CmdRemoveFlag

type CmdRemoveFlag struct {
	Flags Flags
}

func (CmdRemoveFlag) Execute

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

type CmdSet

type CmdSet struct {
	Name  string
	Value string

	ModifyValue func(string) string
}

func (CmdSet) Execute

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

type CmdSetFlag

type CmdSetFlag struct {
	Flags Flags
}

func (CmdSetFlag) Execute

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

type CmdStop

type CmdStop struct{}

func (CmdStop) Execute

func (c CmdStop) Execute(_ context.Context, _ *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"

	DefaultComparator = ComparatorASCIICaseMap
)

type CompiledMatcher

type CompiledMatcher func(value string) (bool, []string, error)

type DummyPolicy

type DummyPolicy struct {
}

func (DummyPolicy) RedirectAllowed

func (d DummyPolicy) RedirectAllowed(_ context.Context, _ *RuntimeData, _ string) (bool, error)

type Envelope

type Envelope interface {
	EnvelopeFrom() string
	EnvelopeTo() string
	AuthUsername() string
}

type EnvelopeStatic

type EnvelopeStatic struct {
	From string
	To   string
	Auth string
}

func (EnvelopeStatic) AuthUsername

func (m EnvelopeStatic) AuthUsername() string

func (EnvelopeStatic) EnvelopeFrom

func (m EnvelopeStatic) EnvelopeFrom() string

func (EnvelopeStatic) EnvelopeTo

func (m EnvelopeStatic) EnvelopeTo() string

type EnvelopeTest

type EnvelopeTest struct {
	AddressPart AddressPart
	Field       []string
	// contains filtered or unexported fields
}

func (EnvelopeTest) Check

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

type ExistsTest

type ExistsTest struct {
	Fields []string
}

func (ExistsTest) Check

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

type FalseTest

type FalseTest struct{}

func (FalseTest) Check

type Flags

type Flags []string

type HeaderTest

type HeaderTest struct {
	Header []string
	// contains filtered or unexported fields
}

func (HeaderTest) Check

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

type Match

type Match string
const (
	MatchContains Match = "contains"
	MatchIs       Match = "is"
	MatchMatches  Match = "matches"
	MatchValue    Match = "value"
	MatchCount    Match = "count"
)

type Message

type Message interface {
	/*
		HeaderGet returns the header field value.

		RFC requires the following handling for encoded fields:

		      Comparisons are performed on octets.  Implementations convert text
		      from header fields in all charsets [MIME3] to Unicode, encoded as
		      UTF-8, as input to the comparator (see section 2.7.3).
		      Implementations MUST be capable of converting US-ASCII, ISO-8859-
		      1, the US-ASCII subset of ISO-8859-* character sets, and UTF-8.
		      Text that the implementation cannot convert to Unicode for any
		      reason MAY be treated as plain US-ASCII (including any [MIME3]
		      syntax) or processed according to local conventions.  An encoded
		      NUL octet (character zero) SHOULD NOT cause early termination of
		      the header content being compared against.
	*/
	HeaderGet(key string) ([]string, error)
	MessageSize() int
}

type MessageHeader

type MessageHeader interface {
	Values(key string) []string
	Set(key, value string)
	Del(key string)
}

type MessageStatic

type MessageStatic struct {
	Size   int
	Header MessageHeader
}

MessageStatic is a simple Message interface implementation that just keeps all data in memory in a Go struct.

func (MessageStatic) HeaderGet

func (m MessageStatic) HeaderGet(key string) ([]string, error)

func (MessageStatic) MessageSize

func (m MessageStatic) MessageSize() int

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

	MaxVariableCount   int
	MaxVariableNameLen int
	MaxVariableLen     int

	// If specified - enables vnd.dovecot.testsuite extension
	// and will execute tests.
	T             *testing.T
	DisabledTests []string
}

type PolicyReader

type PolicyReader interface {
	RedirectAllowed(ctx context.Context, d *RuntimeData, addr string) (bool, error)
}

type Relational

type Relational string
const (
	RelGreaterThan    Relational = "gt"
	RelGreaterOrEqual Relational = "ge"
	RelLessThan       Relational = "lt"
	RelLessOrEqual    Relational = "le"
	RelEqual          Relational = "eq"
	RelNotEqual       Relational = "ne"
)

func (Relational) CompareNumericValue

func (r Relational) CompareNumericValue(lhs, rhs *uint64) bool

func (Relational) CompareString

func (r Relational) CompareString(lhs, rhs string) bool

func (Relational) CompareUint64

func (r Relational) CompareUint64(lhs, rhs uint64) bool

type RuntimeData

type RuntimeData struct {
	Policy   PolicyReader
	Envelope Envelope
	Msg      Message
	Script   *Script
	// For files accessible vis "include", "test_script_compile", etc.
	Namespace fs.FS

	RedirectAddr []string
	Mailboxes    []string
	Flags        []string
	Keep         bool
	ImplicitKeep bool

	FlagAliases map[string]string

	MatchVariables []string
	Variables      map[string]string
	// contains filtered or unexported fields
}

func NewRuntimeData

func NewRuntimeData(s *Script, p PolicyReader, e Envelope, m Message) *RuntimeData

func (*RuntimeData) Copy

func (d *RuntimeData) Copy() *RuntimeData

func (*RuntimeData) MatchVariable

func (d *RuntimeData) MatchVariable(i int) string

func (*RuntimeData) SetVar

func (d *RuntimeData) SetVar(name, value string) error

func (*RuntimeData) Var

func (d *RuntimeData) Var(name string) (string, error)

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) IsVarUsable

func (s *Script) IsVarUsable(variableName string) (settable, gettable bool)

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(_ 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

	// Toggle checks for valid variable names.
	NoVariables bool
}

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

	// Toggle checks for valid variable names.
	NoVariables bool
}

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 TestDovecotCompile

type TestDovecotCompile struct {
	ScriptPath string
}

func (TestDovecotCompile) Check

type TestDovecotRun

type TestDovecotRun struct {
}

func (TestDovecotRun) Check

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

type TestDovecotTestError

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

func (TestDovecotTestError) Check

type TestString

type TestString struct {
	Source []string
	// contains filtered or unexported fields
}

func (TestString) Check

func (t TestString) Check(_ context.Context, d *RuntimeData) (bool, error)

type TrueTest

type TrueTest struct{}

func (TrueTest) Check

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

Jump to

Keyboard shortcuts

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