fix: route keyword writes to the email's own account in unified view

Tags applied to a shared/group-mailbox message did not persist. Custom
keywords (:*),  and  were written via Email/set
against the reaching client's primary account instead of the email's
owning account, so the server returned notUpdated without an error and
the change was lost on the next reload.

toggleStar already threaded an accountId through (#281); the keyword
methods did not. Add an optional accountId to updateEmailKeywords and
setKeyword and resolve it at the call sites from the email's source
account (sourceClientAccountId / sourceAccountId), matching the existing
delete/archive routing. Personal sources resolve to the account itself,
so behavior there is unchanged.
This commit is contained in:
Patrick Rotter
2026-07-04 14:53:15 +02:00
committed by Linus Rath
parent e9ac2de6cb
commit a099ab442a
5 changed files with 138 additions and 25 deletions
+15 -3
View File
@@ -74,14 +74,26 @@ export function useTagDrop({ tagId, onSuccess, onError }: UseTagDropOptions): Us
for (const emailId of emailIds) {
// Read fresh state to avoid stale closures
const currentEmails = useEmailStore.getState().emails;
const email = currentEmails.find(em => em.id === emailId);
const emailState = useEmailStore.getState();
const email = emailState.emails.find(em => em.id === emailId);
const keywords = { ...(email?.keywords || {}) };
// Add the tag without removing existing ones
keywords[`$label:${tagId}`] = true;
await client.updateEmailKeywords(emailId, keywords);
// In unified view route the write to the email's own account, reached
// through the login it is reachable via (`sourceClientAccountId`) and
// applied to its owning JMAP account (`sourceAccountId`). For personal
// sources these resolve to the account itself, so behavior is unchanged.
// Without this, tags on shared/group-mailbox messages are written to the
// reaching account and silently dropped by the server. (#281)
const tagClientId = emailState.isUnifiedView ? email?.sourceClientAccountId : undefined;
const tagAccountId = emailState.isUnifiedView ? email?.sourceAccountId : undefined;
const tagClient = tagClientId
? (useAuthStore.getState().getClientForAccount(tagClientId) ?? client)
: client;
await tagClient.updateEmailKeywords(emailId, keywords, tagAccountId);
}
// Refresh the email list