mail

package
v0.0.0-...-6b4b14b Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2021 License: EUPL-1.2 Imports: 19 Imported by: 0

Documentation

Overview

Package mail implements a mail server, client and various other bits and bobs.

Index

Constants

View Source
const (
	// OutCapacity is the capacity of the output queue.
	OutCapacity = 250

	// OutCapacityMargin is the additional margin to keep in the output queue.
	// This margin avoids the output queue becoming blocked
	// when multiple messages arrive simultaneously.
	OutCapacityMargin = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	GetList    ListRetriever
	Directory  string
	HandleFunc *MessageHandler
}

Backend contains the backend implementation for the mail server. It implements smtp.Backend.

func (*Backend) AnonymousLogin

func (bkd *Backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error)

AnonymousLogin requires clients to authenticate using SMTP AUTH before sending emails.

func (*Backend) Login

func (bkd *Backend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error)

Login handles a login command with username and password.

type Client

type Client struct {
	SMTPServer string
	// contains filtered or unexported fields
}

Client represents an SMTP client.

func NewClient

func NewClient(server string) (s *Client, err error)

NewClient configures an SMTP client.

func (*Client) Connect

func (c *Client) Connect() (err error)

Connect connects to the email server.

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect disconnects from the email server.

func (*Client) SendMessage

func (c *Client) SendMessage(msg *SingleMessage) (err error)

SendMessage sends an email message

func (*Client) Worker

func (c *Client) Worker(ch chan *SingleMessage) (err error)

Worker sends emails that are placed in a channel. It automatically connects and disconnects to

type Config

type Config struct {
	// Address is the address to listen on.
	Address string `yaml:"address"`

	// Domain is the domain of this mail server.
	Domain string `yaml:"domain"`

	// SMTPServer contains the address the SMTP server to use for sending mail.
	SMTPServer string `yaml:"smtp_server"`

	// Directory is the directory used for storing received mails.
	Directory string `yaml:"directory"`
}

Config contains the configuration of an SMTP server.

type List

type List struct {
	ID, Name, Address, URL string
	Members                []*Recipient
	Hidden                 bool
}

List represents a mailing list

func (*List) Header

func (l *List) Header() mail.Header

Header returns the mailing list headers.

func (*List) IDString

func (l *List) IDString() string

IDString returns the mailing list ID string for use in mail headers.

type ListRetriever

type ListRetriever func(to string) *List

ListRetriever represents a function that can be used to retrieve a mailing list.

type Message

type Message struct {
	*mail.Message
	Lists  []*List
	Author string
	Date   time.Time
	Body   []byte
}

Message represents a single e-mail message on one or more mailing lists.

func MessageFromFile

func MessageFromFile(path string, lists ...*List) (*Message, error)

MessageFromFile opens and parses a message from a file.

func (*Message) FileName

func (m *Message) FileName() string

FileName returns the filename for this message when stored in a maildir.

func (*Message) ID

func (m *Message) ID() string

ID returns a unique identifier for this message

func (*Message) SetBody

func (m *Message) SetBody(r io.Reader) (err error)

SetBody sets the body of the message from an io.Reader. Headers are modified as needed.

func (*Message) SingleMessages

func (m *Message) SingleMessages() (messages []*SingleMessage)

SingleMessages returns a set of single messages corresponding to this message.

func (*Message) WriteRaw

func (m *Message) WriteRaw(w io.Writer) (err error)

WriteRaw writes the current message to an io.Writer. Nothing is modified.

func (*Message) WriteToFile

func (m *Message) WriteToFile(path string) error

WriteToFile writes the message to a given file.

type MessageHandler

type MessageHandler func(*Message) error

MessageHandler is a function that handles a message.

type Recipient

type Recipient struct {
	Name, Address string
}

Recipient contains an email recipient

func (*Recipient) String

func (r *Recipient) String() string

String returns a string version of the recipient. It can be used in email headers.

type Server

type Server struct {
	*smtp.Server
	Client     *Client
	OutQueue   chan *SingleMessage
	HandleFunc MessageHandler
	// contains filtered or unexported fields
}

Server is an SMTP server.

func NewServer

func NewServer(config *Config, listFunc ListRetriever) (*Server, error)

NewServer creates a new SMTP server.

func (*Server) HandleMessage

func (s *Server) HandleMessage(in *Message) error

HandleMessage handles an incoming message from the queue or some external component.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe listens on the network address s.Addr and serves incoming connections. Incoming messages are automatically added to OutQueue.

func (*Server) OutWorker

func (s *Server) OutWorker() error

OutWorker takes messages from OutQueue and attempts to send them.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown performs a graceful shutdown of the mail server.

type Session

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

Session contains the sessions information for a connection. It implements smtp.Session.

func (*Session) Data

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

Data handles the DATA command, and the end of the message.

func (*Session) Logout

func (s *Session) Logout() error

Logout frees all resources associated with session.

func (*Session) Mail

func (s *Session) Mail(from string) error

Mail handles the MAIL FROM command.

func (*Session) Rcpt

func (s *Session) Rcpt(to string) error

Rcpt handles the RCPT TO command.

func (*Session) Reset

func (s *Session) Reset()

Reset discards the currently processed message.

type SingleMessage

type SingleMessage struct {
	*Message
	List      *List
	Recipient *Recipient
}

SingleMessage is an email/list/recipient link. Recipient can be `nil`.

func (*SingleMessage) Write

func (m *SingleMessage) Write(w io.Writer) error

Write writes the current message to an io.Writer. The Recipient is used to modify headers as required.

Jump to

Keyboard shortcuts

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