aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/seqmap.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/imap/seqmap.go')
-rw-r--r--worker/imap/seqmap.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/worker/imap/seqmap.go b/worker/imap/seqmap.go
new file mode 100644
index 00000000..2752cc87
--- /dev/null
+++ b/worker/imap/seqmap.go
@@ -0,0 +1,48 @@
+package imap
+
+import "sync"
+
+type SeqMap struct {
+ lock sync.Mutex
+ // map of IMAP sequence numbers to message UIDs
+ m map[uint32]uint32
+}
+
+func (s *SeqMap) Size() int {
+ s.lock.Lock()
+ size := len(s.m)
+ s.lock.Unlock()
+ return size
+}
+
+func (s *SeqMap) Get(seqnum uint32) (uint32, bool) {
+ s.lock.Lock()
+ uid, found := s.m[seqnum]
+ s.lock.Unlock()
+ return uid, found
+}
+
+func (s *SeqMap) Put(seqnum, uid uint32) {
+ s.lock.Lock()
+ if s.m == nil {
+ s.m = make(map[uint32]uint32)
+ }
+ s.m[seqnum] = uid
+ s.lock.Unlock()
+}
+
+func (s *SeqMap) Pop(seqnum uint32) (uint32, bool) {
+ s.lock.Lock()
+ uid, found := s.m[seqnum]
+ if found {
+ delete(s.m, seqnum)
+ }
+ s.lock.Unlock()
+ return uid, found
+}
+
+func (s *SeqMap) Clear() {
+ s.lock.Lock()
+ s.m = make(map[uint32]uint32)
+ s.lock.Unlock()
+}