courrier multi account

This commit is contained in:
alma 2025-04-27 17:33:09 +02:00
parent 24614f9596
commit 0d6c4a1be9

View File

@ -263,24 +263,52 @@ export default function CourrierPage() {
updatedAccounts.push(accountWithFolders); updatedAccounts.push(accountWithFolders);
}); });
} else if (data.email) { } else if (data.email) {
// Fallback to single account if allAccounts is not available // Check if we have accounts from the API
console.log(`[DEBUG] Fallback to single account: ${data.email}`); if (data.allAccounts && Array.isArray(data.allAccounts) && data.allAccounts.length === 1) {
const singleAccount = data.allAccounts[0];
// Force include some hardcoded folders if none are present console.log('[DEBUG] Single account detected:',
const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk']; { id: singleAccount.id, email: singleAccount.email, folders: singleAccount.folders?.length });
// Prioritize mailboxes from IMAP if available // Force include some hardcoded folders if none are present
const folderList = (data.mailboxes && data.mailboxes.length > 0) ? const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'];
data.mailboxes : fallbackFolders;
// Fix: Check for account-specific folders first, then global mailboxes
// Create account with mailboxes as folders (using type assertion to avoid TypeScript error) const accountFolders = (singleAccount.folders && singleAccount.folders.length > 0) ?
updatedAccounts.push({ singleAccount.folders :
id: 1, (data.mailboxes && data.mailboxes.length > 0) ?
name: data.email, data.mailboxes :
email: data.email, fallbackFolders;
color: 'bg-blue-500',
folders: folderList console.log(`[DEBUG] Using folders for single account ${singleAccount.email}:`, accountFolders);
} as Account);
updatedAccounts.push({
id: singleAccount.id || 1,
name: singleAccount.display_name || singleAccount.email,
email: singleAccount.email,
color: singleAccount.color || 'bg-blue-500',
folders: accountFolders
} as Account);
} else {
// Fallback to single account if allAccounts is not available
console.log(`[DEBUG] Fallback to single account: ${data.email}`);
// Force include some hardcoded folders if none are present
const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'];
// Prioritize mailboxes from IMAP if available
const folderList = (data.mailboxes && data.mailboxes.length > 0) ?
data.mailboxes : fallbackFolders;
console.log(`[DEBUG] Using folders for fallback account ${data.email}:`, folderList);
updatedAccounts.push({
id: 1,
name: data.displayName || data.email,
email: data.email,
color: 'bg-blue-500',
folders: folderList
} as Account);
}
} }
console.log('Setting accounts:', updatedAccounts); console.log('Setting accounts:', updatedAccounts);