feat: prioritise sent-folder addresses in To/Cc/Bcc autocomplete #380

Merged
guettlibot merged 1 commits from refs/pull/380/head into main 2026-06-03 22:27:06 +00:00
guettlibot commented 2026-06-03 22:12:46 +00:00 (Migrated from codeberg.org)

What changed

searchAddresses (used by the To/Cc/Bcc autocomplete) now runs two passes over the candidate email rows:

  1. Sent-folder rows first — the mailboxes table is queried for mailboxes with role='sent'; any email row whose mailboxPath matches gets processed before inbox/other rows. Within this group addresses are ordered by receivedAt DESC as before.
  2. All other rows — processed after sent rows, also by receivedAt DESC.

Within sent-folder rows, toAddresses and ccJson are checked before fromJson (the sender in a sent email is our own address, not a useful suggestion). For non-sent rows the original order (fromJson, toAddresses, ccJson) is kept.

This means: if you wrote to info@foo.de yesterday and received spam from info@spam.de today, typing "i" surfaces info@foo.de first.

How verified

  • All 492 unit tests pass (task test).
  • Added a dedicated test searchAddresses prioritises sent-folder addresses over newer received that inserts an older sent email and a newer received email matching the same query prefix and asserts the sent-folder address is returned first.

Closes #375

## What changed `searchAddresses` (used by the To/Cc/Bcc autocomplete) now runs two passes over the candidate email rows: 1. **Sent-folder rows first** — the mailboxes table is queried for mailboxes with `role='sent'`; any email row whose `mailboxPath` matches gets processed before inbox/other rows. Within this group addresses are ordered by `receivedAt` DESC as before. 2. **All other rows** — processed after sent rows, also by `receivedAt` DESC. Within sent-folder rows, `toAddresses` and `ccJson` are checked before `fromJson` (the sender in a sent email is our own address, not a useful suggestion). For non-sent rows the original order (`fromJson`, `toAddresses`, `ccJson`) is kept. This means: if you wrote to `info@foo.de` yesterday and received spam from `info@spam.de` today, typing "i" surfaces `info@foo.de` first. ## How verified - All 492 unit tests pass (`task test`). - Added a dedicated test `searchAddresses prioritises sent-folder addresses over newer received` that inserts an older sent email and a newer received email matching the same query prefix and asserts the sent-folder address is returned first. Closes #375
Sign in to join this conversation.