Skip to content

Commit

Permalink
imapserver: add FLAGS unilateral update
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Apr 3, 2023
1 parent 63b29fb commit 84a2562
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions imapserver/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ func (w *UpdateWriter) WriteNumMessages(n uint32) error {
return w.conn.writeExists(n)
}

// WriteMailboxFlags writes a FLAGS response.
func (w *UpdateWriter) WriteMailboxFlags(flags []imap.Flag) error {
return w.conn.writeFlags(flags)
}

// WriteMessageFlags writes a FETCH response with FLAGS.
func (w *UpdateWriter) WriteMessageFlags(seqNum, uid uint32, flags []imap.Flag) error {
fetchWriter := &FetchWriter{conn: w.conn}
Expand Down
17 changes: 14 additions & 3 deletions imapserver/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ func (t *MailboxTracker) QueueNumMessages(n uint32) {
t.queueUpdate(&trackerUpdate{numMessages: n}, nil)
}

// QueueMailboxFlags queues a new FLAGS update.
func (t *MailboxTracker) QueueMailboxFlags(flags []imap.Flag) {
if flags == nil {
flags = []imap.Flag{}
}
t.queueUpdate(&trackerUpdate{mailboxFlags: flags}, nil)
}

// QueueMessageFlags queues a new FETCH FLAGS update.
//
// If source is not nil, the update won't be dispatched to it.
Expand All @@ -90,9 +98,10 @@ func (t *MailboxTracker) QueueMessageFlags(seqNum, uid uint32, flags []imap.Flag
}

type trackerUpdate struct {
expunge uint32
numMessages uint32
fetch *trackerUpdateFetch
expunge uint32
numMessages uint32
mailboxFlags []imap.Flag
fetch *trackerUpdateFetch
}

type trackerUpdateFetch struct {
Expand Down Expand Up @@ -166,6 +175,8 @@ func (t *SessionTracker) Poll(w *UpdateWriter, allowExpunge bool) error {
err = w.WriteExpunge(update.expunge)
case update.numMessages != 0:
err = w.WriteNumMessages(update.numMessages)
case update.mailboxFlags != nil:
err = w.WriteMailboxFlags(update.mailboxFlags)
case update.fetch != nil:
err = w.WriteMessageFlags(update.fetch.seqNum, update.fetch.uid, update.fetch.flags)
default:
Expand Down

0 comments on commit 84a2562

Please sign in to comment.