mailtest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mailtest is an in-memory mail.Mailbox for tests of the packages that sit on top of the connector. It keeps the same promises as the IMAP one: UIDs only grow, a moved message gets a new UID in its destination, fetching never sets \Seen, and a reference with the wrong UIDVALIDITY finds nothing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mailbox

type Mailbox struct {
	AccountID int64
	Caps      mail.Caps
	// Moves counts move commands, one per Move and one per MoveMany, so a test can tell a
	// batch from a run of single moves. Read it while nothing else uses the mailbox.
	Moves int
	// contains filtered or unexported fields
}

Mailbox is the fake. Set Caps before use to simulate a limited server.

func New

func New(accountID int64) *Mailbox

New returns a mailbox with an empty INBOX on a server that supports everything.

func (*Mailbox) AddFolder

func (m *Mailbox) AddFolder(name, role string)

AddFolder creates a folder with a special-use role ("" for none). Re-adding an existing name rebuilds it empty with a new UIDVALIDITY.

func (*Mailbox) Append added in v0.3.0

func (m *Mailbox) Append(ctx context.Context, name string, raw []byte, flags []string, date time.Time) (mail.MsgRef, error)

Append adds a message to a folder, as APPEND does, and returns its place as APPENDUID would, without waking watchers of new mail (a draft is not an arrival).

func (*Mailbox) Capabilities

func (m *Mailbox) Capabilities() mail.Caps

Capabilities returns Caps.

func (*Mailbox) Close

func (m *Mailbox) Close() error

Close does nothing.

func (*Mailbox) Delete added in v0.3.0

func (m *Mailbox) Delete(ctx context.Context, ref mail.MsgRef) error

Delete removes one message for good; without UIDPLUS it refuses, as the IMAP connector does.

func (*Mailbox) Deliver

func (m *Mailbox) Deliver(folderName, eml string, flags ...string) mail.MsgRef

Deliver puts an RFC 5322 message into a folder, as new mail arriving, and wakes watchers.

func (*Mailbox) EnsureFolder

func (m *Mailbox) EnsureFolder(ctx context.Context, name string) error

EnsureFolder creates the folder if it is missing.

func (*Mailbox) Fetch

func (m *Mailbox) Fetch(ctx context.Context, ref mail.MsgRef, maxBody int) (*message.Raw, error)

Fetch returns a copy of the message with its text cut to maxBody bytes. Flags are untouched.

func (*Mailbox) FetchMany

func (m *Mailbox) FetchMany(ctx context.Context, refs []mail.MsgRef, maxBody int) ([]*message.Raw, error)

FetchMany returns a copy of each message, like Fetch, and nil for one that is gone.

func (*Mailbox) FetchSince

func (m *Mailbox) FetchSince(ctx context.Context, name string, since time.Time, limit int) ([]mail.MsgRef, int, error)

FetchSince lists messages delivered at or after since, oldest first, newest limit only.

func (*Mailbox) FindByMessageID

func (m *Mailbox) FindByMessageID(ctx context.Context, name, messageID string) (mail.MsgRef, error)

FindByMessageID returns the newest message in the folder with that Message-ID.

func (*Mailbox) Flags

func (m *Mailbox) Flags(ctx context.Context, ref mail.MsgRef) ([]string, error)

Flags returns the message's flags, sorted.

func (*Mailbox) Folders

func (m *Mailbox) Folders(ctx context.Context) ([]mail.Folder, error)

Folders lists folders by name.

func (*Mailbox) Message added in v0.3.0

func (m *Mailbox) Message(ref mail.MsgRef) (raw string, flags []string, err error)

Message returns the whole stored message at ref, header and text, and its flags: for tests that check what was appended.

func (*Mailbox) Move

func (m *Mailbox) Move(ctx context.Context, ref mail.MsgRef, dest string) (mail.MsgRef, error)

Move takes the message out of its folder and gives it a new UID in dest.

func (*Mailbox) MoveMany added in v0.3.0

func (m *Mailbox) MoveMany(ctx context.Context, refs []mail.MsgRef, dest string) ([]mail.MsgRef, error)

MoveMany is Move for each message, as one command, with a zero MsgRef for one that is not there.

func (*Mailbox) Present added in v0.3.0

func (m *Mailbox) Present(ctx context.Context, name string, uidValidity uint32, uids []uint32) ([]uint32, error)

Present reports which of uids the folder still holds; a message marked \Deleted is gone.

func (*Mailbox) SentRecipients

func (m *Mailbox) SentRecipients(ctx context.Context, name string, limit int) ([]mail.Recipient, error)

SentRecipients returns the To and Cc addresses of the newest limit messages.

func (*Mailbox) SetFlags

func (m *Mailbox) SetFlags(ctx context.Context, ref mail.MsgRef, add, remove []string) error

SetFlags adds and removes flags.

func (*Mailbox) Status

func (m *Mailbox) Status(ctx context.Context, name string) (mail.FolderStatus, error)

Status returns the folder's UIDVALIDITY and next UID.

func (*Mailbox) Watch

func (m *Mailbox) Watch(ctx context.Context, name string, lastUID uint32, out chan<- mail.NewMail) error

Watch sends every message above lastUID, then each delivery, until ctx is done.

Jump to

Keyboard shortcuts

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