courrier multi account restore compose
This commit is contained in:
parent
ccd8b8d762
commit
5f2da42848
@ -197,7 +197,8 @@ export default function CourrierPage() {
|
|||||||
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
||||||
false;
|
false;
|
||||||
|
|
||||||
if (isUnread && email.folder === 'INBOX') {
|
// Count unread emails regardless of current folder
|
||||||
|
if (isUnread) {
|
||||||
// If email has an accountId, increment that account's count
|
// If email has an accountId, increment that account's count
|
||||||
if (email.accountId) {
|
if (email.accountId) {
|
||||||
const currentCount = accountUnreadCounts.get(email.accountId) || 0;
|
const currentCount = accountUnreadCounts.get(email.accountId) || 0;
|
||||||
|
|||||||
@ -302,6 +302,8 @@ export async function getEmails(
|
|||||||
const start = Math.max(1, totalEmails - (page * perPage) + 1);
|
const start = Math.max(1, totalEmails - (page * perPage) + 1);
|
||||||
const end = Math.max(1, totalEmails - ((page - 1) * perPage));
|
const end = Math.max(1, totalEmails - ((page - 1) * perPage));
|
||||||
|
|
||||||
|
// Only fetch if we have messages
|
||||||
|
if (totalEmails > 0) {
|
||||||
// Fetch messages
|
// Fetch messages
|
||||||
const messages = await client.fetch(`${start}:${end}`, {
|
const messages = await client.fetch(`${start}:${end}`, {
|
||||||
envelope: true,
|
envelope: true,
|
||||||
@ -337,7 +339,8 @@ export async function getEmails(
|
|||||||
size: message.size || 0,
|
size: message.size || 0,
|
||||||
hasAttachments: message.bodyStructure?.childNodes?.some(node => node.disposition === 'attachment') || false,
|
hasAttachments: message.bodyStructure?.childNodes?.some(node => node.disposition === 'attachment') || false,
|
||||||
folder: folder,
|
folder: folder,
|
||||||
contentFetched: false
|
contentFetched: false,
|
||||||
|
accountId: accountId
|
||||||
};
|
};
|
||||||
emails.push(email);
|
emails.push(email);
|
||||||
}
|
}
|
||||||
@ -356,6 +359,23 @@ export async function getEmails(
|
|||||||
await cacheEmailList(userId, accountId || 'default', folder, page, perPage, result);
|
await cacheEmailList(userId, accountId || 'default', folder, page, perPage, result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
} else {
|
||||||
|
// Return empty result for empty folders
|
||||||
|
const result: EmailListResult = {
|
||||||
|
emails: [],
|
||||||
|
totalEmails: 0,
|
||||||
|
page,
|
||||||
|
perPage,
|
||||||
|
totalPages: 0,
|
||||||
|
folder,
|
||||||
|
mailboxes: await getMailboxes(client)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Cache the empty result
|
||||||
|
await cacheEmailList(userId, accountId || 'default', folder, page, perPage, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error fetching emails for ${userId}${accountId ? ` account ${accountId}` : ''}:`, error);
|
console.error(`Error fetching emails for ${userId}${accountId ? ` account ${accountId}` : ''}:`, error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
17
lib/types.ts
17
lib/types.ts
@ -33,29 +33,26 @@ export interface EmailAttachment {
|
|||||||
|
|
||||||
export interface EmailMessage {
|
export interface EmailMessage {
|
||||||
id: string;
|
id: string;
|
||||||
messageId?: string;
|
|
||||||
subject: string;
|
|
||||||
from: EmailAddress[];
|
from: EmailAddress[];
|
||||||
to: EmailAddress[];
|
to: EmailAddress[];
|
||||||
cc?: EmailAddress[];
|
cc?: EmailAddress[];
|
||||||
bcc?: EmailAddress[];
|
bcc?: EmailAddress[];
|
||||||
|
subject: string;
|
||||||
|
content: string;
|
||||||
|
preview?: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
flags: {
|
flags: {
|
||||||
seen: boolean;
|
seen: boolean;
|
||||||
flagged: boolean;
|
|
||||||
answered: boolean;
|
answered: boolean;
|
||||||
deleted: boolean;
|
flagged: boolean;
|
||||||
draft: boolean;
|
draft: boolean;
|
||||||
|
deleted: boolean;
|
||||||
};
|
};
|
||||||
preview?: string;
|
size: number;
|
||||||
content?: string;
|
|
||||||
html?: string;
|
|
||||||
text?: string;
|
|
||||||
hasAttachments: boolean;
|
hasAttachments: boolean;
|
||||||
attachments?: EmailAttachment[];
|
|
||||||
folder: string;
|
folder: string;
|
||||||
size?: number;
|
|
||||||
contentFetched: boolean;
|
contentFetched: boolean;
|
||||||
|
accountId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Account {
|
export interface Account {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user