From 925e321759901068f3a546e3790bd70028853e5a Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 16 Apr 2025 00:31:38 +0200 Subject: [PATCH] mail page imap connection mime 5 bis rest 16 login page 18 --- app/api/mail/route.ts | 33 +++++++++++++++++++++------------ app/mail/login/page.tsx | 24 +++++++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/app/api/mail/route.ts b/app/api/mail/route.ts index 33b593d..1435ca0 100644 --- a/app/api/mail/route.ts +++ b/app/api/mail/route.ts @@ -56,22 +56,31 @@ interface ImapConfig { function getStoredCredentials(): StoredCredentials | null { const cookieStore = cookies(); - const email = cookieStore.get('imap_email')?.value; - const password = cookieStore.get('imap_password')?.value; - const host = cookieStore.get('imap_host')?.value; - const port = cookieStore.get('imap_port')?.value; + const credentialsCookie = cookieStore.get('imap_credentials'); + console.log('Retrieved credentials cookie:', credentialsCookie ? 'Found' : 'Not found'); - if (!email || !password || !host || !port) { - console.log('Missing credentials in cookies'); + if (!credentialsCookie?.value) { + console.log('No credentials cookie found'); return null; } - return { - email, - password, - host, - port: parseInt(port) - }; + try { + const credentials = JSON.parse(credentialsCookie.value); + console.log('Parsed credentials:', { + ...credentials, + password: '***' + }); + + return { + email: credentials.email, + password: credentials.password, + host: credentials.host, + port: credentials.port + }; + } catch (error) { + console.error('Error parsing credentials cookie:', error); + return null; + } } export async function GET() { diff --git a/app/mail/login/page.tsx b/app/mail/login/page.tsx index 7275688..9f1e34c 100644 --- a/app/mail/login/page.tsx +++ b/app/mail/login/page.tsx @@ -43,19 +43,29 @@ export default function LoginPage() { throw new Error(testData.error || 'Failed to connect to email server'); } - // Store credentials in a cookie + // Store all credentials in a single cookie const credentials = { email, password, host, port: parseInt(port), }; - - // Store each credential in a separate cookie - setCookie('imap_email', email, { maxAge: 60 * 60 * 24 }); // 1 day - setCookie('imap_password', password, { maxAge: 60 * 60 * 24 }); - setCookie('imap_host', host, { maxAge: 60 * 60 * 24 }); - setCookie('imap_port', port, { maxAge: 60 * 60 * 24 }); + + console.log('Storing credentials in cookie:', { + ...credentials, + password: '***' + }); + + // Store as a single cookie + setCookie('imap_credentials', JSON.stringify(credentials), { + maxAge: 60 * 60 * 24, // 1 day + path: '/', + sameSite: 'lax' + }); + + // Verify cookie was set + const stored = document.cookie.split(';').find(c => c.trim().startsWith('imap_credentials=')); + console.log('Cookie verification:', stored ? 'Cookie found' : 'Cookie not found'); // Redirect to mail page router.push('/mail');