Skip to content

Commit dda7e0f

Browse files
committed
imapmemserver: add support for the recent flag
1 parent 991c638 commit dda7e0f

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

imapserver/imapmemserver/mailbox.go

Lines changed: 14 additions & 5 deletions
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
}
@@ -94,10 +98,6 @@ func (mbox *Mailbox) statusDataLocked(options *imap.StatusOptions) *imap.StatusD
9498
size := mbox.sizeLocked()
9599
data.Size = &size
96100
}
97-
if options.NumRecent {
98-
num := uint32(0)
99-
data.NumRecent = &num
100-
}
101101
return &data
102102
}
103103

@@ -146,6 +146,7 @@ func (mbox *Mailbox) appendBytes(buf []byte, options *imap.AppendOptions) *imap.
146146
msg.t = options.Time
147147
}
148148

149+
msg.flags[canonicalFlag("\\Recent")] = struct{}{}
149150
for _, flag := range options.Flags {
150151
msg.flags[canonicalFlag(flag)] = struct{}{}
151152
}
@@ -188,12 +189,14 @@ func (mbox *Mailbox) selectDataLocked() *imap.SelectData {
188189
// TODO: skip if IMAP4rev1 is disabled by the server, or IMAP4rev2 is
189190
// enabled by the client
190191
firstUnseenSeqNum := mbox.firstUnseenSeqNumLocked()
192+
numRecent := mbox.countByFlagLocked("\\Recent")
191193

192194
return &imap.SelectData{
193195
Flags: flags,
194196
PermanentFlags: permanentFlags,
195197
NumMessages: uint32(len(mbox.l)),
196198
FirstUnseenSeqNum: firstUnseenSeqNum,
199+
NumRecent: numRecent,
197200
UIDNext: mbox.uidNext,
198201
UIDValidity: mbox.uidValidity,
199202
}
@@ -283,10 +286,11 @@ func (mbox *Mailbox) expungeLocked(expunged map[*message]struct{}) (seqNums []ui
283286
// NewView creates a new view into this mailbox.
284287
//
285288
// Callers must call MailboxView.Close once they are done with the mailbox view.
286-
func (mbox *Mailbox) NewView() *MailboxView {
289+
func (mbox *Mailbox) NewView(options *imap.SelectOptions) *MailboxView {
287290
return &MailboxView{
288291
Mailbox: mbox,
289292
tracker: mbox.tracker.NewSession(),
293+
options: *options,
290294
}
291295
}
292296

@@ -300,6 +304,7 @@ func (mbox *Mailbox) NewView() *MailboxView {
300304
// selected state.
301305
type MailboxView struct {
302306
*Mailbox
307+
options imap.SelectOptions // immutable
303308
tracker *imapserver.SessionTracker
304309
searchRes imap.UIDSet
305310
}
@@ -331,6 +336,10 @@ func (mbox *MailboxView) Fetch(w *imapserver.FetchWriter, numSet imap.NumSet, op
331336

332337
respWriter := w.CreateMessage(mbox.tracker.EncodeSeqNum(seqNum))
333338
err = msg.fetch(respWriter, options)
339+
340+
if !mbox.options.ReadOnly {
341+
delete(msg.flags, canonicalFlag("\\Recent"))
342+
}
334343
})
335344
return err
336345
}

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)