mail page rest
This commit is contained in:
parent
80e2d616ab
commit
5d5275183a
@ -1610,7 +1610,7 @@ export default function CourrierPage() {
|
|||||||
return selectedEmail.cc || '';
|
return selectedEmail.cc || '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const getReplyBody = (): string => {
|
const getReplyBody = () => {
|
||||||
if (!selectedEmail?.body) return '';
|
if (!selectedEmail?.body) return '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1621,7 +1621,7 @@ export default function CourrierPage() {
|
|||||||
// Get the content from either HTML or text part
|
// Get the content from either HTML or text part
|
||||||
if (parsed.html) {
|
if (parsed.html) {
|
||||||
// Use MIME decoding for HTML content
|
// 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
|
// Convert HTML to plain text for the reply
|
||||||
originalContent = originalContent
|
originalContent = originalContent
|
||||||
@ -1650,66 +1650,23 @@ export default function CourrierPage() {
|
|||||||
.trim();
|
.trim();
|
||||||
} else if (parsed.text) {
|
} else if (parsed.text) {
|
||||||
// Use MIME decoding for plain text content
|
// Use MIME decoding for plain text content
|
||||||
originalContent = decodeMimeContent(parsed.text).trim();
|
originalContent = decodeMIME(parsed.text, 'quoted-printable', 'utf-8').trim();
|
||||||
} else {
|
} else {
|
||||||
// Fallback to raw body if parsing fails, but still try to decode it
|
// Fallback to raw body if parsing fails, but still try to decode it
|
||||||
originalContent = decodeMimeContent(
|
originalContent = decodeMIME(
|
||||||
selectedEmail.body.replace(/<[^>]+>/g, '')
|
selectedEmail.body.replace(/<[^>]+>/g, ''),
|
||||||
|
'quoted-printable',
|
||||||
|
'utf-8'
|
||||||
).trim();
|
).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up the content
|
// Format the reply with proper indentation
|
||||||
originalContent = originalContent
|
const formattedContent = originalContent
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(line => line.trim())
|
.map(line => `> ${line}`)
|
||||||
.filter(line => {
|
.join('\n');
|
||||||
// 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();
|
|
||||||
|
|
||||||
// Format the reply
|
return `\n\n${formattedContent}\n\n`;
|
||||||
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;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error preparing reply body:', error);
|
console.error('Error preparing reply body:', error);
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@ -3,11 +3,7 @@ import { getServerSession } from 'next-auth';
|
|||||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { prisma } from '@/lib/prisma';
|
||||||
|
|
||||||
let client: ImapFlow | null = null;
|
|
||||||
|
|
||||||
export async function getImapClient() {
|
export async function getImapClient() {
|
||||||
if (client) return client;
|
|
||||||
|
|
||||||
const session = await getServerSession(authOptions);
|
const session = await getServerSession(authOptions);
|
||||||
if (!session?.user?.id) {
|
if (!session?.user?.id) {
|
||||||
throw new Error('No authenticated user');
|
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.');
|
throw new Error('No mail credentials found. Please configure your email account.');
|
||||||
}
|
}
|
||||||
|
|
||||||
client = new ImapFlow({
|
const client = new ImapFlow({
|
||||||
host: credentials.host,
|
host: credentials.host,
|
||||||
port: credentials.port,
|
port: credentials.port,
|
||||||
secure: true,
|
secure: true,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user