courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 19:38:59 +02:00
parent e62d197d2c
commit d3776c1026
3 changed files with 36 additions and 8 deletions

View File

@ -35,6 +35,7 @@ export async function GET(
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const folder = searchParams.get("folder") || "INBOX"; const folder = searchParams.get("folder") || "INBOX";
const accountId = searchParams.get("accountId");
try { try {
// Try to get email from Redis cache first // Try to get email from Redis cache first
@ -47,7 +48,7 @@ export async function GET(
console.log(`Cache miss for email content ${session.user.id}:${id}, fetching from IMAP`); console.log(`Cache miss for email content ${session.user.id}:${id}, fetching from IMAP`);
// Use the email service to fetch the email content // Use the email service to fetch the email content
const email = await getEmailContent(session.user.id, id, folder); const email = await getEmailContent(session.user.id, id, folder, accountId);
// Return the complete email object // Return the complete email object
return NextResponse.json(email); return NextResponse.json(email);

View File

@ -1013,6 +1013,31 @@ export default function CourrierPage() {
> >
<div className={`w-3 h-3 rounded-full ${account.color?.startsWith('#') ? 'bg-blue-500' : account.color || 'bg-blue-500'} mr-2`}></div> <div className={`w-3 h-3 rounded-full ${account.color?.startsWith('#') ? 'bg-blue-500' : account.color || 'bg-blue-500'} mr-2`}></div>
<span className="truncate text-gray-700 flex-1">{account.name}</span> <span className="truncate text-gray-700 flex-1">{account.name}</span>
{/* More options button (⋮) */}
{account.id !== 'loading-account' && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
type="button"
className="ml-1 text-gray-400 hover:text-gray-600 cursor-pointer flex items-center justify-center h-5 w-5"
tabIndex={-1}
onClick={e => e.stopPropagation()}
aria-label="Account options"
>
<span style={{ fontSize: '18px', lineHeight: 1 }}></span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={e => { e.stopPropagation(); setAccountToEdit(account); setShowEditModal(true); }}>
Edit
</DropdownMenuItem>
<DropdownMenuItem onClick={e => { e.stopPropagation(); setAccountToDelete(account); setShowDeleteDialog(true); }}>
Delete
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
{/* Expand/collapse arrow */}
{account.id !== 'loading-account' && ( {account.id !== 'loading-account' && (
<button <button
type="button" type="button"

View File

@ -397,10 +397,11 @@ export async function getEmails(
export async function getEmailContent( export async function getEmailContent(
userId: string, userId: string,
emailId: string, emailId: string,
folder: string = 'INBOX' folder: string = 'INBOX',
accountId?: string
): Promise<EmailMessage> { ): Promise<EmailMessage> {
// Try to get from cache first // Try to get from cache first
const cachedEmail = await getCachedEmailContent(userId, folder, emailId); const cachedEmail = await getCachedEmailContent(userId, accountId || folder, emailId);
if (cachedEmail) { if (cachedEmail) {
console.log(`Using cached email content for ${userId}:${emailId}`); console.log(`Using cached email content for ${userId}:${emailId}`);
return cachedEmail; return cachedEmail;
@ -408,7 +409,7 @@ export async function getEmailContent(
console.log(`Cache miss for email content ${userId}:${emailId}, fetching from IMAP`); console.log(`Cache miss for email content ${userId}:${emailId}, fetching from IMAP`);
const client = await getImapConnection(userId); const client = await getImapConnection(userId, accountId);
try { try {
await client.mailboxOpen(folder); await client.mailboxOpen(folder);
@ -472,16 +473,17 @@ export async function getEmailContent(
contentType: att.contentType, contentType: att.contentType,
size: att.size || 0 size: att.size || 0
})), })),
html: rawHtml, content: {
text: parsedEmail.text || undefined, text: parsedEmail.text || '',
content: rawHtml || parsedEmail.text || '', html: rawHtml
},
folder, folder,
contentFetched: true, contentFetched: true,
size: size || 0 size: size || 0
}; };
// Cache the email content // Cache the email content
await cacheEmailContent(userId, folder, emailId, email); await cacheEmailContent(userId, accountId || folder, emailId, email);
return email; return email;
} finally { } finally {