courrier multi account restore compose
This commit is contained in:
parent
e62d197d2c
commit
d3776c1026
@ -35,6 +35,7 @@ export async function GET(
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const folder = searchParams.get("folder") || "INBOX";
|
||||
const accountId = searchParams.get("accountId");
|
||||
|
||||
try {
|
||||
// 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`);
|
||||
|
||||
// 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 NextResponse.json(email);
|
||||
|
||||
@ -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>
|
||||
<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' && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@ -397,10 +397,11 @@ export async function getEmails(
|
||||
export async function getEmailContent(
|
||||
userId: string,
|
||||
emailId: string,
|
||||
folder: string = 'INBOX'
|
||||
folder: string = 'INBOX',
|
||||
accountId?: string
|
||||
): Promise<EmailMessage> {
|
||||
// Try to get from cache first
|
||||
const cachedEmail = await getCachedEmailContent(userId, folder, emailId);
|
||||
const cachedEmail = await getCachedEmailContent(userId, accountId || folder, emailId);
|
||||
if (cachedEmail) {
|
||||
console.log(`Using cached email content for ${userId}:${emailId}`);
|
||||
return cachedEmail;
|
||||
@ -408,7 +409,7 @@ export async function getEmailContent(
|
||||
|
||||
console.log(`Cache miss for email content ${userId}:${emailId}, fetching from IMAP`);
|
||||
|
||||
const client = await getImapConnection(userId);
|
||||
const client = await getImapConnection(userId, accountId);
|
||||
|
||||
try {
|
||||
await client.mailboxOpen(folder);
|
||||
@ -472,16 +473,17 @@ export async function getEmailContent(
|
||||
contentType: att.contentType,
|
||||
size: att.size || 0
|
||||
})),
|
||||
html: rawHtml,
|
||||
text: parsedEmail.text || undefined,
|
||||
content: rawHtml || parsedEmail.text || '',
|
||||
content: {
|
||||
text: parsedEmail.text || '',
|
||||
html: rawHtml
|
||||
},
|
||||
folder,
|
||||
contentFetched: true,
|
||||
size: size || 0
|
||||
};
|
||||
|
||||
// Cache the email content
|
||||
await cacheEmailContent(userId, folder, emailId, email);
|
||||
await cacheEmailContent(userId, accountId || folder, emailId, email);
|
||||
|
||||
return email;
|
||||
} finally {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user