mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Fix some null pointers during message retrieval
This commit is contained in:
@@ -112,7 +112,7 @@ func (s *StoreManager) GetMetadata(mailbox string) ([]*Metadata, error) {
|
||||
// GetMessage returns the specified message.
|
||||
func (s *StoreManager) GetMessage(mailbox, id string) (*Message, error) {
|
||||
sm, err := s.Store.GetMessage(mailbox, id)
|
||||
if err != nil {
|
||||
if err != nil || sm == nil {
|
||||
return nil, err
|
||||
}
|
||||
r, err := sm.Source()
|
||||
@@ -148,7 +148,7 @@ func (s *StoreManager) RemoveMessage(mailbox, id string) error {
|
||||
// SourceReader allows the stored message source to be read.
|
||||
func (s *StoreManager) SourceReader(mailbox, id string) (io.ReadCloser, error) {
|
||||
sm, err := s.Store.GetMessage(mailbox, id)
|
||||
if err != nil {
|
||||
if err != nil || sm == nil {
|
||||
return nil, err
|
||||
}
|
||||
return sm.Source()
|
||||
|
||||
@@ -53,14 +53,13 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (
|
||||
return err
|
||||
}
|
||||
msg, err := ctx.Manager.GetMessage(name, id)
|
||||
if err == storage.ErrNotExist {
|
||||
if err != nil && err != storage.ErrNotExist {
|
||||
return fmt.Errorf("GetMessage(%q) failed: %v", id, err)
|
||||
}
|
||||
if msg == nil {
|
||||
http.NotFound(w, req)
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
// This doesn't indicate empty, likely an IO error
|
||||
return fmt.Errorf("GetMessage(%q) failed: %v", id, err)
|
||||
}
|
||||
attachParts := msg.Attachments()
|
||||
attachments := make([]*model.JSONMessageAttachmentV1, len(attachParts))
|
||||
for i, part := range attachParts {
|
||||
@@ -146,14 +145,13 @@ func MailboxSourceV1(w http.ResponseWriter, req *http.Request, ctx *web.Context)
|
||||
return err
|
||||
}
|
||||
r, err := ctx.Manager.SourceReader(name, id)
|
||||
if err == storage.ErrNotExist {
|
||||
if err != nil && err != storage.ErrNotExist {
|
||||
return fmt.Errorf("SourceReader(%q) failed: %v", id, err)
|
||||
}
|
||||
if r == nil {
|
||||
http.NotFound(w, req)
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
// This doesn't indicate missing, likely an IO error
|
||||
return fmt.Errorf("SourceReader(%q) failed: %v", id, err)
|
||||
}
|
||||
// Output message source
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
_, err = io.Copy(w, r)
|
||||
|
||||
@@ -93,7 +93,11 @@ func (s *Store) AddMessage(message storage.Message) (id string, err error) {
|
||||
// GetMessage gets a mesage.
|
||||
func (s *Store) GetMessage(mailbox, id string) (m storage.Message, err error) {
|
||||
s.withMailbox(mailbox, false, func(mb *mbox) {
|
||||
m = mb.messages[id]
|
||||
var ok bool
|
||||
m, ok = mb.messages[id]
|
||||
if !ok {
|
||||
m = nil
|
||||
}
|
||||
})
|
||||
return m, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user