Skip to content

Commit d438f34

Browse files
committed
Introduce a UID type
References: #526
1 parent cde91ed commit d438f34

File tree

16 files changed

+36
-29
lines changed

16 files changed

+36
-29
lines changed

append.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ type AppendOptions struct {
1212

1313
// AppendData is the data returned by an APPEND command.
1414
type AppendData struct {
15-
UID, UIDValidity uint32 // requires UIDPLUS or IMAP4rev2
15+
// requires UIDPLUS or IMAP4rev2
16+
UID UID
17+
UIDValidity uint32
1618
}

imap.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,6 @@ type LiteralReader interface {
100100
io.Reader
101101
Size() int64
102102
}
103+
104+
// UID is a message unique identifier.
105+
type UID uint32

imapclient/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
643643
return nil, fmt.Errorf("in resp-code-apnd: %v", c.dec.Err())
644644
}
645645
if cmd, ok := cmd.(*AppendCommand); ok {
646-
cmd.data.UID = uid
646+
cmd.data.UID = imap.UID(uid)
647647
cmd.data.UIDValidity = uidValidity
648648
}
649649
case "COPYUID":
@@ -765,7 +765,7 @@ func (c *Client) readResponseData(typ string) error {
765765
return c.dec.Err()
766766
}
767767
if cmd := findPendingCmdByType[*SelectCommand](c); cmd != nil {
768-
cmd.data.UIDNext = uidNext
768+
cmd.data.UIDNext = imap.UID(uidNext)
769769
}
770770
case "UIDVALIDITY":
771771
var uidValidity uint32

imapclient/fetch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func (FetchItemDataRFC822Size) fetchItemData() {}
347347

348348
// FetchItemDataUID holds data returned by FETCH UID.
349349
type FetchItemDataUID struct {
350-
UID uint32
350+
UID imap.UID
351351
}
352352

353353
func (FetchItemDataUID) fetchItemData() {}
@@ -387,7 +387,7 @@ type FetchMessageBuffer struct {
387387
Envelope *imap.Envelope
388388
InternalDate time.Time
389389
RFC822Size int64
390-
UID uint32
390+
UID imap.UID
391391
BodyStructure imap.BodyStructure
392392
BodySection map[*imap.FetchItemBodySection][]byte
393393
BinarySection map[*imap.FetchItemBinarySection][]byte
@@ -548,7 +548,7 @@ func (c *Client) handleFetch(seqNum uint32) error {
548548
return dec.Err()
549549
}
550550

551-
item = FetchItemDataUID{UID: uid}
551+
item = FetchItemDataUID{UID: imap.UID(uid)}
552552
case "BODY", "BINARY":
553553
if dec.Special('[') {
554554
var section interface{}

imapclient/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ func readStatusAttVal(dec *imapwire.Decoder, data *imap.StatusData) error {
111111
ok = dec.ExpectNumber(&num)
112112
data.NumMessages = &num
113113
case "UIDNEXT":
114-
ok = dec.ExpectNumber(&data.UIDNext)
114+
var uidNext uint32
115+
ok = dec.ExpectNumber(&uidNext)
116+
data.UIDNext = imap.UID(uidNext)
115117
case "UIDVALIDITY":
116118
ok = dec.ExpectNumber(&data.UIDValidity)
117119
case "UNSEEN":

imapserver/append.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (c *Conn) writeAppendOK(tag string, data *imap.AppendData) error {
9494
enc.Atom(tag).SP().Atom("OK").SP()
9595
if data != nil {
9696
enc.Special('[')
97-
enc.Atom("APPENDUID").SP().Number(data.UIDValidity).SP().Number(data.UID)
97+
enc.Atom("APPENDUID").SP().Number(data.UIDValidity).SP().Number(uint32(data.UID))
9898
enc.Special(']').SP()
9999
}
100100
enc.Text("APPEND completed")

imapserver/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ func (w *UpdateWriter) WriteMailboxFlags(flags []imap.Flag) error {
588588
}
589589

590590
// WriteMessageFlags writes a FETCH response with FLAGS.
591-
func (w *UpdateWriter) WriteMessageFlags(seqNum, uid uint32, flags []imap.Flag) error {
591+
func (w *UpdateWriter) WriteMessageFlags(seqNum uint32, uid imap.UID, flags []imap.Flag) error {
592592
fetchWriter := &FetchWriter{conn: w.conn}
593593
respWriter := fetchWriter.CreateMessage(seqNum)
594594
if uid != 0 {

imapserver/fetch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ func (w *FetchResponseWriter) writeItemSep() {
349349
}
350350

351351
// WriteUID writes the message's UID.
352-
func (w *FetchResponseWriter) WriteUID(uid uint32) {
352+
func (w *FetchResponseWriter) WriteUID(uid imap.UID) {
353353
w.writeItemSep()
354-
w.enc.Atom("UID").SP().Number(uid)
354+
w.enc.Atom("UID").SP().Number(uint32(uid))
355355
}
356356

357357
// WriteFlags writes the message's flags.

imapserver/imapmemserver/mailbox.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Mailbox struct {
2222
name string
2323
subscribed bool
2424
l []*message
25-
uidNext uint32
25+
uidNext imap.UID
2626
}
2727

2828
// NewMailbox creates a new mailbox.
@@ -207,7 +207,7 @@ func (mbox *Mailbox) Expunge(w *imapserver.ExpungeWriter, uids *imap.SeqSet) err
207207
expunged := make(map[*message]struct{})
208208
mbox.mutex.Lock()
209209
for _, msg := range mbox.l {
210-
if uids != nil && !uids.Contains(msg.uid) {
210+
if uids != nil && !uids.Contains(uint32(msg.uid)) {
211211
continue
212212
}
213213
if _, ok := msg.flags[canonicalFlag(imap.FlagDeleted)]; ok {
@@ -335,7 +335,7 @@ func (mbox *MailboxView) Search(numKind imapserver.NumKind, criteria *imap.Searc
335335
case imapserver.NumKindSeq:
336336
num = seqNum
337337
case imapserver.NumKindUID:
338-
num = msg.uid
338+
num = uint32(msg.uid)
339339
}
340340
if num == 0 {
341341
continue
@@ -391,7 +391,7 @@ func (mbox *MailboxView) forEachLocked(numKind imapserver.NumKind, seqSet imap.S
391391
case imapserver.NumKindSeq:
392392
num = mbox.tracker.EncodeSeqNum(seqNum)
393393
case imapserver.NumKindUID:
394-
num = msg.uid
394+
num = uint32(msg.uid)
395395
}
396396
if num == 0 || !seqSet.Contains(num) {
397397
continue
@@ -411,7 +411,7 @@ func (mbox *MailboxView) staticSeqSet(seqSet imap.SeqSet, numKind imapserver.Num
411411
case imapserver.NumKindSeq:
412412
max = uint32(len(mbox.l))
413413
case imapserver.NumKindUID:
414-
max = mbox.uidNext - 1
414+
max = uint32(mbox.uidNext) - 1
415415
}
416416

417417
for i := range seqSet {

imapserver/imapmemserver/message.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
type message struct {
2121
// immutable
22-
uid uint32
22+
uid imap.UID
2323
buf []byte
2424
t time.Time
2525

@@ -245,7 +245,7 @@ func (msg *message) search(seqNum uint32, criteria *imap.SearchCriteria) bool {
245245
}
246246
}
247247
for _, seqSet := range criteria.UID {
248-
if !seqSet.Contains(msg.uid) {
248+
if !seqSet.Contains(uint32(msg.uid)) {
249249
return false
250250
}
251251
}

0 commit comments

Comments
 (0)