mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-06 11:27:18 +00:00
Take care of more TODO flagged code
- Improve TODO comments, mention related issues - Export ErrNotWritable, move it to datastore.go - Improve logging of corrupt mailbox GOB file
This commit is contained in:
@@ -9,8 +9,13 @@ import (
|
||||
"github.com/jhillyerd/go.enmime"
|
||||
)
|
||||
|
||||
// ErrNotExist indicates the requested message does not exist
|
||||
var ErrNotExist = errors.New("Message does not exist")
|
||||
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")
|
||||
)
|
||||
|
||||
// DataStore is an interface to get Mailboxes stored in Inbucket
|
||||
type DataStore interface {
|
||||
|
||||
@@ -3,7 +3,6 @@ package smtpd
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -28,9 +27,6 @@ var (
|
||||
// million index files
|
||||
indexLock = new(sync.RWMutex)
|
||||
|
||||
// TODO Consider moving this to the Message interface
|
||||
errNotWritable = errors.New("Message not writable")
|
||||
|
||||
// countChannel is filled with a sequential numbers (0000..9999), which are
|
||||
// used by generateID() to generate unique message IDs. It's global
|
||||
// because we only want one regardless of the number of DataStore objects
|
||||
@@ -222,17 +218,15 @@ func (mb *FileMailbox) readIndex() error {
|
||||
// Decode gob data
|
||||
dec := gob.NewDecoder(bufio.NewReader(file))
|
||||
for {
|
||||
// TODO Detect EOF
|
||||
msg := new(FileMessage)
|
||||
if err = dec.Decode(msg); err != nil {
|
||||
if err == io.EOF {
|
||||
// It's OK to get an EOF here
|
||||
break
|
||||
}
|
||||
return fmt.Errorf("While decoding message: %v", err)
|
||||
return fmt.Errorf("Corrupt mailbox %q: %v", mb.indexPath, err)
|
||||
}
|
||||
msg.mailbox = mb
|
||||
log.Tracef("Found: %v", msg)
|
||||
mb.messages = append(mb.messages, msg)
|
||||
}
|
||||
|
||||
@@ -339,8 +333,7 @@ func (m *FileMessage) ID() string {
|
||||
return m.Fid
|
||||
}
|
||||
|
||||
// Date returns the date of the Message
|
||||
// TODO Is this the create timestamp, or from the Date header?
|
||||
// Date returns the date/time this Message was received by Inbucket
|
||||
func (m *FileMessage) Date() time.Time {
|
||||
return m.Fdate
|
||||
}
|
||||
@@ -443,7 +436,7 @@ func (m *FileMessage) ReadRaw() (raw *string, err error) {
|
||||
func (m *FileMessage) Append(data []byte) error {
|
||||
// Prevent Appending to a pre-existing Message
|
||||
if !m.writable {
|
||||
return errNotWritable
|
||||
return ErrNotWritable
|
||||
}
|
||||
// Open file for writing if we haven't yet
|
||||
if m.writer == nil {
|
||||
|
||||
@@ -413,8 +413,11 @@ func (ss *Session) dataHandler() {
|
||||
for _, m := range messages {
|
||||
if m != nil {
|
||||
if err := m.Close(); err != nil {
|
||||
// This logic should be updated to report failures
|
||||
// writing the initial message file to the client
|
||||
// after we implement a single-store system (issue
|
||||
// #23)
|
||||
ss.logError("Error: %v while writing message", err)
|
||||
// TODO Report to client?
|
||||
}
|
||||
expReceivedTotal.Add(1)
|
||||
}
|
||||
@@ -437,7 +440,7 @@ func (ss *Session) dataHandler() {
|
||||
ss.send("552 Maximum message size exceeded")
|
||||
ss.logWarn("Max message size exceeded while in DATA")
|
||||
ss.reset()
|
||||
// TODO: Should really cleanup the crap on filesystem...
|
||||
// Should really cleanup the crap on filesystem (after issue #23)
|
||||
return
|
||||
}
|
||||
// Append to message objects
|
||||
@@ -448,7 +451,7 @@ func (ss *Session) dataHandler() {
|
||||
ss.logError("Failed to append to mailbox %v: %v", mailboxes[i], err)
|
||||
ss.send("554 Something went wrong")
|
||||
ss.reset()
|
||||
// TODO: Should really cleanup the crap on filesystem...
|
||||
// Should really cleanup the crap on filesystem (after issue #23)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user