Merge branch 'main' of https://github.com/bulwarkmail/webmail
This commit is contained in:
@@ -621,6 +621,10 @@ export default function Home() {
|
||||
onToggleSpam: async () => {
|
||||
if (isScheduledView) return;
|
||||
const currentMailbox = mailboxes.find(m => m.id === selectedMailbox);
|
||||
// Marking your own outgoing mail as spam makes no sense - the toolbar
|
||||
// and menus hide the action in Sent/Drafts/Scheduled, so the shortcut
|
||||
// is a no-op there too.
|
||||
if (['sent', 'drafts', 'scheduled'].includes(currentMailbox?.role || '')) return;
|
||||
const isInJunk = currentMailbox?.role === 'junk';
|
||||
if (selectedEmailIds.size > 0 && client) {
|
||||
const ids = Array.from(selectedEmailIds);
|
||||
@@ -1648,6 +1652,45 @@ export default function Home() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleTogglePinned = async (emailToPin: Email) => {
|
||||
if (!client) return;
|
||||
|
||||
try {
|
||||
const email = emails.find(e => e.id === emailToPin.id) ?? emailToPin;
|
||||
const isPinned = email.keywords?.['$pinned'] === true;
|
||||
// JMAP keywords are a set of present keys - drop the key to unpin
|
||||
// rather than writing a false value.
|
||||
const keywords = { ...email.keywords };
|
||||
if (isPinned) {
|
||||
delete keywords['$pinned'];
|
||||
} else {
|
||||
keywords['$pinned'] = true;
|
||||
}
|
||||
|
||||
// Same unified-view routing as color tags: write to the email's own
|
||||
// account via the login it is reachable through. (#281)
|
||||
const pinClientId = isUnifiedView ? email.sourceClientAccountId : undefined;
|
||||
const pinAccountId = isUnifiedView ? email.sourceAccountId : undefined;
|
||||
const pinClient = pinClientId
|
||||
? (useAuthStore.getState().getClientForAccount(pinClientId) ?? client)
|
||||
: client;
|
||||
|
||||
await pinClient.updateEmailKeywords(email.id, keywords, pinAccountId);
|
||||
|
||||
// Patch in place so the icon flips immediately, then refetch the first
|
||||
// page so the mail floats/sinks per the server's pinned-first sort.
|
||||
// Skip the refetch where that sort does not apply (unified views) or
|
||||
// where it would replace a tag-filtered list (refreshCurrentMailbox
|
||||
// fetches by folder only).
|
||||
setEmailKeywordsLocal(email.id, keywords);
|
||||
if (!isUnifiedView && !useEmailStore.getState().selectedKeyword) {
|
||||
void refreshCurrentMailbox(client);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to toggle pin:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetColorTag = async (emailId: string, color: string | null) => {
|
||||
if (!client) return;
|
||||
|
||||
@@ -3038,6 +3081,9 @@ export default function Home() {
|
||||
await toggleStar(client, email.id);
|
||||
}
|
||||
}}
|
||||
onTogglePinned={async (email) => {
|
||||
await handleTogglePinned(email);
|
||||
}}
|
||||
onDelete={async (email) => {
|
||||
await handleDelete(email);
|
||||
}}
|
||||
|
||||
@@ -82,9 +82,16 @@ export async function PUT(request: NextRequest) {
|
||||
if (!tokenResponse.ok) {
|
||||
const errorText = await tokenResponse.text();
|
||||
logger.error('Token refresh failed', { status: tokenResponse.status, error: errorText });
|
||||
cookieStore.delete(cookieName);
|
||||
cookieStore.delete(refreshTokenServerCookieName(slot));
|
||||
return NextResponse.json({ error: 'Refresh failed' }, { status: 401 });
|
||||
// Drop the refresh token only when the server definitively rejected it
|
||||
// (invalid/expired/revoked grant). A 5xx or 429 is an outage - keeping
|
||||
// the cookie lets the session resume once the server is back.
|
||||
const status = tokenResponse.status;
|
||||
if (status === 400 || status === 401 || status === 403) {
|
||||
cookieStore.delete(cookieName);
|
||||
cookieStore.delete(refreshTokenServerCookieName(slot));
|
||||
return NextResponse.json({ error: 'Refresh failed' }, { status: 401 });
|
||||
}
|
||||
return NextResponse.json({ error: 'Token endpoint unavailable' }, { status: 503 });
|
||||
}
|
||||
|
||||
const tokens = await tokenResponse.json();
|
||||
|
||||
Reference in New Issue
Block a user