diff --git a/web/EmailList.tsx b/web/EmailList.tsx
index 2999737..a9109eb 100644
--- a/web/EmailList.tsx
+++ b/web/EmailList.tsx
@@ -63,6 +63,17 @@ export const EmailList = () => {
// with a message open should not close it.
const [searchParams, setSearchParams] = useSearchParams();
const folder = searchParams.get('folder') ?? 'inbox';
+ /*
+ WHICH MAILBOX, on the same reasoning as the folder above: addressable state, so a query param rather
+ than component state. Reload, share the URL or cmd-click a mailbox and you land where you meant to.
+
+ Absent means `all` HERE and only here. The routes themselves treat absent as "first enabled", which
+ `mail-scope.ts` keeps deliberately so the mobile app and the agent's email_db tool — neither of which
+ knows accounts exist — carry on working. That default is right for a caller that cannot choose and
+ wrong for a person looking at a screen: someone with three accounts opening their mail wants all of
+ it, not whichever one happens to sort first.
+ */
+ const account = searchParams.get('account') ?? 'all';
const qs = searchParams.toString() ? `?${searchParams}` : '';
const [page, setPage] = useState(1);
const [search, setSearch] = useState('');
@@ -76,7 +87,7 @@ export const EmailList = () => {
// cannot any more, because the folder pills are links and nobody handles their click.
useEffect(() => {
setPage(1);
- }, [debouncedSearch, folder]);
+ }, [debouncedSearch, folder, account]);
const { data: emailAccounts = [], refetch: refetchAccounts } = useQuery({
queryKey: ['email-accounts'],
@@ -87,14 +98,18 @@ export const EmailList = () => {
const hasAccounts = emailAccounts.length > 0;
const { data, isLoading } = useQuery({
- queryKey: isSearching ? ['email-search', debouncedSearch, page] : ['email-messages', page, folder],
+ // `account` is in the key: switching mailbox has to refetch, and without it react-query would serve
+ // the previous mailbox's page from cache under the new selection.
+ queryKey: isSearching
+ ? ['email-search', debouncedSearch, page, account]
+ : ['email-messages', page, folder, account],
queryFn: () =>
isSearching
? client.get<{ messages: EmailSummary[]; total: number }>(
- `/email/search?q=${encodeURIComponent(debouncedSearch)}&page=${page}&limit=${LIMIT}`,
+ `/email/search?q=${encodeURIComponent(debouncedSearch)}&page=${page}&limit=${LIMIT}&account=${account}`,
)
: client.get<{ messages: EmailSummary[]; total: number }>(
- `/email/messages?page=${page}&limit=${LIMIT}&folder=${folder}`,
+ `/email/messages?page=${page}&limit=${LIMIT}&folder=${folder}&account=${account}`,
),
// Keep the previous results visible while the next query loads, so switching search terms/pages
// never bails to the full-panel loading view (which would unmount the search input and drop focus).
@@ -271,6 +286,47 @@ export const EmailList = () => {