mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
storage: Eliminate storage.Mailbox interface for #69
storage/file Mailbox has been renamed mbox, and is now just an implementation detail.
This commit is contained in:
@@ -65,7 +65,6 @@ type Session struct {
|
||||
state State // Current session state
|
||||
reader *bufio.Reader // Buffered reader for our net conn
|
||||
user string // Mailbox name
|
||||
mailbox storage.Mailbox // Mailbox instance
|
||||
messages []storage.Message // Slice of messages in mailbox
|
||||
retain []bool // Messages to retain upon UPDATE (true=retain)
|
||||
msgCount int // Number of undeleted messages
|
||||
@@ -195,14 +194,6 @@ func (ses *Session) authorizationHandler(cmd string, args []string) {
|
||||
if ses.user == "" {
|
||||
ses.ooSeq(cmd)
|
||||
} else {
|
||||
var err error
|
||||
ses.mailbox, err = ses.server.dataStore.MailboxFor(ses.user)
|
||||
if err != nil {
|
||||
ses.logError("Failed to open mailbox for %v", ses.user)
|
||||
ses.send(fmt.Sprintf("-ERR Failed to open mailbox for %v", ses.user))
|
||||
ses.enterState(QUIT)
|
||||
return
|
||||
}
|
||||
ses.loadMailbox()
|
||||
ses.send(fmt.Sprintf("+OK Found %v messages for %v", ses.msgCount, ses.user))
|
||||
ses.enterState(TRANSACTION)
|
||||
@@ -214,14 +205,6 @@ func (ses *Session) authorizationHandler(cmd string, args []string) {
|
||||
return
|
||||
}
|
||||
ses.user = args[0]
|
||||
var err error
|
||||
ses.mailbox, err = ses.server.dataStore.MailboxFor(ses.user)
|
||||
if err != nil {
|
||||
ses.logError("Failed to open mailbox for %v", ses.user)
|
||||
ses.send(fmt.Sprintf("-ERR Failed to open mailbox for %v", ses.user))
|
||||
ses.enterState(QUIT)
|
||||
return
|
||||
}
|
||||
ses.loadMailbox()
|
||||
ses.send(fmt.Sprintf("+OK Found %v messages for %v", ses.msgCount, ses.user))
|
||||
ses.enterState(TRANSACTION)
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
|
||||
"github.com/jhillyerd/inbucket/pkg/log"
|
||||
"github.com/jhillyerd/inbucket/pkg/msghub"
|
||||
"github.com/jhillyerd/inbucket/pkg/storage"
|
||||
"github.com/jhillyerd/inbucket/pkg/stringutil"
|
||||
)
|
||||
|
||||
@@ -73,7 +72,6 @@ var commands = map[string]bool{
|
||||
// recipientDetails for message delivery
|
||||
type recipientDetails struct {
|
||||
address, localPart, domainPart string
|
||||
mailbox storage.Mailbox
|
||||
}
|
||||
|
||||
// Session holds the state of an SMTP session
|
||||
@@ -365,14 +363,7 @@ func (ss *Session) dataHandler() {
|
||||
}
|
||||
if strings.ToLower(domain) != ss.server.domainNoStore {
|
||||
// Not our "no store" domain, so store the message
|
||||
mb, err := ss.server.dataStore.MailboxFor(local)
|
||||
if err != nil {
|
||||
ss.logError("Failed to open mailbox for %q: %s", local, err)
|
||||
ss.send(fmt.Sprintf("451 Failed to open mailbox for %v", local))
|
||||
ss.reset()
|
||||
return
|
||||
}
|
||||
recipients = append(recipients, recipientDetails{recip, local, domain, mb})
|
||||
recipients = append(recipients, recipientDetails{recip, local, domain})
|
||||
} else {
|
||||
log.Tracef("Not storing message for %q", recip)
|
||||
}
|
||||
@@ -469,13 +460,13 @@ func (ss *Session) deliverMessage(r recipientDetails, msgBuf [][]byte) (ok bool)
|
||||
// Append lines from msgBuf
|
||||
for _, line := range msgBuf {
|
||||
if err := msg.Append(line); err != nil {
|
||||
ss.logError("Failed to append to mailbox %v: %v", r.mailbox, err)
|
||||
ss.logError("Failed to append to mailbox %v: %v", r.localPart, err)
|
||||
// Should really cleanup the crap on filesystem
|
||||
return false
|
||||
}
|
||||
}
|
||||
if err := msg.Close(); err != nil {
|
||||
ss.logError("Error while closing message for %v: %v", r.mailbox, err)
|
||||
ss.logError("Error while closing message for %v: %v", r.localPart, err)
|
||||
return false
|
||||
}
|
||||
name, err := stringutil.ParseMailboxName(r.localPart)
|
||||
|
||||
@@ -145,11 +145,8 @@ func TestReadyState(t *testing.T) {
|
||||
func TestMailState(t *testing.T) {
|
||||
// Setup mock objects
|
||||
mds := &storage.MockDataStore{}
|
||||
mb1 := &storage.MockMailbox{}
|
||||
msg1 := &storage.MockMessage{}
|
||||
mds.On("MailboxFor", "u1").Return(mb1, nil)
|
||||
mds.On("NewMessage", "u1").Return(msg1, nil)
|
||||
mb1.On("Name").Return("u1")
|
||||
msg1.On("ID").Return("")
|
||||
msg1.On("From").Return("")
|
||||
msg1.On("To").Return(make([]string, 0))
|
||||
@@ -260,11 +257,8 @@ func TestMailState(t *testing.T) {
|
||||
func TestDataState(t *testing.T) {
|
||||
// Setup mock objects
|
||||
mds := &storage.MockDataStore{}
|
||||
mb1 := &storage.MockMailbox{}
|
||||
msg1 := &storage.MockMessage{}
|
||||
mds.On("MailboxFor", "u1").Return(mb1, nil)
|
||||
mds.On("NewMessage", "u1").Return(msg1, nil)
|
||||
mb1.On("Name").Return("u1")
|
||||
msg1.On("ID").Return("")
|
||||
msg1.On("From").Return("")
|
||||
msg1.On("To").Return(make([]string, 0))
|
||||
|
||||
Reference in New Issue
Block a user