storage

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: MIT Imports: 12 Imported by: 16

Documentation

Overview

Package storage contains implementation independent datastore logic

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist indicates the requested message does not exist.
	ErrNotExist = errors.New("message does not exist")

	// ErrNotWritable indicates the message is closed; no longer writable
	ErrNotWritable = errors.New("Message not writable")

	// Constructors tracks registered storage constructors
	Constructors = make(map[string]func(config.Storage) (Store, error))
)

Functions

This section is empty.

Types

type HashLock

type HashLock [4096]sync.RWMutex

HashLock holds a fixed length array of mutexes. This approach allows concurrent mailbox access in most cases without requiring an infinite number of mutexes.

func (*HashLock) Get

func (h *HashLock) Get(hash string) *sync.RWMutex

Get returns a RWMutex based on the first 12 bits of the mailbox hash. Hash must be a hexidecimal string of three or more characters.

type Message

type Message interface {
	Mailbox() string
	ID() string
	From() *mail.Address
	To() []*mail.Address
	Date() time.Time
	Subject() string
	Source() (io.ReadCloser, error)
	Size() int64
	Seen() bool
}

Message represents a message to be stored, or returned from a storage implementation.

type RetentionScanner

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

RetentionScanner looks for messages older than the configured retention period and deletes them.

func NewRetentionScanner

func NewRetentionScanner(
	cfg config.Storage,
	ds Store,
	shutdownChannel chan bool,
) *RetentionScanner

NewRetentionScanner configures a new RententionScanner.

func (*RetentionScanner) DoScan

func (rs *RetentionScanner) DoScan() error

DoScan does a single pass of all mailboxes looking for messages that can be purged.

func (*RetentionScanner) Join

func (rs *RetentionScanner) Join()

Join does not return until the retention scanner has shut down.

func (*RetentionScanner) Start

func (rs *RetentionScanner) Start()

Start up the retention scanner if retention period > 0

type Store

type Store interface {
	// AddMessage stores the message, message ID and Size will be ignored.
	AddMessage(message Message) (id string, err error)
	GetMessage(mailbox, id string) (Message, error)
	GetMessages(mailbox string) ([]Message, error)
	MarkSeen(mailbox, id string) error
	PurgeMessages(mailbox string) error
	RemoveMessage(mailbox, id string) error
	VisitMailboxes(f func([]Message) (cont bool)) error
}

Store is the interface Inbucket uses to interact with storage implementations.

func FromConfig

func FromConfig(c config.Storage) (store Store, err error)

FromConfig creates an instance of the Store based on the provided configuration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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