storage

package
v0.0.0-...-30e5c69 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 12 Imported by: 0

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 Mailbox

type Mailbox interface {
	ID() string
}

type Mailhost

type Mailhost interface {
	ID() string
}

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
	//mailbox
	AddAllowedMailbox(string) error
	RemoveAllowedMailbox(string) error
	KeepaliveAllowedMailbox(string) error
	IsMailboxAllow(string, time.Duration) bool
	CleanupExpiredMailbox(period time.Duration) int
	//mailhost
	AddAllowedMailhost(host string, weight int) error
	RemoveAllowedMailhost(id string) error
	UpdateMailhost(id string, host string, weight int) error
	ListMailhost() []Mailhost
}

Store is the interface TempMail 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
* ===================================================================================== * * Package: mongo * Filename: ${FILENAME} * * Description: tempmail * * Created: 9/23/18 9:25 AM * * Author: hacklog * URL: http://80x86.io * * =====================================================================================
* ===================================================================================== * * Package: mongo * Filename: ${FILENAME} * * Description: tempmail * * Created: 9/23/18 9:25 AM * * Author: hacklog * URL: http://80x86.io * * =====================================================================================

Jump to

Keyboard shortcuts

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