courrier multi account restore compose
This commit is contained in:
parent
7fc8e83330
commit
4da979c51d
@ -66,9 +66,32 @@ export async function getImapConnection(userId: string, accountId?: string): Pro
|
|||||||
// Get credentials from cache or database
|
// Get credentials from cache or database
|
||||||
const credentials = await getCachedEmailCredentials(userId, accountId || 'default');
|
const credentials = await getCachedEmailCredentials(userId, accountId || 'default');
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
|
// 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');
|
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
|
// Create new connection
|
||||||
const client = new ImapFlow({
|
const client = new ImapFlow({
|
||||||
host: credentials.host,
|
host: credentials.host,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user