Skip to content

Commit b8c5b81

Browse files
committed
imapmemserver: add support for the recent flag
1 parent b3805e6 commit b8c5b81

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

imapserver/imapmemserver/mailbox.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (mbox *Mailbox) statusDataLocked(options *imap.StatusOptions) *imap.StatusD
7676
num := uint32(len(mbox.l))
7777
data.NumMessages = &num
7878
}
79+
if options.NumRecent {
80+
num := mbox.countByFlagLocked("\\Recent")
81+
data.NumRecent = &num
82+
}
7983
if options.UIDNext {
8084
data.UIDNext = mbox.uidNext
8185
}
@@ -142,6 +146,7 @@ func (mbox *Mailbox) appendBytes(buf []byte, options *imap.AppendOptions) *imap.
142146
msg.t = options.Time
143147
}
144148

149+
msg.flags[canonicalFlag("\\Recent")] = struct{}{}
145150
for _, flag := range options.Flags {
146151
msg.flags[canonicalFlag(flag)] = struct{}{}
147152
}
@@ -184,12 +189,14 @@ func (mbox *Mailbox) selectDataLocked() *imap.SelectData {
184189
// TODO: skip if IMAP4rev1 is disabled by the server, or IMAP4rev2 is
185190
// enabled by the client
186191
firstUnseenSeqNum := mbox.firstUnseenSeqNumLocked()
192+
numRecent := mbox.countByFlagLocked("\\Recent")
187193

188194
return &imap.SelectData{
189195
Flags: flags,
190196
PermanentFlags: permanentFlags,
191197
NumMessages: uint32(len(mbox.l)),
192198
FirstUnseenSeqNum: firstUnseenSeqNum,
199+
NumRecent: numRecent,
193200
UIDNext: mbox.uidNext,
194201
UIDValidity: mbox.uidValidity,
195202
}
@@ -279,10 +286,11 @@ func (mbox *Mailbox) expungeLocked(expunged map[*message]struct{}) (seqNums []ui
279286
// NewView creates a new view into this mailbox.
280287
//
281288
// Callers must call MailboxView.Close once they are done with the mailbox view.
282-
func (mbox *Mailbox) NewView() *MailboxView {
289+
func (mbox *Mailbox) NewView(options *imap.SelectOptions) *MailboxView {
283290
return &MailboxView{
284291
Mailbox: mbox,
285292
tracker: mbox.tracker.NewSession(),
293+
options: *options,
286294
}
287295
}
288296

@@ -296,6 +304,7 @@ func (mbox *Mailbox) NewView() *MailboxView {
296304
// selected state.
297305
type MailboxView struct {
298306
*Mailbox
307+
options imap.SelectOptions // immutable
299308
tracker *imapserver.SessionTracker
300309
searchRes imap.UIDSet
301310
}
@@ -327,6 +336,10 @@ func (mbox *MailboxView) Fetch(w *imapserver.FetchWriter, numSet imap.NumSet, op
327336

328337
respWriter := w.CreateMessage(mbox.tracker.EncodeSeqNum(seqNum))
329338
err = msg.fetch(respWriter, options)
339+
340+
if !mbox.options.ReadOnly {
341+
delete(msg.flags, canonicalFlag("\\Recent"))
342+
}
330343
})
331344
return err
332345
}

imapserver/imapmemserver/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (sess *UserSession) Select(name string, options *imap.SelectOptions) (*imap
4040
}
4141
mbox.mutex.Lock()
4242
defer mbox.mutex.Unlock()
43-
sess.mailbox = mbox.NewView()
43+
sess.mailbox = mbox.NewView(options)
4444
return mbox.selectDataLocked(), nil
4545
}
4646

0 commit comments

Comments
 (0)