smtpd

package
v0.0.0-...-b13d2c2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV_CONFFILE = "_GOMS_CONFFILE"
	ENV_PIDFILE  = "_GOMS_PIDFILE"

	GOMS_DEFAULT_PORT = 25
)

Variables

This section is empty.

Functions

func Run

func Run(control *Control)

func RunConfig

func RunConfig(control *Control)

RunConfig - this is effectively the main entry point of the program

We parse the config, then start each of the listeners, restarting them when we get SIGHUP, but being sure not to kill the sessions

func StartServer

func StartServer(parentCtx context.Context, sessionParentCtx context.Context, sessionWaitGroup *sync.WaitGroup, logger *log.Logger, s ServerConfig)

Startserver starts a single server.

A parent context is given in which the listener runs, as well as a session context in which the sessions (connections) themselves run. This enables the sessions to be retained when the listener is cancelled on a SIGHUP

Types

type AddressString

type AddressString string

AddressString holds an email address. Subtyped so we can play with it later

func CanonicaliseInboundAddress

func CanonicaliseInboundAddress(a string) *AddressString

CanonicaliseInboundAddress changes a string containing an email address into canonical format and returns it as an AddressString. This currently involves stripping source routing information

func (*AddressString) String

func (as *AddressString) String() string

String() returns a string representation of an AddressString

type Config

type Config struct {
	Servers []ServerConfig // array of server configs
	Logging LogConfig      // Configuration for logging
}

Config holds the config that applies to all servers (currently just logging), and an array of server configs

func ParseConfig

func ParseConfig(confFile string) (*Config, error)

ParseConfig parses the YAML configuration provided

func (*Config) GetLogger

func (c *Config) GetLogger() (*log.Logger, io.Closer, error)

type Control

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

Control mediates the running of the main process

type DeadlineListener

type DeadlineListener interface {
	SetDeadline(t time.Time) error
	net.Listener
}

An listener type that does what we want

type DriverParametersConfig

type DriverParametersConfig map[string]string

DriverConfig is an arbitrary map of other parameters in string format

type DummyITP

type DummyITP struct{}

DummyITP is an InboundTransactionProcessor which accepts all mail and dumps it

func (*DummyITP) CheckConnection

func (i *DummyITP) CheckConnection(ctx context.Context, c *InboundConnection) (*ICResponse, error)

CheckConnection accepts all servers

func (*DummyITP) CheckFromAddress

func (i *DummyITP) CheckFromAddress(ctx context.Context, c *InboundConnection, address *AddressString) (*ICResponse, error)

CheckFromAddress accepts all from addresses

func (*DummyITP) CheckRecipientAddress

func (i *DummyITP) CheckRecipientAddress(ctx context.Context, c *InboundConnection, address *AddressString) (*ICResponse, error)

CheckRecipientAddress accepts all recipient addresses

func (*DummyITP) ProcessMail

func (i *DummyITP) ProcessMail(ctx context.Context, c *InboundConnection, data []byte) (*ICResponse, error)

ProcessMail accepts all mail and does nothing with it

type ICCommand

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

ICCommand holds an inbound command

type ICResponse

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

ICResponse is a potentially multiline SMTP response

func (*ICResponse) IsError

func (r *ICResponse) IsError() bool

IsError() returns true if and only if r is an error code (i.e. 400 to 599) Technically there is a response code on each line of a multiline response, but we assume these all have the same code

type ICResponseLine

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

ICResponseLine is a single line SMTP response code

type InboundConnection

type InboundConnection struct {
	RecipientList []*AddressString // current recipient list

	ReversePath AddressString               // current sender
	ITP         InboundTransactionProcessor // inbound transaction processor associated with this connection
	// contains filtered or unexported fields
}

Connection holds the details for each connection

func (*InboundConnection) Process

func (c *InboundConnection) Process(ctx context.Context, cmd *ICCommand) (*ICResponse, error)

Process processes a command once received

func (*InboundConnection) Receive

func (c *InboundConnection) Receive() (*ICCommand, error)

Receive receives a command from an inbound connection

func (*InboundConnection) Send

func (c *InboundConnection) Send(r *ICResponse) error

Send sends a response to an inbound connection

func (*InboundConnection) Serve

func (c *InboundConnection) Serve(parentCtx context.Context)

Serve processes an SMTP conversation, closing the connections etc. when done

type InboundConnectionParameters

type InboundConnectionParameters struct {
	IdleTimeout        time.Duration // time to shut connection if idle
	ReadTimeout        time.Duration // time to read other than at command stage
	WriteTimeout       time.Duration // time to write
	GreetingHostname   string
	GreetingMailserver string
	MaxMessageSize     int
}

ConnectionParameters holds parameters for each inbound connection

type InboundTransactionProcessor

type InboundTransactionProcessor interface {
	CheckConnection(ctx context.Context, c *InboundConnection) (*ICResponse, error)
	CheckFromAddress(ctx context.Context, c *InboundConnection, address *AddressString) (*ICResponse, error)
	CheckRecipientAddress(ctx context.Context, c *InboundConnection, address *AddressString) (*ICResponse, error)
	ProcessMail(ctx context.Context, c *InboundConnection, data []byte) (*ICResponse, error)
}

InboundTransactionProcessor is an interface representing an inbound transaction processor, i.e. structs that satisfy this interface can check inbound SMTP connections and process their data

type Listener

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

A single listener on a given net.Conn address

func NewListener

func NewListener(logger *log.Logger, s ServerConfig) (*Listener, error)

NewListener returns a new listener object

func (*Listener) Listen

func (l *Listener) Listen(parentCtx context.Context, sessionParentCtx context.Context, sessionWaitGroup *sync.WaitGroup)

Listen listens on an given address for incoming connections

When sessions come in they are started on a separate context (sessionParentCtx), so that the listener can be killed without killing the sessions

type LogConfig

type LogConfig struct {
	File           string // a file to log to
	FileMode       string // file mode
	SyslogFacility string // a syslog facility name - set to enable syslog
	Date           bool   // log the date - i.e. log.Ldate
	Time           bool   // log the time - i.e. log.Ltime
	Microseconds   bool   // log microseconds - i.e. log.Lmicroseconds
	UTC            bool   // log time in URC - i.e. LUTC
	SourceFile     bool   // log source file - i.e. Lshortfile
}

LogConfig specifies configuration for logging

type ServerConfig

type ServerConfig struct {
	Protocol        string    // protocol it should listen on (in net.Conn form)
	Address         string    // address to listen on
	DefaultExport   string    // name of default export
	Tls             TlsConfig // TLS configuration
	DisableNoZeroes bool      // Disable NoZereos extension
}

ServerConfig holds the config that applies to each server (i.e. listener)

type SyslogWriter

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

SyslogWriter is a WriterCloser that logs to syslog with an extracted priority

func NewSyslogWriter

func NewSyslogWriter(facility string) (*SyslogWriter, error)

Create a new syslog writer

func (*SyslogWriter) Close

func (s *SyslogWriter) Close() error

Close the channel

func (*SyslogWriter) Write

func (s *SyslogWriter) Write(p []byte) (n int, err error)

Write to the syslog, removing the prefix and setting the appropriate level

type TlsConfig

type TlsConfig struct {
	KeyFile    string // path to TLS key file
	CertFile   string // path to TLS cert file
	ServerName string // server name
	CaCertFile string // path to certificate file
	ClientAuth string // client authentication strategy
	MinVersion string // minimum TLS version
	MaxVersion string // maximum TLS version
}

TlsConfig has the configuration for TLS

type Verb

type Verb struct {
	Run func(c *InboundConnection, ctx context.Context, params []byte) (*ICResponse, error)
}

Verb represents an SMTP verb and the action method associated with it

Jump to

Keyboard shortcuts

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