imapserver: only send OLDNAME in LIST responses when IMAP4rev2 was enabled

OLDNAME is included in IMAP4rev2, but not in IMAP4rev1. it is also included in
the NOTIFY extension, but we don't implement that yet.

found by Damian Poddebniak with https://github.com/duesee/imap-flow, thanks!
This commit is contained in:
Mechiel Lukkien
2023-12-14 20:09:13 +01:00
parent fbc18d522d
commit 41e3d1af10
3 changed files with 26 additions and 9 deletions

View File

@ -1311,7 +1311,12 @@ func (c *conn) applyChanges(changes []store.Change, initial bool) {
case store.ChangeAddMailbox:
c.bwritelinef(`* LIST (%s) "/" %s`, strings.Join(ch.Flags, " "), astring(ch.Mailbox.Name).pack(c))
case store.ChangeRenameMailbox:
c.bwritelinef(`* LIST (%s) "/" %s ("OLDNAME" (%s))`, strings.Join(ch.Flags, " "), astring(ch.NewName).pack(c), string0(ch.OldName).pack(c))
// OLDNAME only with IMAP4rev2 or NOTIFY ../rfc/9051:2726 ../rfc/5465:628
var oldname string
if c.enabled[capIMAP4rev2] {
oldname = fmt.Sprintf(` ("OLDNAME" (%s))`, string0(ch.OldName).pack(c))
}
c.bwritelinef(`* LIST (%s) "/" %s%s`, strings.Join(ch.Flags, " "), astring(ch.NewName).pack(c), oldname)
case store.ChangeAddSubscription:
c.bwritelinef(`* LIST (%s) "/" %s`, strings.Join(append([]string{`\Subscribed`}, ch.Flags...), " "), astring(ch.Name).pack(c))
default:
@ -2211,11 +2216,12 @@ func (c *conn) cmdCreate(tag, cmd string, p *parser) {
})
for _, n := range created {
var more string
if n == name && name != origName && !(name == "Inbox" || strings.HasPrefix(name, "Inbox/")) {
more = fmt.Sprintf(` ("OLDNAME" (%s))`, string0(origName).pack(c))
var oldname string
// OLDNAME only with IMAP4rev2 or NOTIFY ../rfc/9051:2726 ../rfc/5465:628
if c.enabled[capIMAP4rev2] && n == name && name != origName && !(name == "Inbox" || strings.HasPrefix(name, "Inbox/")) {
oldname = fmt.Sprintf(` ("OLDNAME" (%s))`, string0(origName).pack(c))
}
c.bwritelinef(`* LIST (\Subscribed) "/" %s%s`, astring(n).pack(c), more)
c.bwritelinef(`* LIST (\Subscribed) "/" %s%s`, astring(n).pack(c), oldname)
}
c.ok(tag, cmd)
}