Issue #485 reports search showing the oldest mail at the top. PR #520 already fixed the two largest culprits (searchEmails and searchEmailsGlobal) by switching the FTS query from ORDER BY rank to ORDER BY received_at DESC and re-sorting the merged FTS + notes results.
The remaining two search paths surfaced from the UI — searchEmailsStructured (advanced search) and getEmailsByAddress (the per-address email list) — already used OrderingTerm.desc(receivedAt), but had no regression test, so a future change to either could silently reintroduce the bug this issue describes.
Changes
Add searchEmailsStructured returns results sorted by receivedAt descending
Add getEmailsByAddress returns results sorted by receivedAt descending
No production code changes — the existing implementations already sort newest-first; this just locks in the contract.
Test plan
fvm flutter test test/unit/email_repository_impl_test.dart — all 73 tests pass, including the two new ones.
fvm dart analyze test/unit/email_repository_impl_test.dart — no issues.
## Summary
Issue #485 reports search showing the oldest mail at the top. PR #520 already fixed the two largest culprits (`searchEmails` and `searchEmailsGlobal`) by switching the FTS query from `ORDER BY rank` to `ORDER BY received_at DESC` and re-sorting the merged FTS + notes results.
The remaining two search paths surfaced from the UI — `searchEmailsStructured` (advanced search) and `getEmailsByAddress` (the per-address email list) — already used `OrderingTerm.desc(receivedAt)`, but had no regression test, so a future change to either could silently reintroduce the bug this issue describes.
## Changes
- Add `searchEmailsStructured returns results sorted by receivedAt descending`
- Add `getEmailsByAddress returns results sorted by receivedAt descending`
No production code changes — the existing implementations already sort newest-first; this just locks in the contract.
## Test plan
- [x] `fvm flutter test test/unit/email_repository_impl_test.dart` — all 73 tests pass, including the two new ones.
- [x] `fvm dart analyze test/unit/email_repository_impl_test.dart` — no issues.
- [x] `fvm dart format` — no formatting changes.
Closes #485
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Issue #485 reports search showing the oldest mail at the top. PR #520 already fixed the two largest culprits (
searchEmailsandsearchEmailsGlobal) by switching the FTS query fromORDER BY ranktoORDER BY received_at DESCand re-sorting the merged FTS + notes results.The remaining two search paths surfaced from the UI —
searchEmailsStructured(advanced search) andgetEmailsByAddress(the per-address email list) — already usedOrderingTerm.desc(receivedAt), but had no regression test, so a future change to either could silently reintroduce the bug this issue describes.Changes
searchEmailsStructured returns results sorted by receivedAt descendinggetEmailsByAddress returns results sorted by receivedAt descendingNo production code changes — the existing implementations already sort newest-first; this just locks in the contract.
Test plan
fvm flutter test test/unit/email_repository_impl_test.dart— all 73 tests pass, including the two new ones.fvm dart analyze test/unit/email_repository_impl_test.dart— no issues.fvm dart format— no formatting changes.Closes #485