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

@@ -7,8 +7,10 @@ import (
)
type Entry struct {
UID uint64
Extra map[string][]string
UID uint64
SeqNum uint64
Extra map[string][]string
LastKnownFilename string
}

View File

@@ -83,6 +83,12 @@ func handleFile(filename string, flags int) (*List, error) {
}, nil
}
func (l *List) NextUID() uint64 {
l.mutex.Lock()
defer l.mutex.Unlock()
return l.header.NextUID
}
func (l *List) UIDValidity() uint64 {
return l.header.UIDValidity
}
@@ -95,11 +101,35 @@ func (l *List) Entries() []Entry {
l.mutex.Lock()
defer l.mutex.Unlock()
// FIXME: use copy() ?
return l.entries
}
func (l *List) EntriesInRange(start, end uint64) []Entry {
func (l *List) EntriesInRangeBySeqNum(start, end uint64) []Entry {
l.mutex.Lock()
defer l.mutex.Unlock()
// IMAP SeqNums are indexed from 1. So 0 should be invalid, right?
if start == 0 {
return nil
}
start--
if int(start) > len(l.entries) {
return nil
}
if end == 0 {
return l.entries[start:]
}
if int(end) > len(l.entries) {
end = uint64(len(l.entries))
}
return l.entries[start:end]
}
func (l *List) EntriesInRangeByUID(start, end uint64) []Entry {
l.mutex.Lock()
defer l.mutex.Unlock()
@@ -124,6 +154,13 @@ func (l *List) Entry(key string) *Entry {
return nil
}
func (l *List) Count() uint64 {
l.mutex.Lock()
defer l.mutex.Unlock()
return uint64(len(l.entries))
}
func (l *List) Append(filenames ...string) error {
l.mutex.Lock()
defer l.mutex.Unlock()