mail page imap connection 3

This commit is contained in:
alma 2025-04-15 20:24:09 +02:00
parent ea4de624eb
commit 69f39607ea

View File

@ -6,7 +6,7 @@ import { simpleParser } from 'mailparser';
const imapConfig = {
user: 'contact@governance-labs.org',
password: 'K!376c$6H#kMknM',
host: 'mail.infomniak.com',
host: 'mail.infomaniak.com',
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false }
@ -14,10 +14,11 @@ const imapConfig = {
interface ImapMessage {
header: {
from: string[];
to: string[];
subject: string[];
date: string[];
from?: string[];
to?: string[];
subject?: string[];
date?: string[];
[key: string]: string[] | undefined;
};
body: string;
attributes: {
@ -112,12 +113,12 @@ export async function GET(request: Request) {
const processedMessages = messages.map((msg: ImapMessage, index: number) => ({
id: index + 1,
accountId: 1,
from: msg.header.from[0],
fromName: msg.header.from[0].split('<')[0].trim(),
to: msg.header.to[0],
subject: msg.header.subject[0],
body: msg.body,
date: msg.header.date[0],
from: msg.header.from?.[0] || '',
fromName: (msg.header.from?.[0] || '').split('<')[0].trim(),
to: msg.header.to?.[0] || '',
subject: msg.header.subject?.[0] || '',
body: msg.body || '',
date: msg.header.date?.[0] || new Date().toISOString(),
read: !(msg.attributes.flags.indexOf('\\Seen') < 0),
starred: !(msg.attributes.flags.indexOf('\\Flagged') < 0),
category: 'inbox'