mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-28 22:15:56 +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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user