imapserver: Don't keep account write-locked during IMAP FETCH command

We effectively held the account write-locked by using a writable transaction
while processing the FETCH command. We did this because we may have to update
\Seen flags, for non-PEEK attribute fetches. This meant other FETCHes would
block, and other write access to the account too.

We now read the messages in a read-only transaction. We gather messages that
need marking as \Seen, and make that change in one (much shorter) database
transaction at the end of the FETCH command.

In practice, it doesn't seem too sensible to mark messages as seen
automatically. Most clients probably use the PEEK-variant of attribute fetches.

Related to issue #128.
This commit is contained in:
Mechiel Lukkien
2025-02-27 09:35:14 +01:00
parent caaace403a
commit b822533df3
4 changed files with 215 additions and 138 deletions

View File

@ -3565,9 +3565,7 @@ func (c *conn) cmdAppend(tag, cmd string, p *parser) {
committed = true
// Fetch pending changes, possibly with new UIDs, so we can apply them before adding our own new UID.
if c.comm != nil {
pendingChanges = c.comm.Get()
}
pendingChanges = c.comm.Get()
// Broadcast the change to other connections.
for _, a := range appends {