emersion / go-imap

📥 An IMAP library for clients and servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider adding seq num and UID sub-types for SeqSet

emersion opened this issue · comments

This would make it more difficult to mix UIDs and seq nums by mistake, and would remove all of the UID* methods.

We could instead add a Kind = UID/Num field to SeqSet without introducing a new type. Callers would always need to specify the kind when creating a new SeqSet, but the two kinds would not be different from the point-of-view of the type system. Most IMAP commands accept both UIDs and sequence numbers, with the exception of EXPUNGE which always requires UIDs.

OTOH, if we have separate types, we can also have separate types for single UID/SeqNum values, and prevent users from mixing these up.

With full types, would probably look like:

type UID uint32
// no separate type for sequence numbers, since these are often mixed with
// number of messages

type NumSet interface {
	isNumSet()
}

type UIDSet []UIDRange
type SeqSet []SeqRange

func (UIDSet) isNumSet() {}
func (SeqSet) isNumSet() {}

type UIDRange struct {
	Start, Stop UID
}
type SeqRange struct {
	Start, Stop uint32
}