From 63669217db637a15ccf01e04bc50ef03e1d1b062 Mon Sep 17 00:00:00 2001 From: alma Date: Tue, 15 Apr 2025 23:20:35 +0200 Subject: [PATCH] mail page imap connection mime 5 bis rest 14 --- app/api/mail/route.ts | 22 +++++++++++++--------- next.config.mjs | 12 ++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/api/mail/route.ts b/app/api/mail/route.ts index a4842ee..17ed9fa 100644 --- a/app/api/mail/route.ts +++ b/app/api/mail/route.ts @@ -1,26 +1,30 @@ import { NextResponse } from 'next/server'; import Imap from 'imap'; import { simpleParser } from 'mailparser'; +import getConfig from 'next/config'; + +// Get server runtime config +const { serverRuntimeConfig } = getConfig(); // Debug logging for environment variables console.log('Environment Variables:', { - IMAP_USER: process.env.IMAP_USER, - IMAP_HOST: process.env.IMAP_HOST, - IMAP_PORT: process.env.IMAP_PORT, - IMAP_PASSWORD: process.env.IMAP_PASSWORD ? '***' : undefined, + IMAP_USER: serverRuntimeConfig.IMAP_USER, + IMAP_HOST: serverRuntimeConfig.IMAP_HOST, + IMAP_PORT: serverRuntimeConfig.IMAP_PORT, + IMAP_PASSWORD: serverRuntimeConfig.IMAP_PASSWORD ? '***' : undefined, NODE_ENV: process.env.NODE_ENV }); // IMAP configuration const imapConfig: Imap.Config = { - user: process.env.IMAP_USER as string, - password: process.env.IMAP_PASSWORD as string, - host: process.env.IMAP_HOST || 'mail.infomaniak.com', - port: parseInt(process.env.IMAP_PORT || '993', 10), + user: serverRuntimeConfig.IMAP_USER as string, + password: serverRuntimeConfig.IMAP_PASSWORD as string, + host: serverRuntimeConfig.IMAP_HOST || 'mail.infomaniak.com', + port: parseInt(serverRuntimeConfig.IMAP_PORT || '993', 10), tls: true, tlsOptions: { rejectUnauthorized: false, - servername: process.env.IMAP_HOST || 'mail.infomaniak.com' + servername: serverRuntimeConfig.IMAP_HOST || 'mail.infomaniak.com' }, authTimeout: 10000, connTimeout: 10000, diff --git a/next.config.mjs b/next.config.mjs index 140065d..9b625cb 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -27,6 +27,18 @@ const nextConfig = { IMAP_HOST: process.env.IMAP_HOST, IMAP_PORT: process.env.IMAP_PORT, }, + // Ensure environment variables are available in API routes + serverRuntimeConfig: { + IMAP_USER: process.env.IMAP_USER, + IMAP_PASSWORD: process.env.IMAP_PASSWORD, + IMAP_HOST: process.env.IMAP_HOST, + IMAP_PORT: process.env.IMAP_PORT, + }, + // Make environment variables available to the client + publicRuntimeConfig: { + IMAP_HOST: process.env.IMAP_HOST, + IMAP_PORT: process.env.IMAP_PORT, + } }; mergeConfig(nextConfig, userConfig);