1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00
Files
go-inbucket/pkg/storage/storage.go
James Hillyerd 10bc07a18e message: Implement service layer, stubs for #81
I've made some effort to wire the manager into the controllers, but
tests are currently failing.
2018-03-12 20:21:59 -07:00

51 lines
1.4 KiB
Go

// Package storage contains implementation independent datastore logic
package storage
import (
"errors"
"io"
"net/mail"
"sync"
"time"
"github.com/jhillyerd/enmime"
)
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")
)
// Store is the interface Inbucket uses to interact with storage implementations.
type Store interface {
GetMessage(mailbox, id string) (StoreMessage, error)
GetMessages(mailbox string) ([]StoreMessage, error)
PurgeMessages(mailbox string) error
RemoveMessage(mailbox, id string) error
VisitMailboxes(f func([]StoreMessage) (cont bool)) error
// LockFor is a temporary hack to fix #77 until Datastore revamp
LockFor(emailAddress string) (*sync.RWMutex, error)
// NewMessage is temproary until #69 MessageData refactor
NewMessage(mailbox string) (StoreMessage, error)
}
// StoreMessage represents a message to be stored, or returned from a storage implementation.
type StoreMessage interface {
Mailbox() string
ID() string
From() *mail.Address
To() []*mail.Address
Date() time.Time
Subject() string
RawReader() (reader io.ReadCloser, err error)
ReadBody() (body *enmime.Envelope, err error)
ReadRaw() (raw *string, err error)
Append(data []byte) error
Close() error
String() string
Size() int64
}