diff --git a/app/courrier/components/DebugView.tsx b/app/courrier/components/DebugView.tsx
new file mode 100644
index 00000000..574cb8f6
--- /dev/null
+++ b/app/courrier/components/DebugView.tsx
@@ -0,0 +1,67 @@
+'use client';
+
+import { useState } from 'react';
+import { Button } from '@/components/ui/button';
+
+interface Account {
+ id: number | string;
+ name: string;
+ email: string;
+ color: string;
+ folders?: string[];
+}
+
+interface DebugViewProps {
+ accounts: Account[];
+ selectedAccount: Account | null;
+ mailboxes: string[];
+}
+
+export default function DebugView({ accounts, selectedAccount, mailboxes }: DebugViewProps) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ if (!isOpen) {
+ return (
+
+ );
+ }
+
+ return (
+
+
+
+
Debug View
+
+
+
+
+
+
Accounts ({accounts.length})
+
+ {JSON.stringify(accounts, null, 2)}
+
+
+
+
+
Selected Account
+
+ {selectedAccount ? JSON.stringify(selectedAccount, null, 2) : 'None'}
+
+
+
+
+
+
Mailboxes ({mailboxes?.length || 0})
+
+ {JSON.stringify(mailboxes, null, 2)}
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx
index fb44a6b5..2fd47fd3 100644
--- a/app/courrier/page.tsx
+++ b/app/courrier/page.tsx
@@ -72,6 +72,14 @@ interface Account {
folders?: string[];
}
+interface EmailWithFlags {
+ id: string;
+ read?: boolean;
+ flags?: {
+ seen?: boolean;
+ };
+}
+
export default function CourrierPage() {
const router = useRouter();
const { data: session } = useSession();
@@ -156,8 +164,9 @@ export default function CourrierPage() {
// Example: counting unread emails in the inbox
const unreadInInbox = (emails || []).filter(email => {
// Access the 'read' property safely, handling both old and new email formats
- return (!email.read && email.read !== undefined) ||
- (email.flags && !email.flags.seen) ||
+ const emailWithFlags = email as unknown as EmailWithFlags;
+ return (!emailWithFlags.read && emailWithFlags.read !== undefined) ||
+ (emailWithFlags.flags && !emailWithFlags.flags.seen) ||
false;
}).filter(email => currentFolder === 'INBOX').length;
setUnreadCount(unreadInInbox);
@@ -219,7 +228,7 @@ export default function CourrierPage() {
setPrefetchStarted(Boolean(data.prefetchStarted));
// Update accounts with the default email as fallback
- const updatedAccounts = [
+ const updatedAccounts: Account[] = [
{ id: 0, name: 'All', email: '', color: 'bg-gray-500' }
];
@@ -228,15 +237,17 @@ export default function CourrierPage() {
console.log('Multiple accounts found:', data.allAccounts.length);
// Add each account from the server
- data.allAccounts.forEach((account, index) => {
- console.log(`[DEBUG] Processing account: ${account.email}, display_name: ${account.display_name}, has folders: ${!!data.mailboxes}`);
+ data.allAccounts.forEach((account: any, index: number) => {
+ console.log(`[DEBUG] Processing account: ${account.email}, display_name: ${account.display_name}, has folders: ${account.folders ? account.folders.length : 0}`);
// Force include some hardcoded folders if none are present
const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'];
- const folderList = (data.mailboxes && data.mailboxes.length > 0) ?
- data.mailboxes :
- (account.folders && account.folders.length > 0) ?
- account.folders :
+
+ // Prioritize account-specific folders over global mailboxes
+ const folderList = (account.folders && account.folders.length > 0) ?
+ account.folders :
+ (data.mailboxes && data.mailboxes.length > 0) ?
+ data.mailboxes :
fallbackFolders;
console.log(`[DEBUG] Using folders for ${account.email}:`, folderList);
@@ -257,16 +268,19 @@ export default function CourrierPage() {
// 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;
+ // Create account with mailboxes as folders (using type assertion to avoid TypeScript error)
updatedAccounts.push({
id: 1,
name: data.email,
email: data.email,
color: 'bg-blue-500',
folders: folderList
- });
+ } as Account);
}
console.log('Setting accounts:', updatedAccounts);