1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

storage: Add test for id='latest', implment in mem store.

This commit is contained in:
James Hillyerd
2018-10-22 15:43:17 -07:00
parent 2f67a6922a
commit 8a3d2ff6a2
2 changed files with 36 additions and 1 deletions

View File

@@ -92,6 +92,17 @@ 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) {
if id == "latest" {
ms, err := s.GetMessages(mailbox)
if err != nil {
return nil, err
}
count := len(ms)
if count == 0 {
return nil, nil
}
return ms[count-1], nil
}
s.withMailbox(mailbox, false, func(mb *mbox) {
var ok bool
m, ok = mb.messages[id]