delivery

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongAddressPassword is returned when an address either does not exist or the password
	// does not match the hash.
	ErrWrongAddressPassword = errors.New("wrong address or password combination")
)

Functions

This section is empty.

Types

type Addressbook

type Addressbook interface {
	// Lookup looks up an address without a transaction. See LookupTx.
	Lookup(context.Context, models.Address) (*LookupResult, error)
	// LookupTx looks up an address. The result indicates if the address belongs to a local domain
	// and if it does, if it exists. Only database errors may occur.
	LookupTx(context.Context, database.Queryer, models.Address) (*LookupResult, error)
}

Addressbook is a registry to lookup mail addresses.

func NewAddressbook

func NewAddressbook(
	db database.Conn,
	domainDao database.DomainDao,
	mailboxDao database.MailboxDao,
) Addressbook

NewAddressbook creates a new Addressbook.

type Authenticator

type Authenticator interface {
	// Auth searches for a mailbox by address. If the address does not exist, is not local or the
	// password does not match the stored hash, ErrWrongAddressPassword is returned. Database errors
	// may occur.
	Auth(ctx context.Context, name, pass []byte) (*models.MailboxEntity, error)
}

Authenticator is for authentication of users based on their addresses.

func NewAuthenticator

func NewAuthenticator(
	db database.Conn,
	mailboxCredentialDao database.MailboxCredentialDao,
	addressbook Addressbook,
) Authenticator

NewAuthenticator creates a new Authenticator.

type Cleaner

type Cleaner interface {
	// Clean finds all orphaned mails and deletes them. An orphaned mail is a mail not assigned to a
	// mailbox and not queued for outbound delivery.
	Clean(ctx context.Context) error
}

Cleaner is a service to clean orphaned mail blobs and their database counterparts.

func NewCleaner

func NewCleaner(db database.Conn, mailDao database.MailDao, blobs storage.Blobs) Cleaner

NewCleaner creates a new Cleaner.

type Courier

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

Courier handles the delivery of outbound mails.

func NewCourier

func NewCourier(
	db database.Conn,
	mailDao database.MailDao,
	recipientDao database.RecipientDao,
	blobs storage.Blobs,
) *Courier

NewCourier creates a new courier for delivery.

func (*Courier) SendMail

func (c *Courier) SendMail(ctx context.Context, mail *models.MailEntity) (SendResult, error)

SendMail attempts to send a mail to all pending recipients. An error is only returned on database errors. Other errors are logged but only affect the SendResult. After the attempt, the mail attempt count and the status of all pending recipients is updated and stored in the database.

type Envelope

type Envelope struct {
	// Helo is the string provided by an smtp client when greeting the server.
	Helo string
	// Addr is the remote address of the sender.
	Addr net.IP
	// Date is the time when the data transmission begins.
	Date time.Time
	// From is the email-address of the sender.
	From models.Address
	// To is a list of recipient email-addresses.
	To []models.Address
}

Envelope stores the information about an email before the actual content is read. It is basically what a real envelope is to mail.

type Inbox

type Inbox struct {
	Mails []models.MailEntity
	// contains filtered or unexported fields
}

Inbox is a list of unreal mails as well as a set of "marks". Marked mails are removed, when the inbox state is committed.

func (*Inbox) Count

func (i *Inbox) Count() int

Count is the amount of non-marked mails.

func (*Inbox) IsMarked

func (i *Inbox) IsMarked(index int) bool

IsMarked checks if a mail is marked for removal.

func (*Inbox) Mail

func (i *Inbox) Mail(index int) (models.MailEntity, bool)

Mail returns the mail if it exists and is not yet marked.

func (*Inbox) Mark

func (i *Inbox) Mark(index int)

Mark marks a mail for removal.

func (*Inbox) Reset

func (i *Inbox) Reset()

Reset removes all marks.

func (*Inbox) Size

func (i *Inbox) Size() int64

Size is the sum of the sizes of non-marked mails.

type Inboxer

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

Inboxer is service to read a list of unread mails of a mailbox and committing changes later.

func NewInboxer

func NewInboxer(db database.Conn, cleaner Cleaner) *Inboxer

NewInboxer creates a new Inboxer.

func (*Inboxer) Commit

func (i *Inboxer) Commit(ctx context.Context, mailbox *models.MailboxEntity, inbox *Inbox) error

Commit removes all marked mails of an inbox from the mailbox.

func (*Inboxer) Inbox

func (i *Inboxer) Inbox(ctx context.Context, mailbox *models.MailboxEntity) (*Inbox, error)

Inbox reads the a list of unread mails for a mailbox.

type LookupResult

type LookupResult struct {
	// Address is the address used for lookup.
	Address models.Address
	// IsLocal indicates if the domain part of the address is local. This does not imply that the
	// address exists.
	IsLocal bool
	// Mailbox is the local mailbox of an address, if it is local and exists. If Mailbox is not nil
	// IsLocal is implied to be true.
	Mailbox *models.MailboxEntity
}

LookupResult is the result of an address lookup.

type Mailman

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

Mailman handles the delivery of local mails into mailboxes as well as queuing outbound delivery.

func NewMailman

func NewMailman(
	db database.Conn,
	mailDao database.MailDao,
	recipientDao database.RecipientDao,
	blobs storage.Blobs,
	addressbook Addressbook,
	queue *Queue,
) *Mailman

NewMailman creates a new mailman for delivery.

func (*Mailman) Deliver

func (m *Mailman) Deliver(ctx context.Context, envelope Envelope, content io.Reader) error

Deliver goes through the list of recipients and determines if they are local or outbound. Local mails are put into the corresponding mailboxes. Outbound mails are queued for delivery. Because of the queue errors during outbound delivery are not known at this point.

type Queue

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

Queue coordinates the delivery attempts of outbound mails.

func NewQueue

func NewQueue(
	db database.Conn,
	mailDao database.MailDao,
	courier *Courier,
	cleaner Cleaner,
) (*Queue, error)

NewQueue creates a new Queue.

func (*Queue) WakeUp

func (q *Queue) WakeUp(ctx context.Context)

WakeUp schedules the next pending mail for delivery. Only one delivery will be executed at a time.

type SendResult

type SendResult int

SendResult indicates the status of delivery for a collection of recipients.

const (

	// SomePending means at least one recipient is still pending, because of a transient error.
	SomePending SendResult
	// SomeFailed means at least one recipient permanently failed.
	SomeFailed
	// SomeSuccess means at least one recipient was delivered succesfully.
	SomeSuccess
)

Jump to

Keyboard shortcuts

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