Closed Bug 2083049 Opened 1 month ago Closed 12 days ago

Exchange: a rebuilt folder database (deleted .msf, Repair Folder) leaves the folder permanently empty: sync token kept, and maildirValid never set

Categories

(MailNews Core :: Networking: Exchange, defect)

Thunderbird 158
defect

Tracking

(Not tracked)

RESOLVED FIXED
162 Branch

People

(Reporter: btirmarche, Assigned: btirmarche)

Details

Attachments

(1 file, 1 external file)

Thunderbird 158, Exchange (EWS) account, maildir store, some messages downloaded for offline use.

Steps: quit Thunderbird, delete the Inbox .msf (or use Repair Folder), then restart.

Actual: the Inbox stays empty for good, with no error. The folder's ewsSyncStateToken survives in folderCache.json, so the next sync only asks for changes. If the token is removed by hand, the folder resyncs fully, but it is empty again after the next restart: the rebuilt .msf has no maildirValid (the original one had it).

Cause:

  • nsMsgMaildirStore::IsSummaryFileValid requires maildirValid in dbFolderInfo once cur/ holds messages. For Exchange folders, that flag is set at folder creation and as a side effect of nsMailDatabase::DeleteMessages, but never on a database created by ExchangeFolder::GetDatabase → CreateNewDB.
  • On the next open, the summary is reported out of date and deleted, and GetDatabase silently creates another empty database. Meanwhile the sync token is kept, so the folder never fills again.

Patch: when GetDatabase falls back to CreateNewDB, clear ewsSyncStateToken (forcing a full resync), call SetSummaryValid(true) and commit, and log the rebuild. Test: test_rebuiltDatabaseResync.js (maildir and mbox).

Built and tested locally (macOS, mozilla-central of 2026-10-16 + comm-central d438ab08ff66): the test passes, and fails without the fix ("the sync state should have been reset along with the database"). Exchange unit tests 30/30, lint clean on the changed lines.

Known follow-ups: a rebuild resync treats every message as new (filters, junk classification and notifications run again), and with maildir the old offline files are left orphaned in cur/.

See also bug 1967333.

Proposed fix, includes test_rebuiltDatabaseResync.js (built and tested locally, see the description).

Justin - is your in-progress sync token work going to handle this case?

Flags: needinfo?(jtracey)

Nope, this is an EWS (and Graph, presumably) bug, the patch I'm working on only affects Graph. I can take it on since it's also touching sync state token problems.

Benoit: Our Phabricator instance we normally use for code review isn't publicly accessible right now, but should be in the next week or so. Would you like to submit this your patch there once it's back, and go through the review process, or would you prefer to just treat it as part of the bug report and let me take over the fix?

Flags: needinfo?(jtracey) → needinfo?(benoit)
Assignee: nobody → jtracey
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true

Thanks Justin! I'd like to take care of it. Phabricator is reachable for me now, so I'll submit the patch there shortly and go through the review process.

Flags: needinfo?(benoit)

When OpenFolderDB() fails, ExchangeFolder::GetDatabase() creates an empty
database but used to keep the folder's ewsSyncStateToken, so the next sync only
fetched changes and the folder stayed empty. It also never marked the new
summary valid, so with maildir the rebuilt database was discarded again on the
next startup.

Clear the sync state and call SetSummaryValid(true) when a new database is
created, and log the rebuild.

The resulting full resync treats the folder's messages as new (filters, junk
classification, notifications); avoiding that is left to a follow-up.

Attachment #9671118 - Attachment description: Bug 2083049 - Reset the sync state and mark the summary valid when an Exchange folder's database is rebuilt. r?jtracey → Bug 2083049 - Reset the sync state and mark the summary valid when an Exchange folder's database is rebuilt. r=jtracey

D337981 is accepted, thanks! I can't set the target milestone on this bug, which Bugzilla requires for checkin-needed-tb. Could you add checkin-needed-tb, or assign the bug to me so I can request landing?

Flags: needinfo?(jtracey)

Oh, sorry about that.

Assignee: jtracey → benoit
Flags: needinfo?(jtracey)
Target Milestone: --- → 162 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/87c438c61ecf
Reset the sync state and mark the summary valid when an Exchange folder's database is rebuilt. r=jtracey

Status: ASSIGNED → RESOLVED
Closed: 12 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: