mail page rest

This commit is contained in:
alma 2025-04-21 15:01:44 +02:00
parent 80e2d616ab
commit 5d5275183a
2 changed files with 13 additions and 60 deletions

View File

@ -1610,7 +1610,7 @@ export default function CourrierPage() {
return selectedEmail.cc || '';
};
const getReplyBody = (): string => {
const getReplyBody = () => {
if (!selectedEmail?.body) return '';
try {
@ -1621,7 +1621,7 @@ export default function CourrierPage() {
// Get the content from either HTML or text part
if (parsed.html) {
// Use MIME decoding for HTML content
originalContent = decodeMimeContent(parsed.html);
originalContent = decodeMIME(parsed.html, 'quoted-printable', 'utf-8');
// Convert HTML to plain text for the reply
originalContent = originalContent
@ -1650,66 +1650,23 @@ export default function CourrierPage() {
.trim();
} else if (parsed.text) {
// Use MIME decoding for plain text content
originalContent = decodeMimeContent(parsed.text).trim();
originalContent = decodeMIME(parsed.text, 'quoted-printable', 'utf-8').trim();
} else {
// Fallback to raw body if parsing fails, but still try to decode it
originalContent = decodeMimeContent(
selectedEmail.body.replace(/<[^>]+>/g, '')
originalContent = decodeMIME(
selectedEmail.body.replace(/<[^>]+>/g, ''),
'quoted-printable',
'utf-8'
).trim();
}
// Clean up the content
originalContent = originalContent
// Format the reply with proper indentation
const formattedContent = originalContent
.split('\n')
.map(line => line.trim())
.filter(line => {
// Remove email client signatures and headers
return !line.match(/^(From|To|Sent|Subject|Date|Cc|Bcc):/i) &&
!line.match(/^-{2,}/) &&
!line.match(/^_{2,}/) &&
!line.match(/^={2,}/) &&
!line.match(/^This (email|message) has been/i) &&
!line.match(/^Disclaimer/i) &&
!line.match(/^[*_-]{3,}/) &&
!line.match(/^Envoyé depuis/i) &&
!line.match(/^Envoyé à partir de/i) &&
!line.match(/^Sent from/i) &&
!line.match(/^Outlook pour/i) &&
!line.match(/^De :/i) &&
!line.match(/^À :/i) &&
!line.match(/^Objet :/i);
})
.join('\n')
.trim();
.map(line => `> ${line}`)
.join('\n');
// Format the reply
const date = new Date(selectedEmail.date);
const formattedDate = date.toLocaleString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false
});
let replyHeader = '';
if (type === 'forward') {
replyHeader = `\n\n---------- Forwarded message ----------\n`;
replyHeader += `From: ${selectedEmail.from}\n`;
replyHeader += `Date: ${formattedDate}\n`;
replyHeader += `Subject: ${selectedEmail.subject}\n`;
replyHeader += `To: ${selectedEmail.to}\n`;
if (selectedEmail.cc) {
replyHeader += `Cc: ${selectedEmail.cc}\n`;
}
replyHeader += `\n`;
} else {
// Simple header for reply and reply all
replyHeader = `\n\nOn ${formattedDate}, ${selectedEmail.from} wrote:\n`;
}
return replyHeader + originalContent;
return `\n\n${formattedContent}\n\n`;
} catch (error) {
console.error('Error preparing reply body:', error);
return '';

View File

@ -3,11 +3,7 @@ import { getServerSession } from 'next-auth';
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { prisma } from '@/lib/prisma';
let client: ImapFlow | null = null;
export async function getImapClient() {
if (client) return client;
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
throw new Error('No authenticated user');
@ -23,7 +19,7 @@ export async function getImapClient() {
throw new Error('No mail credentials found. Please configure your email account.');
}
client = new ImapFlow({
const client = new ImapFlow({
host: credentials.host,
port: credentials.port,
secure: true,