mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
storage: Message refactoring for #69
- Message interface renamed to StoreMessage - Message.Delete becomes Store.RemoveMessage - Added deleted message tracking to Store stub for #80
This commit is contained in:
@@ -57,17 +57,17 @@ var commands = map[string]bool{
|
||||
|
||||
// Session defines an active POP3 session
|
||||
type Session struct {
|
||||
server *Server // Reference to the server we belong to
|
||||
id int // Session ID number
|
||||
conn net.Conn // Our network connection
|
||||
remoteHost string // IP address of client
|
||||
sendError error // Used to bail out of read loop on send error
|
||||
state State // Current session state
|
||||
reader *bufio.Reader // Buffered reader for our net conn
|
||||
user string // Mailbox name
|
||||
messages []storage.Message // Slice of messages in mailbox
|
||||
retain []bool // Messages to retain upon UPDATE (true=retain)
|
||||
msgCount int // Number of undeleted messages
|
||||
server *Server // Reference to the server we belong to
|
||||
id int // Session ID number
|
||||
conn net.Conn // Our network connection
|
||||
remoteHost string // IP address of client
|
||||
sendError error // Used to bail out of read loop on send error
|
||||
state State // Current session state
|
||||
reader *bufio.Reader // Buffered reader for our net conn
|
||||
user string // Mailbox name
|
||||
messages []storage.StoreMessage // Slice of messages in mailbox
|
||||
retain []bool // Messages to retain upon UPDATE (true=retain)
|
||||
msgCount int // Number of undeleted messages
|
||||
}
|
||||
|
||||
// NewSession creates a new POP3 session
|
||||
@@ -415,7 +415,7 @@ func (ses *Session) transactionHandler(cmd string, args []string) {
|
||||
}
|
||||
|
||||
// Send the contents of the message to the client
|
||||
func (ses *Session) sendMessage(msg storage.Message) {
|
||||
func (ses *Session) sendMessage(msg storage.StoreMessage) {
|
||||
reader, err := msg.RawReader()
|
||||
if err != nil {
|
||||
ses.logError("Failed to read message for RETR command")
|
||||
@@ -448,7 +448,7 @@ func (ses *Session) sendMessage(msg storage.Message) {
|
||||
}
|
||||
|
||||
// Send the headers plus the top N lines to the client
|
||||
func (ses *Session) sendMessageTop(msg storage.Message, lineCount int) {
|
||||
func (ses *Session) sendMessageTop(msg storage.StoreMessage, lineCount int) {
|
||||
reader, err := msg.RawReader()
|
||||
if err != nil {
|
||||
ses.logError("Failed to read message for RETR command")
|
||||
@@ -522,7 +522,7 @@ func (ses *Session) processDeletes() {
|
||||
for i, msg := range ses.messages {
|
||||
if !ses.retain[i] {
|
||||
ses.logTrace("Deleting %v", msg)
|
||||
if err := msg.Delete(); err != nil {
|
||||
if err := ses.server.dataStore.RemoveMessage(ses.user, msg.ID()); err != nil {
|
||||
ses.logWarn("Error deleting %v: %v", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/jhillyerd/inbucket/pkg/config"
|
||||
"github.com/jhillyerd/inbucket/pkg/msghub"
|
||||
"github.com/jhillyerd/inbucket/pkg/storage"
|
||||
"github.com/jhillyerd/inbucket/pkg/test"
|
||||
)
|
||||
|
||||
type scriptStep struct {
|
||||
@@ -25,10 +26,8 @@ type scriptStep struct {
|
||||
|
||||
// Test commands in GREET state
|
||||
func TestGreetState(t *testing.T) {
|
||||
// Setup mock objects
|
||||
mds := &storage.MockDataStore{}
|
||||
|
||||
server, logbuf, teardown := setupSMTPServer(mds)
|
||||
ds := test.NewStore()
|
||||
server, logbuf, teardown := setupSMTPServer(ds)
|
||||
defer teardown()
|
||||
|
||||
// Test out some mangled HELOs
|
||||
@@ -82,10 +81,8 @@ func TestGreetState(t *testing.T) {
|
||||
|
||||
// Test commands in READY state
|
||||
func TestReadyState(t *testing.T) {
|
||||
// Setup mock objects
|
||||
mds := &storage.MockDataStore{}
|
||||
|
||||
server, logbuf, teardown := setupSMTPServer(mds)
|
||||
ds := test.NewStore()
|
||||
server, logbuf, teardown := setupSMTPServer(ds)
|
||||
defer teardown()
|
||||
|
||||
// Test out some mangled READY commands
|
||||
|
||||
Reference in New Issue
Block a user