courrier multi account restore compose

This commit is contained in:
alma 2025-04-28 16:42:13 +02:00
parent 7fc8e83330
commit 4da979c51d

View File

@ -66,7 +66,30 @@ export async function getImapConnection(userId: string, accountId?: string): Pro
// Get credentials from cache or database
const credentials = await getCachedEmailCredentials(userId, accountId || 'default');
if (!credentials) {
throw new Error('No email credentials found');
// If no credentials found with default accountId, try to get from database
const dbCredentials = await prisma.mailCredentials.findFirst({
where: { userId }
});
if (!dbCredentials) {
throw new Error('No email credentials found');
}
// Cache the credentials with the email as accountId
await cacheEmailCredentials(userId, dbCredentials.email, {
email: dbCredentials.email,
password: dbCredentials.password,
host: dbCredentials.host,
port: dbCredentials.port
});
// Try to get credentials again with the email as accountId
const retryCredentials = await getCachedEmailCredentials(userId, dbCredentials.email);
if (!retryCredentials) {
throw new Error('Failed to cache email credentials');
}
return getImapConnection(userId, dbCredentials.email);
}
// Create new connection