smtpd

package
v0.0.0-...-dcb6a6f Latest Latest
Warning

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

Go to latest
Published: May 6, 2014 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const INDEX_FILE = "index.gob"

Name of index file in each mailbox

View Source
const STAMP_FMT = "Mon, 02 Jan 2006 15:04:05 -0700 (MST)"

Variables

View Source
var ErrNotExist = errors.New("Message does not exist")
View Source
var ErrNotWritable = errors.New("Message not writable")

Functions

func HashMailboxName

func HashMailboxName(mailbox string) string

Take a mailbox name and hash it into the directory we'll store it in

func JoinStringList

func JoinStringList(listOfStrings *list.List) string

JoinStringList joins a List containing strings by commas

func ParseEmailAddress

func ParseEmailAddress(address string) (local string, domain string, err error)

ParseEmailAddress unescapes an email address, and splits the local part from the domain part. An error is returned if the local or domain parts fail validation following the guidelines in RFC3696.

func ParseMailboxName

func ParseMailboxName(localPart string) (result string, err error)

Take "user+ext" and return "user", aka the mailbox we'll store it in Return error if it contains invalid characters, we don't accept anything that must be quoted according to RFC3696.

func StartRetentionScanner

func StartRetentionScanner(ds DataStore)

func ValidateDomainPart

func ValidateDomainPart(domain string) bool

ValidateDomainPart returns true if the domain part complies to RFC3696, RFC1035

Types

type DataStore

type DataStore interface {
	MailboxFor(emailAddress string) (Mailbox, error)
	AllMailboxes() ([]Mailbox, error)
}

func DefaultFileDataStore

func DefaultFileDataStore() DataStore

DefaultFileDataStore creates a new DataStore object. It uses the inbucket.Config object to construct it's path.

func NewFileDataStore

func NewFileDataStore(cfg config.DataStoreConfig) DataStore

NewFileDataStore creates a new DataStore object using the specified path

type FileDataStore

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

A DataStore is the root of the mail storage hiearchy. It provides access to Mailbox objects

func (*FileDataStore) AllMailboxes

func (ds *FileDataStore) AllMailboxes() ([]Mailbox, error)

AllMailboxes returns a slice with all Mailboxes

func (*FileDataStore) MailboxFor

func (ds *FileDataStore) MailboxFor(emailAddress string) (Mailbox, error)

Retrieves the Mailbox object for a specified email address, if the mailbox does not exist, it will attempt to create it.

type FileMailbox

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

A Mailbox manages the mail for a specific user and correlates to a particular directory on disk.

func (*FileMailbox) GetMessage

func (mb *FileMailbox) GetMessage(id string) (Message, error)

GetMessage decodes a single message by Id and returns a Message object

func (*FileMailbox) GetMessages

func (mb *FileMailbox) GetMessages() ([]Message, error)

GetMessages scans the mailbox directory for .gob files and decodes them into a slice of Message objects.

func (*FileMailbox) NewMessage

func (mb *FileMailbox) NewMessage() (Message, error)

NewMessage creates a new Message object and sets the Date and Id fields. It will also delete messages over messageCap if configured.

func (*FileMailbox) Purge

func (mb *FileMailbox) Purge() error

Delete all messages in this mailbox

func (*FileMailbox) String

func (mb *FileMailbox) String() string

type FileMessage

type FileMessage struct {

	// Stored in GOB
	Fid      string
	Fdate    time.Time
	Ffrom    string
	Fsubject string
	Fsize    int64
	// contains filtered or unexported fields
}

Message contains a little bit of data about a particular email message, and methods to retrieve the rest of it from disk.

func (*FileMessage) Append

func (m *FileMessage) Append(data []byte) error

Append data to a newly opened Message, this will fail on a pre-existing Message and after Close() is called.

func (*FileMessage) Close

func (m *FileMessage) Close() error

Close this Message for writing - no more data may be Appended. Close() will also trigger the creation of the .gob file.

func (*FileMessage) Date

func (m *FileMessage) Date() time.Time

func (*FileMessage) Delete

func (m *FileMessage) Delete() error

Delete this Message from disk by removing both the gob and raw files

func (*FileMessage) From

func (m *FileMessage) From() string

func (*FileMessage) Id

func (m *FileMessage) Id() string

func (*FileMessage) RawReader

func (m *FileMessage) RawReader() (reader io.ReadCloser, err error)

RawReader opens the .raw portion of a Message as an io.ReadCloser

func (*FileMessage) ReadBody

func (m *FileMessage) ReadBody() (body *enmime.MIMEBody, err error)

ReadBody opens the .raw portion of a Message and returns a MIMEBody object

func (*FileMessage) ReadHeader

func (m *FileMessage) ReadHeader() (msg *mail.Message, err error)

ReadHeader opens the .raw portion of a Message and returns a standard Go mail.Message object

func (*FileMessage) ReadRaw

func (m *FileMessage) ReadRaw() (raw *string, err error)

ReadRaw opens the .raw portion of a Message and returns it as a string

func (*FileMessage) Size

func (m *FileMessage) Size() int64

func (*FileMessage) String

func (m *FileMessage) String() string

func (*FileMessage) Subject

func (m *FileMessage) Subject() string

type Mailbox

type Mailbox interface {
	GetMessages() ([]Message, error)
	GetMessage(id string) (Message, error)
	Purge() error
	NewMessage() (Message, error)
	String() string
}

type Message

type Message interface {
	Id() string
	From() string
	Date() time.Time
	Subject() string
	RawReader() (reader io.ReadCloser, err error)
	ReadHeader() (msg *mail.Message, err error)
	ReadBody() (body *enmime.MIMEBody, err error)
	ReadRaw() (raw *string, err error)
	Append(data []byte) error
	Close() error
	Delete() error
	String() string
	Size() int64
}

type Server

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

Real server code starts here

func NewSmtpServer

func NewSmtpServer(cfg config.SmtpConfig, ds DataStore) *Server

Init a new Server object

func (*Server) Drain

func (s *Server) Drain()

Drain causes the caller to block until all active SMTP sessions have finished

func (*Server) Start

func (s *Server) Start()

Main listener loop

func (*Server) Stop

func (s *Server) Stop()

Stop requests the SMTP server closes it's listener

type Session

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

func NewSession

func NewSession(server *Server, id int, conn net.Conn) *Session

func (*Session) String

func (ss *Session) String() string

type State

type State int
const (
	GREET State = iota // Waiting for HELO
	READY              // Got HELO, waiting for MAIL
	MAIL               // Got MAIL, accepting RCPTs
	DATA               // Got DATA, waiting for "."
	QUIT               // Close session
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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