session

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilEnvelope error = errors.New("nil envelope")
	ErrNilRcpt     error = errors.New("nil rcpt")
	ErrNilSender   error = errors.New("nil sender")

	ErrValidation error = errors.New("validation failure")
	ErrTimeout    error = errors.New("timeout")
)

Functions

func AsFilter

func AsFilter(f FilterSet) filterSet

func AsHook

func AsHook(h HookSet) hookSet

Types

type Address

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

Address represents an email address.

func MustParseAddr

func MustParseAddr(addr string) Address

MustParseAddr creates an Address from one line string.

Panics

  • If addr is invalid format for mail address.

func NewAddr

func NewAddr(user string, domain string) (*Address, error)

NewAddr creates an Address from user and domain.

Errors

  • If provides invalid format for mail address.

func ParseAddr

func ParseAddr(address string) (*Address, error)

ParseAddr creates an Address from one line string.

Errors

  • If address is invalid format for mail address.

func RandomAddr

func RandomAddr(domain string) (*Address, error)

RandomAddr creates an Address with user that generated by uuid v4.

Errors

  • If provides invalid format for mail address.

func (Address) Domain

func (a Address) Domain() string

Domain returns a section of domain in address.

func (Address) Name

func (a Address) Name() string

Name returns a section of name in address.

func (Address) String

func (a Address) String() string

String returns the address as string. e.g. alice@mail.com

func (Address) User

func (a Address) User() string

User returns a section of user in address.

type Filter

type Filter interface {
	// Validate validates a Transaction.
	// Returns an error if the transaction is invalid.
	Validate(t Transaction) error
}

Filter determains the mail should be recieved.

type FilterSet

type FilterSet interface {
	// FindFilters returns an array of Filters or an error.
	// If no Filters matched the key `addr`, returns an empty array.
	FindFilters(addr Address) ([]Filter, error)
}

FilterSet represents a set of filters.

type Filters

type Filters []Filter

Filters is an array of Filter.

func (Filters) Validate

func (f Filters) Validate(t Transaction) error

type Hook

type Hook interface {
	// Send sends a Transaction.
	// Returns an error if sending fails.
	Send(t Transaction) error
}

Hook hooks

type HookSet

type HookSet interface {
	// FindHooks returns an array of Hooks or an error.
	// If no Hooks matched the key `addr`, returns an empty array.
	FindHooks(addr Address) ([]Hook, error)
}

HookSet represents a set of hooks.

type HooksAll

type HooksAll []Hook

func (HooksAll) Send

func (h HooksAll) Send(t Transaction) error

type HooksSome

type HooksSome []Hook

func (HooksSome) Send

func (h HooksSome) Send(t Transaction) error

type Logger

type Logger interface {
	Error(meg string, args ...any)
}

type Option

type Option func(*Session)

func WithFilters

func WithFilters(xs ...Filter) Option

WithFilters sets one or more filters into Session. Each filters execute asynchronously. Returns an error immediately if execution of at least one function fails.

func WithHooksAll

func WithHooksAll(xs ...Hook) Option

WithHooksAll sets one or more hooks into Session. Each hooks execute asynchronously. Returns an error immediately if execution of at least one function fails.

func WithHooksSome

func WithHooksSome(xs ...Hook) Option

WithHooksSome sets one or more hooks into Session. Each hooks execute asynchronously.

func WithLogger

func WithLogger(logger Logger) Option

WithLogger sets a Logger into the Session.

func WithTimeout

func WithTimeout(d time.Duration) Option

type Session

type Session struct {
	Filter
	Hook
	// contains filtered or unexported fields
}

func New

func New(options ...Option) Session

func (Session) Commit

func (s Session) Commit() error

Commit creates, validates, and sends a Transaction.

Errors

  • `sender`, `rcpt`, or `envelope` is nil.
  • Validate failed.
  • Send failed.

func (Session) ID

func (s Session) ID() uuid.UUID

ID returns uuid.

func (Session) IntoTransaction

func (s Session) IntoTransaction() (*Transaction, error)

func (*Session) Reset

func (s *Session) Reset()

Reset sets default values into Session.

func (*Session) SetData

func (s *Session) SetData(r io.Reader) error

SetData parse body into an Envelope and sets it into the Session.

func (*Session) SetMail

func (s *Session) SetMail(addr string) error

SetMail parse a sender address and sets it into the Session.

func (*Session) SetRcpt

func (s *Session) SetRcpt(addr string) error

SetRcpt parse a recipient address and sets it into the Session.

type Transaction

type Transaction struct {
	ID uuid.UUID
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(id uuid.UUID, sender Address, rcpt Address, body io.Reader) (*Transaction, error)

func (Transaction) From

func (t Transaction) From() string

func (Transaction) HTML

func (t Transaction) HTML() string

func (Transaction) Raw

func (t Transaction) Raw() []byte

func (Transaction) RcptAddress

func (t Transaction) RcptAddress() string

func (Transaction) RcptName

func (t Transaction) RcptName() string

func (Transaction) SenderAddress

func (t Transaction) SenderAddress() string

func (Transaction) SenderName

func (t Transaction) SenderName() string

func (Transaction) Subject

func (t Transaction) Subject() string

func (Transaction) Text

func (t Transaction) Text() string

func (Transaction) To

func (t Transaction) To() string

Jump to

Keyboard shortcuts

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