imapserver: implement UIDONLY extension, RFC 9586

Once clients enable this extension, commands can no longer refer to "message
sequence numbers" (MSNs), but can only refer to messages with UIDs. This means
both sides no longer have to carefully keep their sequence numbers in sync
(error-prone), and don't have to keep track of a mapping of sequence numbers to
UIDs (saves resources).

With UIDONLY enabled, all FETCH responses are replaced with UIDFETCH response.
This commit is contained in:
Mechiel Lukkien
2025-04-11 11:45:49 +02:00
parent 8bab38eac4
commit 507ca73b96
41 changed files with 2405 additions and 1545 deletions

View File

@ -136,6 +136,7 @@ var knownCodes = stringMap(
"INPROGRESS", // ../rfc/9585:104
"BADEVENT", "NOTIFICATIONOVERFLOW", // ../rfc/5465:1023
"SERVERBUG",
"UIDREQUIRED", // ../rfc/9586:136
)
func stringMap(l ...string) map[string]struct{} {
@ -654,14 +655,17 @@ func (c *Conn) xuntagged() Untagged {
w = c.xword()
W = strings.ToUpper(w)
switch W {
case "FETCH":
case "FETCH", "UIDFETCH":
if num == 0 {
c.xerrorf("invalid zero number for untagged fetch response")
}
c.xspace()
r := c.xfetch(num)
attrs := c.xfetch()
c.xcrlf()
return r
if W == "UIDFETCH" {
return UntaggedUIDFetch{num, attrs}
}
return UntaggedFetch{num, attrs}
case "EXPUNGE":
if num == 0 {
@ -691,14 +695,14 @@ func (c *Conn) xuntagged() Untagged {
// ../rfc/3501:4864 ../rfc/9051:6742
// Already parsed: "*" SP nznumber SP "FETCH" SP
func (c *Conn) xfetch(num uint32) UntaggedFetch {
func (c *Conn) xfetch() []FetchAttr {
c.xtake("(")
attrs := []FetchAttr{c.xmsgatt1()}
for c.space() {
attrs = append(attrs, c.xmsgatt1())
}
c.xtake(")")
return UntaggedFetch{num, attrs}
return attrs
}
// ../rfc/9051:6746