backend

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const InternalIDHeaderLength = 51

InternalIDHeaderLength is the expected length of the full header entry, excluding the new line character.

View Source
const InternalIDHeaderLengthWithNewLine = InternalIDHeaderLength + 2

InternalIDHeaderLengthWithNewLine is the same as InternalIDHeaderLength, but includes the \r\n character.

View Source
const InternalIDKey = `X-PM-GLUON-ID`

InternalIDKey is the key of the header entry we add to messages in the mailserver system. This allows us to detect when clients try to create a duplicate of a message, which we treat instead as a copy.

Variables

View Source
var (
	ErrNoSuchUser     = errors.New("no such user")
	ErrNoSuchSnapshot = errors.New("no such snapshot")
	ErrNoSuchMessage  = errors.New("no such message")
	ErrNoSuchMailbox  = errors.New("no such mailbox")

	ErrExistingMailbox     = errors.New("a mailbox with that name already exists")
	ErrAlreadySubscribed   = errors.New("already subscribed to this mailbox")
	ErrAlreadyUnsubscribed = errors.New("not subscribed to this mailbox")
	ErrSessionNotSelected  = errors.New("session is not selected")

	ErrNotImplemented = errors.New("not implemented")
)

Functions

func AsClose

func AsClose(parent context.Context) context.Context

AsClose marks this context as handling a CLOSE command. This modifies some backend behaviour (such as not returning EXPUNGE responses).

func AsSilent

func AsSilent(parent context.Context) context.Context

AsSilent marks this context as handling a silent STORE command. This modifies some backend behaviour (such as not returning EXPUNGE responses).

func AsUID

func AsUID(parent context.Context) context.Context

AsUID marks this context as handling a UID command. This modifies some backend behaviour (such as returning UID within FETCH responses).

func DBAddMessageFlag added in v0.9.0

func DBAddMessageFlag(ctx context.Context, tx *ent.Tx, messageIDs []string, addFlag string) error

func DBAddMessagesToMailbox added in v0.9.0

func DBAddMessagesToMailbox(ctx context.Context, tx *ent.Tx, messageIDs []string, mboxID string) (map[string]int, error)

func DBBumpMailboxUIDNext added in v0.9.0

func DBBumpMailboxUIDNext(ctx context.Context, tx *ent.Tx, mbox *ent.Mailbox, withCount ...int) error

func DBClearRecentFlag added in v0.9.0

func DBClearRecentFlag(ctx context.Context, tx *ent.Tx, mboxID, messageID string) error

func DBClearRecentFlags added in v0.9.0

func DBClearRecentFlags(ctx context.Context, tx *ent.Tx, mboxID string) error

func DBCreateMailbox added in v0.9.0

func DBCreateMailbox(ctx context.Context, tx *ent.Tx, mboxID, name string, flags, permFlags, attrs imap.FlagSet) (*ent.Mailbox, error)

func DBCreateMessages added in v0.9.0

func DBCreateMessages(ctx context.Context, tx *ent.Tx, reqs ...*DBCreateMessageReq) ([]*ent.Message, error)

func DBDeleteMailbox added in v0.9.0

func DBDeleteMailbox(ctx context.Context, tx *ent.Tx, mboxID string) error

func DBDeleteMessages added in v0.9.0

func DBDeleteMessages(ctx context.Context, tx *ent.Tx, messageIDs ...string) error

func DBGetAllMailboxes added in v0.9.0

func DBGetAllMailboxes(ctx context.Context, client *ent.Client) ([]*ent.Mailbox, error)

func DBGetMailboxByID added in v0.9.0

func DBGetMailboxByID(ctx context.Context, client *ent.Client, id string) (*ent.Mailbox, error)

func DBGetMailboxByName added in v0.9.0

func DBGetMailboxByName(ctx context.Context, client *ent.Client, name string) (*ent.Mailbox, error)

func DBGetMailboxMessage added in v0.9.0

func DBGetMailboxMessage(ctx context.Context, client *ent.Client, mailboxID, messageID string) (*ent.UID, error)

func DBGetMailboxMessageIDs added in v0.9.0

func DBGetMailboxMessageIDs(ctx context.Context, client *ent.Client, mailboxID string) ([]string, error)

func DBGetMailboxMessages added in v0.9.0

func DBGetMailboxMessages(ctx context.Context, mbox *ent.Mailbox) ([]*ent.UID, error)

func DBGetMailboxMessagesForNewSnapshot added in v0.9.0

func DBGetMailboxMessagesForNewSnapshot(ctx context.Context, mbox *ent.Mailbox) ([]*ent.UID, error)

func DBGetMailboxName added in v0.9.0

func DBGetMailboxName(ctx context.Context, client *ent.Client, mboxID string) (string, error)

func DBGetMailboxRecentCount added in v0.9.0

func DBGetMailboxRecentCount(ctx context.Context, mbox *ent.Mailbox) (int, error)

func DBGetMessage added in v0.9.0

func DBGetMessage(ctx context.Context, client *ent.Client, messageID string) (*ent.Message, error)

func DBGetMessageDeleted added in v0.9.0

func DBGetMessageDeleted(ctx context.Context, client *ent.Client, mboxID string, messageIDs []string) (map[string]bool, error)

func DBGetMessageFlags added in v0.9.0

func DBGetMessageFlags(ctx context.Context, client *ent.Client, messageIDs []string) (map[string]imap.FlagSet, error)

DBGetMessageFlags returns the flags of the given messages. It does not include per-mailbox flags (\Deleted, \Recent)!

func DBGetMessageID added in v0.9.0

func DBGetMessageID(ctx context.Context, client *ent.Client, internalID string) (string, error)

func DBGetMessageIDsMarkedDeleted added in v0.9.0

func DBGetMessageIDsMarkedDeleted(ctx context.Context, tx *ent.Tx) ([]string, error)

func DBGetMessageMailboxIDs added in v0.9.0

func DBGetMessageMailboxIDs(ctx context.Context, client *ent.Client, messageID string) ([]string, error)

func DBGetMessageUIDs added in v0.9.0

func DBGetMessageUIDs(ctx context.Context, client *ent.Client, mboxID string, messageIDs []string) (map[string]int, error)

func DBGetMessages added in v0.9.0

func DBGetMessages(ctx context.Context, client *ent.Client, messageIDs ...string) (map[string]*ent.Message, error)

func DBGetUIDInterval added in v0.9.0

func DBGetUIDInterval(ctx context.Context, mbox *ent.Mailbox, begin, end int) ([]*ent.UID, error)

func DBMailboxExistsWithID added in v0.9.0

func DBMailboxExistsWithID(ctx context.Context, client *ent.Client, mboxID string) (bool, error)

func DBMailboxExistsWithName added in v0.9.0

func DBMailboxExistsWithName(ctx context.Context, client *ent.Client, name string) (bool, error)

func DBMarkMessageAsDeleted added in v0.9.0

func DBMarkMessageAsDeleted(ctx context.Context, tx *ent.Tx, messageID string) error

func DBMessageExists added in v0.9.0

func DBMessageExists(ctx context.Context, client *ent.Client, messageID string) (bool, error)

func DBRemoveMessageFlag added in v0.9.0

func DBRemoveMessageFlag(ctx context.Context, tx *ent.Tx, messageIDs []string, remFlag string) error

func DBRemoveMessagesFromMailbox added in v0.9.0

func DBRemoveMessagesFromMailbox(ctx context.Context, tx *ent.Tx, messageIDs []string, mboxID string) error

func DBRenameMailbox added in v0.9.0

func DBRenameMailbox(ctx context.Context, tx *ent.Tx, mboxID, name string) error

func DBSetDeletedFlag added in v0.9.0

func DBSetDeletedFlag(ctx context.Context, tx *ent.Tx, mboxID string, messageIDs []string, deleted bool) error

func DBSetMessageFlags added in v0.9.0

func DBSetMessageFlags(ctx context.Context, tx *ent.Tx, messageIDs []string, setFlags imap.FlagSet) error

func DBUpdateMailboxID added in v0.9.0

func DBUpdateMailboxID(ctx context.Context, tx *ent.Tx, oldID, newID string) error

func DBUpdateMessageID added in v0.9.0

func DBUpdateMessageID(ctx context.Context, tx *ent.Tx, oldID, newID string) error

Types

type Backend

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

func New

func New(dir string) (*Backend, error)

func (*Backend) AddUser

func (b *Backend) AddUser(ctx context.Context, userID string, conn connector.Connector, store store.Store, client *ent.Client) error

func (*Backend) Close

func (b *Backend) Close(ctx context.Context) error

func (*Backend) GetState

func (b *Backend) GetState(username, password string, sessionID int) (*State, error)

func (*Backend) NewUserID added in v0.9.0

func (b *Backend) NewUserID() string

func (*Backend) RemoveUser added in v0.5.0

func (b *Backend) RemoveUser(ctx context.Context, userID string) error

func (*Backend) SetDelimiter

func (b *Backend) SetDelimiter(delim string)

type DBCreateMessageReq added in v0.9.0

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

type Mailbox

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

func (*Mailbox) Append

func (m *Mailbox) Append(ctx context.Context, literal []byte, flags imap.FlagSet, date time.Time) (int, error)

func (*Mailbox) Attributes

func (m *Mailbox) Attributes(ctx context.Context) (imap.FlagSet, error)

func (*Mailbox) Close

func (m *Mailbox) Close(ctx context.Context) error

func (*Mailbox) Copy

func (m *Mailbox) Copy(ctx context.Context, seq *proto.SequenceSet, name string) (response.Item, error)

Copy copies the messages represented by the given sequence set into the mailbox with the given name. If the context is a UID context, the sequence set refers to message UIDs. If no items are copied the response object will be nil.

func (*Mailbox) Count

func (m *Mailbox) Count() int

func (*Mailbox) Expunge

func (m *Mailbox) Expunge(ctx context.Context, seq *proto.SequenceSet) error

func (*Mailbox) ExpungeIssued

func (m *Mailbox) ExpungeIssued() bool

func (*Mailbox) Fetch

func (m *Mailbox) Fetch(ctx context.Context, seq *proto.SequenceSet, attributes []*proto.FetchAttribute, ch chan response.Response) error

func (*Mailbox) Flags

func (m *Mailbox) Flags(ctx context.Context) (imap.FlagSet, error)

func (*Mailbox) Flush

func (m *Mailbox) Flush(ctx context.Context, permitExpunge bool) ([]response.Response, error)

func (*Mailbox) GetMessagesWithFlag

func (m *Mailbox) GetMessagesWithFlag(flag string) []int

func (*Mailbox) GetMessagesWithoutFlag

func (m *Mailbox) GetMessagesWithoutFlag(flag string) []int

func (*Mailbox) Move

func (m *Mailbox) Move(ctx context.Context, seq *proto.SequenceSet, name string) (response.Item, error)

Move moves the messages represented by the given sequence set into the mailbox with the given name. If the context is a UID context, the sequence set refers to message UIDs. If no items are moved the response object will be nil.

func (*Mailbox) Name

func (m *Mailbox) Name() string

func (*Mailbox) PermanentFlags

func (m *Mailbox) PermanentFlags(ctx context.Context) (imap.FlagSet, error)

func (*Mailbox) ReadOnly

func (m *Mailbox) ReadOnly() bool

func (*Mailbox) Search

func (m *Mailbox) Search(ctx context.Context, keys []*proto.SearchKey, decoder *encoding.Decoder) ([]int, error)

func (*Mailbox) Selected

func (m *Mailbox) Selected() bool

func (*Mailbox) Store

func (m *Mailbox) Store(ctx context.Context, seq *proto.SequenceSet, operation proto.Operation, flags imap.FlagSet) error

func (*Mailbox) Subscribed

func (m *Mailbox) Subscribed() bool

func (*Mailbox) UIDNext

func (m *Mailbox) UIDNext() int

func (*Mailbox) UIDValidity

func (m *Mailbox) UIDValidity() int

type Match

type Match struct {
	Name      string
	Delimiter string
	Atts      imap.FlagSet
}

type State

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

TODO(REFACTOR): Decide on the best way to pass around user/state/snap objects! Currently quite gross...

func (*State) Close

func (state *State) Close(ctx context.Context) error

func (*State) Create

func (state *State) Create(ctx context.Context, name string) error

func (*State) Delete

func (state *State) Delete(ctx context.Context, name string) error

func (*State) Done added in v0.8.1

func (state *State) Done() <-chan struct{}

func (*State) Examine

func (state *State) Examine(ctx context.Context, name string, fn func(*Mailbox) error) error

func (*State) Idle

func (state *State) Idle(ctx context.Context, fn func([]response.Response, chan response.Response) error) error

func (*State) IsSelected

func (state *State) IsSelected() bool

func (*State) List

func (state *State) List(ctx context.Context, ref, pattern string, subscribed bool, fn func(map[string]Match) error) error

func (*State) Mailbox

func (state *State) Mailbox(ctx context.Context, name string, fn func(*Mailbox) error) error

func (*State) Rename

func (state *State) Rename(ctx context.Context, oldName, newName string) error

func (*State) Select

func (state *State) Select(ctx context.Context, name string, fn func(*Mailbox) error) error

func (*State) Selected

func (state *State) Selected(ctx context.Context, fn func(*Mailbox) error) error

func (*State) SetConnMetadataKeyValue added in v0.8.0

func (state *State) SetConnMetadataKeyValue(key string, value any) error

func (*State) Subscribe

func (state *State) Subscribe(ctx context.Context, name string) error

func (*State) Unsubscribe

func (state *State) Unsubscribe(ctx context.Context, name string) error

func (*State) UserID

func (state *State) UserID() string

Jump to

Keyboard shortcuts

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