Correctly handle LISTMESSAGES and STATUS commands using SeqNum instead of UID

This commit is contained in:
2018-06-28 00:00:44 +01:00
parent 22f6eeacd7
commit 3e5ab5bb0a
5 changed files with 106 additions and 23 deletions

View File

@@ -16,7 +16,8 @@ type MaildirInterface interface {
CreateMaildir(*Maildir) error
FindMaildir(account Account, name string) (Maildir, error)
FindMaildirs(account Account) ([]Maildir, error)
FindMessagesInRange(m Maildir, start, end uint64) ([]Message, error)
FindMessagesInRangeBySeqNum(m Maildir, start, end uint64) ([]Message, error)
CountMessages(m Maildir) uint64
}
type Maildir struct {
@@ -41,6 +42,14 @@ func (m *Maildir) Header(key string) (mail.Header, error) {
return m.filesystem.Header(key)
}
func (m *Maildir) UIDValidity() uint64 {
return m.uids.UIDValidity()
}
func (m *Maildir) NextUID() uint64 {
return m.uids.NextUID()
}
func (c *concrete) CreateMaildir(m *Maildir) error {
if m.directory == "" {
m.directory = c.buildMaildirPath(m.Account, m.Name)
@@ -130,13 +139,14 @@ func (c *concrete) buildMaildirPath(account Account, parts ...string) string {
return filepath.Join(bits...)
}
func (c *concrete) FindMessagesInRange(m Maildir, start, end uint64) ([]Message, error) {
func (c *concrete) FindMessagesInRangeBySeqNum(m Maildir, start, end uint64) ([]Message, error) {
var out []Message
entries := m.uids.EntriesInRange(start, end)
entries := m.uids.EntriesInRangeBySeqNum(start, end)
for _, entry := range entries {
msg := Message{
UID: entry.UID,
SeqNum: entry.SeqNum,
Maildir: m,
Key: entry.Key(),
}
@@ -146,3 +156,7 @@ func (c *concrete) FindMessagesInRange(m Maildir, start, end uint64) ([]Message,
return out, nil
}
func (c *concrete) CountMessages(m Maildir) uint64 {
return m.uids.Count()
}

View File

@@ -13,6 +13,7 @@ type Message struct {
Maildir Maildir // maildir.name
UID uint64
SeqNum uint64
Key string
Data io.ReadCloser
hdrCache mail.Header