Merge pull request #180 from joaoppa/fix/165-imap-release-mailbox

fix: release the selected IMAP mailbox before the LIST-STATUS poll so live sync keeps detecting new mail on Dovecot
This commit is contained in:
Matthew Meszaros
2026-08-24 20:06:53 -07:00
committed by GitHub
2 changed files with 14 additions and 0 deletions
+3
View File
@@ -33,6 +33,9 @@ func (w *WMail) Sync(ctx context.Context) *errx.MailError {
stats := &tickStats{}
client := w.SmtpImapData.ImapClient
// A mailbox left selected by the previous pass freezes LIST-STATUS on this
// connection, so release it before asking what changed.
client.ReleaseMailbox()
folders, err := client.Folders()
if err != nil {
return err
+11
View File
@@ -193,6 +193,17 @@ func (c *Client) SelectForSync(mailbox string) (uint32, *errx.MailError) {
return data.NumMessages, nil
}
// ReleaseMailbox drops the selected mailbox. Dovecot answers LIST-STATUS for
// the selected mailbox with the values it held at SELECT, so a loop that keeps
// INBOX selected never sees another change land. Servers without UNSELECT keep
// the previous behaviour.
func (c *Client) ReleaseMailbox() {
if c.client == nil || !c.client.Caps().Has(imap.CapUnselect) {
return
}
_ = c.client.Unselect().Wait()
}
// Fetched is one message's envelope as read by FetchEnvelopes, plus what
// FetchBody needs to read its text parts later. Bodies are deliberately a
// second step: the sync loop decides per message whether it is new and