mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-03-08 00:55:57 +00:00
storage: Move NewMessage() into Store interface for #69
This commit is contained in:
@@ -175,6 +175,15 @@ func (fs *Store) LockFor(emailAddress string) (*sync.RWMutex, error) {
|
||||
return fs.hashLock.Get(hash), nil
|
||||
}
|
||||
|
||||
// NewMessage is temproary until #69 MessageData refactor
|
||||
func (fs *Store) NewMessage(mailbox string) (storage.Message, error) {
|
||||
mb, err := fs.MailboxFor(mailbox)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mb.(*Mailbox).NewMessage()
|
||||
}
|
||||
|
||||
// Mailbox implements Mailbox, manages the mail for a specific user and
|
||||
// correlates to a particular directory on disk.
|
||||
type Mailbox struct {
|
||||
|
||||
@@ -490,13 +490,9 @@ func deliverMessage(ds *Store, mbName string, subject string,
|
||||
testMsg = append(testMsg, []byte("\r\n")...)
|
||||
testMsg = append(testMsg, []byte("Test Body\r\n")...)
|
||||
|
||||
mb, err := ds.MailboxFor(mbName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Create message object
|
||||
id = generateID(date)
|
||||
msg, err := mb.NewMessage()
|
||||
msg, err := ds.NewMessage(mbName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -28,12 +28,13 @@ type Store interface {
|
||||
MailboxFor(emailAddress string) (Mailbox, 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) (Message, error)
|
||||
}
|
||||
|
||||
// Mailbox is an interface to get and manipulate messages in a DataStore
|
||||
type Mailbox interface {
|
||||
GetMessages() ([]Message, error)
|
||||
NewMessage() (Message, error)
|
||||
String() string
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,12 @@ func (m *MockDataStore) LockFor(name string) (*sync.RWMutex, error) {
|
||||
return &sync.RWMutex{}, nil
|
||||
}
|
||||
|
||||
// NewMessage temporary for #69
|
||||
func (m *MockDataStore) NewMessage(mailbox string) (Message, error) {
|
||||
args := m.Called(mailbox)
|
||||
return args.Get(0).(Message), args.Error(1)
|
||||
}
|
||||
|
||||
// VisitMailboxes accepts a function that will be called with the messages in each mailbox while it
|
||||
// continues to return true.
|
||||
func (m *MockDataStore) VisitMailboxes(f func([]Message) (cont bool)) error {
|
||||
|
||||
Reference in New Issue
Block a user