mailstore

package
v0.0.0-...-1cf758b Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 6 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DummyMailbox

type DummyMailbox struct {
	ID uint32
	// contains filtered or unexported fields
}

DummyMailbox is an in-memory implementation of a Mailstore Mailbox

func (*DummyMailbox) DebugPrintMailbox

func (m *DummyMailbox) DebugPrintMailbox()

DebugPrintMailbox prints out all messages in the mailbox to the command line for debugging purposes

func (*DummyMailbox) DeleteFlaggedMessages

func (m *DummyMailbox) DeleteFlaggedMessages() ([]Message, error)

DeleteFlaggedMessages deletes messages marked with the Delete flag and returns them.

func (*DummyMailbox) LastUID

func (m *DummyMailbox) LastUID() uint32

LastUID returns the UID of the last message in the mailbox or if the mailbox is empty, the next expected UID

func (*DummyMailbox) MessageBySequenceNumber

func (m *DummyMailbox) MessageBySequenceNumber(seqno uint32) Message

MessageBySequenceNumber returns a single message given the message's sequence number

func (*DummyMailbox) MessageByUID

func (m *DummyMailbox) MessageByUID(uidno uint32) Message

MessageByUID returns a single message given the message's sequence number

func (*DummyMailbox) MessageSetBySequenceNumber

func (m *DummyMailbox) MessageSetBySequenceNumber(set types.SequenceSet) []Message

MessageSetBySequenceNumber returns a slice of messages given a set of sequence number ranges

func (*DummyMailbox) MessageSetByUID

func (m *DummyMailbox) MessageSetByUID(set types.SequenceSet) []Message

MessageSetByUID returns a slice of messages given a set of UID ranges. eg 1,5,9,28:140,190:*

func (*DummyMailbox) Messages

func (m *DummyMailbox) Messages() uint32

Messages returns the total number of messages in the Mailbox

func (*DummyMailbox) Name

func (m *DummyMailbox) Name() string

Name returns the Mailbox's name

func (*DummyMailbox) NewMessage

func (m *DummyMailbox) NewMessage() Message

NewMessage creates a new message in the dummy mailbox.

func (*DummyMailbox) NextUID

func (m *DummyMailbox) NextUID() uint32

NextUID returns the UID that is likely to be assigned to the next new message in the Mailbox

func (*DummyMailbox) Recent

func (m *DummyMailbox) Recent() uint32

Recent returns the number of messages in the mailbox which are currently marked with the 'Recent' flag

func (*DummyMailbox) Unseen

func (m *DummyMailbox) Unseen() uint32

Unseen returns the number of messages in the mailbox which are currently marked with the 'Unseen' flag

type DummyMailstore

type DummyMailstore struct {
	User *DummyUser
}

DummyMailstore is an in-memory mail storage for testing purposes and to provide an example implementation of a mailstore

func NewDummyMailstore

func NewDummyMailstore() *DummyMailstore

NewDummyMailstore performs some initialisation and should always be used to create a new DummyMailstore

func (*DummyMailstore) Authenticate

func (d *DummyMailstore) Authenticate(username string, password string) (User, error)

Authenticate implements the Authenticate method on the Mailstore interface

type DummyMessage

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

DummyMessage is a representation of a single in-memory message in a DummyMailbox.

func (*DummyMessage) AddFlags

func (m *DummyMessage) AddFlags(newFlags types.Flags) Message

AddFlags adds the given flag to the message.

func (*DummyMessage) Body

func (m *DummyMessage) Body() string

Body returns the full body of the message

func (*DummyMessage) Flags

func (m *DummyMessage) Flags() types.Flags

Flags returns any flags on the message.

func (*DummyMessage) Header

func (m *DummyMessage) Header() (hdr textproto.MIMEHeader)

Header returns the message's MIME Header.

func (*DummyMessage) InternalDate

func (m *DummyMessage) InternalDate() time.Time

InternalDate returns the internally stored date of the message

func (*DummyMessage) Keywords

func (m *DummyMessage) Keywords() []string

Keywords returns any keywords associated with the message

func (*DummyMessage) OverwriteFlags

func (m *DummyMessage) OverwriteFlags(newFlags types.Flags) Message

OverwriteFlags replaces any flags on the message with those specified.

func (*DummyMessage) RemoveFlags

func (m *DummyMessage) RemoveFlags(newFlags types.Flags) Message

RemoveFlags removes the given flag from the message.

func (*DummyMessage) Save

func (m *DummyMessage) Save() (Message, error)

Save saves the message to the mailbox it belongs to.

func (*DummyMessage) SequenceNumber

func (m *DummyMessage) SequenceNumber() uint32

SequenceNumber returns the message's sequence number.

func (*DummyMessage) SetBody

func (m *DummyMessage) SetBody(newBody string) Message

SetBody sets the body of the message.

func (*DummyMessage) SetHeaders

func (m *DummyMessage) SetHeaders(newHeader textproto.MIMEHeader) Message

SetHeaders sets the e-mail headers of the message.

func (*DummyMessage) Size

func (m *DummyMessage) Size() uint32

Size returns the message's full RFC822 size, including full message header and body.

func (*DummyMessage) UID

func (m *DummyMessage) UID() uint32

UID returns the message's unique identifier (UID).

type DummyUser

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

DummyUser is an in-memory representation of a mailstore's user

func (*DummyUser) MailboxByName

func (u *DummyUser) MailboxByName(name string) (Mailbox, error)

MailboxByName returns a DummyMailbox object, given the mailbox's name

func (*DummyUser) Mailboxes

func (u *DummyUser) Mailboxes() []Mailbox

Mailboxes implements the Mailboxes method on the User interface

type Mailbox

type Mailbox interface {
	// The name of the mailbox
	Name() string

	// The unique identifier that will LIKELY be assigned
	// to the next mail that is added to this mailbox
	NextUID() uint32

	// The UID of the very last message in the mailbox
	// If the mailbox is empty, this should return the next expected UID
	LastUID() uint32

	// Number of recent messages in the mailbox
	Recent() uint32

	// Number of messages in the mailbox
	Messages() uint32

	// Number messages that do not have the Unseen flag set yet
	Unseen() uint32

	// Get a message by its sequence number
	MessageBySequenceNumber(seqno uint32) Message

	// Get a message by its uid number
	MessageByUID(uidno uint32) Message

	// Get messages that belong to a set of ranges of UIDs
	MessageSetByUID(set types.SequenceSet) []Message

	// Get messages that belong to a set of ranges of sequence numbers
	MessageSetBySequenceNumber(set types.SequenceSet) []Message

	// Creates a new (empty) message that belongs to this mailbox
	// NOTE: This should not make any changes to the mailbox until the
	// message's `Save` method is called.
	NewMessage() Message

	// DeleteFlaggedMessages deletes messages marked with the Delete flag and
	// returns them. It also updates the sequence numbers of all messages in the
	// mailbox to account for the deleted messages.
	DeleteFlaggedMessages() ([]Message, error)
}

Mailbox represents a mailbox belonging to a user in the mail storage system

type Mailstore

type Mailstore interface {
	// Attempt to authenticate a user with given credentials,
	// and return the user if successful
	Authenticate(username string, password string) (User, error)
}

Mailstore is an interface to be implemented to provide mail storage

type Message

type Message interface {
	// Return the message's MIME headers as a map in format
	// key: value
	Header() textproto.MIMEHeader

	// Return the unique id of the email
	UID() uint32

	// Return the sequence number of the email
	SequenceNumber() uint32

	// Return the RFC822 size of the message
	Size() uint32

	// Return the date the email was received by the server
	// (This is not the date on the envelope of the email)
	InternalDate() time.Time

	// Return the body of the email
	Body() string

	// Return the list of custom keywords/flags for this message
	Keywords() []string

	// Get the flags for this message
	Flags() types.Flags

	// Overwrite the flags for this message and return the updated message
	OverwriteFlags(types.Flags) Message

	// Write the flags for this message and return the updated message
	AddFlags(types.Flags) Message

	// Write the flags for this message and return the updated message
	RemoveFlags(types.Flags) Message

	// Overwrite the message headers
	SetHeaders(textproto.MIMEHeader) Message

	// Overwrite the message body
	SetBody(string) Message

	// Save any changes to the message
	Save() (Message, error)
}

Message represents a standard email message

type User

type User interface {
	// Return a list of mailboxes belonging to this user
	Mailboxes() []Mailbox

	MailboxByName(name string) (Mailbox, error)
}

User represents a user in the mail storage system

Jump to

Keyboard shortcuts

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