smtp

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: GPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxMessageSize = 30 * 1024 * 1024 // 30MiB

Variables

This section is empty.

Functions

func SearchByHeader

func SearchByHeader[T ContentHaver](haystack []T, rxs ...*regexp.Regexp) []T

SearchByHeader returns the list of all given ContentHavers that, for each of the given regular expressions, has at least one header matching it (different regexes can be matched by different headers or the same header).

Note that in the context of this function, a regex is performed for each header value individually, including for multi-value headers. The header value is first serialized by concatenating it after the header name, colon and space. It is not being encoded as if for transport (e.g. quoted- printable), but concatenated as-is.

Types

type ContentHaver

type ContentHaver interface {
	Content() *ReceivedContent
}

ContentHaver makes it easier to write algorithms over types that have an email message and/or multipart content.

type ReceivedContent

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

ReceivedContent contains the contents of an email message or multipart part.

func NewReceivedContent

func NewReceivedContent(
	headers map[string][]string, bodyReader io.Reader, maxMessageSize int64,
) (*ReceivedContent, error)

NewReceivedContent parses a message or part headers and body into a ReceivedContent struct.

Incoming data is truncated after the given maximum message size. If a maxMessageSize of 0 is given, this function will default to using DefaultMaxMessageSize.

func (*ReceivedContent) Body

func (c *ReceivedContent) Body() []byte

func (*ReceivedContent) ContentType

func (c *ReceivedContent) ContentType() string

func (*ReceivedContent) ContentTypeParams

func (c *ReceivedContent) ContentTypeParams() map[string]string

func (*ReceivedContent) Headers

func (c *ReceivedContent) Headers() map[string][]string

func (*ReceivedContent) IsMultipart

func (c *ReceivedContent) IsMultipart() bool

func (*ReceivedContent) Multiparts

func (c *ReceivedContent) Multiparts() []*ReceivedPart

type ReceivedMessage

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

ReceivedMessage contains a single email message as received via SMTP.

func NewReceivedMessage

func NewReceivedMessage(
	index int,
	from string, rcptTo []string, rawMessageData []byte, receivedAt time.Time,
	maxMessageSize int64,
) (*ReceivedMessage, error)

NewReceivedMessage parses a raw message as received via SMTP into a ReceivedMessage struct.

Incoming data is truncated after the given maximum message size. If a maxMessageSize of 0 is given, this function will default to using DefaultMaxMessageSize.

func NewReceivedMessageFromParsed

func NewReceivedMessageFromParsed(
	index int,
	from string, rcptTo []string, rawMessageData []byte, receivedAt time.Time,
	maxMessageSize int64, parsedMsg *mail.Message,
) (*ReceivedMessage, error)

NewReceivedMessageFromParsed creates a ReceivedMessage from an already parsed email.

See the documentation of NewReceivedMessage for more details.

func (*ReceivedMessage) Content

func (m *ReceivedMessage) Content() *ReceivedContent

func (*ReceivedMessage) Index

func (m *ReceivedMessage) Index() int

func (*ReceivedMessage) RawMessageData

func (m *ReceivedMessage) RawMessageData() []byte

func (*ReceivedMessage) ReceivedAt

func (m *ReceivedMessage) ReceivedAt() time.Time

func (*ReceivedMessage) SmtpFrom

func (m *ReceivedMessage) SmtpFrom() string

func (*ReceivedMessage) SmtpRcptTo

func (m *ReceivedMessage) SmtpRcptTo() []string

type ReceivedPart

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

ReceivedPart contains a single part of a multipart message as received via SMTP.

func NewReceivedPart

func NewReceivedPart(index int, p *multipart.Part, maxMessageSize int64) (*ReceivedPart, error)

NewReceivedPart parses a MIME multipart part into a ReceivedPart struct.

maxMessageSize is passed through to NewReceivedContent (see its documentation for details).

func (*ReceivedPart) Content

func (p *ReceivedPart) Content() *ReceivedContent

func (*ReceivedPart) Index

func (p *ReceivedPart) Index() int

type Server

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

Server contains a basic SMTP server for testing purposes.

It will accept incoming messages and save them to an internal list of received messages, which can be queried using the appropriate methods of Server.

func NewServer

func NewServer(addr string, maxMessageSize int64) *Server

NewServer creates a new testing SMTP server.

The new server will listen at the provided address.

Incoming messages are truncated after the given maximum message size. If a maxMessageSize of 0 is given, Server will default to using DefaultMaxMessageSize.

func (*Server) AppendMessage

func (s *Server) AppendMessage(msg *ReceivedMessage)

AppendMessage adds a custom message to the Server's storage.

The index of the provided message will be updated to the index at which it was actually inserted into the Server's storage.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe runs the SMTP server. It will not return until the server is shut down or otherwise aborts.

func (*Server) ReceivedMessage

func (s *Server) ReceivedMessage(idx int) (*ReceivedMessage, error)

ReceivedMessage returns a message that the server has retrieved by its index in the list of received messages.

func (*Server) ReceivedMessages

func (s *Server) ReceivedMessages() []*ReceivedMessage

ReceivedMessages returns the list of all messages that the server has retrieved.

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(mux *http.ServeMux, prefix string, skipLogs bool)

RegisterRoutes sets up HTTP routes for inspecting the SMTP Server's received messages.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown shuts down the SMTP server that was previously started using ListenAndServe.

Jump to

Keyboard shortcuts

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