smtpd

package
v0.0.0-...-e48ae90 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2015 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthCancelled = &SMTPError{501, errors.New("Cancelled")}
View Source
var ErrAuthFailed = &SMTPError{535, errors.New("Authentication credentials invalid")}
View Source
var ErrRequiresTLS = &SMTPError{538, errors.New("Encryption required for requested authentication mechanism")}
View Source
var ErrTransaction = &SMTPError{501, errors.New("Transaction unsuccessful")}

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Mechanisms map[string]AuthExtension
}

func NewAuth

func NewAuth() *Auth

func (*Auth) EHLO

func (a *Auth) EHLO() string

EHLO returns a stringified list of the installed Auth mechanisms

func (*Auth) Extend

func (a *Auth) Extend(mechanism string, extension AuthExtension) error

Extend the auth handler by adding a new mechanism

func (*Auth) Handle

func (a *Auth) Handle(c *Conn, args string) error

Handle authentication by handing off to one of the configured auth mechanisms

type AuthCramMd5

type AuthCramMd5 struct {
	FindUser func(string) (AuthUser, error)
}

func (*AuthCramMd5) CheckResponse

func (a *AuthCramMd5) CheckResponse(response string, challenge []byte) (AuthUser, bool)

Note: This is currently very weak & requires storing of the user's password in plaintext one good alternative is to do the HMAC manually and expose handlers for pre-processing the password MD5s

func (*AuthCramMd5) Handle

func (a *AuthCramMd5) Handle(conn *Conn, params string) (AuthUser, error)

Handles the negotiation of an AUTH CRAM-MD5 request https://en.wikipedia.org/wiki/CRAM-MD5 http://www.samlogic.net/articles/smtp-commands-reference-auth.htm

type AuthPlain

type AuthPlain struct {
	Auth SimpleAuthFunc
}

func (*AuthPlain) Handle

func (a *AuthPlain) Handle(conn *Conn, params string) (AuthUser, error)

Handles the negotiation of an AUTH PLAIN request

type AuthUser

type AuthUser interface {
	IsUser(value string) bool
	Password() string
}

AuthUser should check if a given string identifies that user

type Conn

type Conn struct {
	// Conn is primarily a wrapper around a net.Conn object
	net.Conn

	// Track some mutable for this connection
	IsTLS    bool
	Errors   []error
	User     AuthUser
	FromAddr *mail.Address
	ToAddr   []*mail.Address

	// Configuration options
	MaxSize      int
	ReadTimeout  int64
	WriteTimeout int64
	// contains filtered or unexported fields
}

func (*Conn) EndTX

func (c *Conn) EndTX() error

EndTX closes off a MAIL transaction and returns a message object

func (*Conn) ReadData

func (c *Conn) ReadData() (string, error)

ReadData brokers the special case of SMTP data messages

func (*Conn) ReadLine

func (c *Conn) ReadLine() (string, error)

ReadLine reads a single line from the client

func (*Conn) ReadSMTP

func (c *Conn) ReadSMTP() (string, string, error)

ReadSMTP pulls a single SMTP command line (ending in a carriage return + newline)

func (*Conn) Reset

func (c *Conn) Reset()

func (*Conn) StartTX

func (c *Conn) StartTX(from *mail.Address) error

StartTX starts a new MAIL transaction

func (*Conn) WriteEHLO

func (c *Conn) WriteEHLO(message string) error

WriteEHLO writes an EHLO line, see https://tools.ietf.org/html/rfc2821#section-4.1.1.1

func (*Conn) WriteOK

func (c *Conn) WriteOK() error

WriteOK is a convenience function for sending the default OK response

func (*Conn) WriteSMTP

func (c *Conn) WriteSMTP(code int, message string) error

WriteSMTP writes a general SMTP line

type Extension

type Extension interface {
	Handle(*Conn, string) error
	EHLO() string
}

type MessageHandler

type MessageHandler func(m *email.Message) error

MessageHandler functions handle application of business logic to the inbound message

type SMTPError

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

SMTPError is an error + SMTP response code

func (*SMTPError) Code

func (a *SMTPError) Code() int

Code pulls the code

func (*SMTPError) Error

func (a *SMTPError) Error() string

Error pulls the base error value

type Server

type Server struct {
	Name string

	TLSConfig  *tls.Config
	ServerName string

	// MaxSize of incoming message objects, zero for no cap otherwise
	// larger messages are thrown away
	MaxSize int

	// MaxConn limits the number of concurrent connections being handled
	MaxConn int

	// MaxCommands is the maximum number of commands a server will accept
	// from a single client before terminating the session
	MaxCommands int

	// RateLimiter gets called before proceeding through to message handling
	RateLimiter func(*Conn) bool

	// Handler is the handoff function for messages
	Handler MessageHandler

	// Auth is an authentication-handling extension
	Auth Extension

	// Extensions is a map of server-specific extensions & overrides, by verb
	Extensions map[string]Extension

	// Disabled features
	Disabled map[string]bool

	// help message to display in response to a HELP request
	Help string

	// Logger to print out status info
	Logger email.Logger
	// contains filtered or unexported fields
}

func NewServer

func NewServer(handler func(*email.Message) error) *Server

NewServer creates a server with the default settings

func (*Server) Address

func (s *Server) Address() string

func (*Server) Close

func (s *Server) Close()

Close the server connection (not happy with this)

func (*Server) Disable

func (s *Server) Disable(verbs ...string)

Disable server capabilities

func (*Server) Enable

func (s *Server) Enable(verbs ...string)

Enable server capabilities that have previously been disabled

func (*Server) Extend

func (s *Server) Extend(verb string, extension Extension) error

func (*Server) GetAddressArg

func (s *Server) GetAddressArg(argName string, args string) (*mail.Address, error)

func (*Server) Greeting

func (s *Server) Greeting(conn *Conn) string

func (*Server) HandleSMTP

func (s *Server) HandleSMTP(conn *Conn) error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts listening for SMTP commands at the supplied TCP address

func (*Server) SetHelp

func (s *Server) SetHelp(message string) error

SetHelp sets a help message

func (*Server) UseAuth

func (s *Server) UseAuth(auth Extension)

UseAuth assigns the server authentication extension

func (*Server) UseTLS

func (s *Server) UseTLS(cert, key string) error

UseTLS tries to enable TLS on the server (can also just explicitly set the TLSConfig)

type SimpleAuthFunc

type SimpleAuthFunc func(string, string) (AuthUser, bool)

type SimpleExtension

type SimpleExtension struct {
	Handler func(*Conn, string) error
	Ehlo    string
}

func (*SimpleExtension) EHLO

func (s *SimpleExtension) EHLO() string

func (*SimpleExtension) Handle

func (s *SimpleExtension) Handle(c *Conn, args string) error

Jump to

Keyboard shortcuts

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