mail page imap connection 15
This commit is contained in:
parent
3daa93bc95
commit
6af27f9065
@ -42,30 +42,56 @@ interface Email {
|
||||
}
|
||||
|
||||
// Improved MIME decoding function for all emails
|
||||
const decodeMimeContent = (content: string) => {
|
||||
const decodeMimeContent = (content: string): string => {
|
||||
try {
|
||||
// Remove MIME headers and metadata
|
||||
let cleanContent = content
|
||||
// Remove MIME headers
|
||||
// Handle forwarded message headers specially
|
||||
if (content.includes('-------- Forwarded message ----------')) {
|
||||
const parts: string[] = content.split('-------- Forwarded message ----------');
|
||||
if (parts.length > 1) {
|
||||
// Clean the forwarded headers section
|
||||
const headers = parts[1].split('\n')
|
||||
.filter(line => line.trim())
|
||||
.map(line => line.replace(/=\n/g, ''))
|
||||
.map(line => line.replace(/=([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))))
|
||||
.join('\n');
|
||||
|
||||
// Clean the message body
|
||||
const messageBody = parts[1].split('\n\n').slice(1).join('\n\n')
|
||||
.replace(/^This is a multi-part message.*?charset="utf-8"/s, '')
|
||||
.replace(/---InfomaniakPhpMail.*?Content-Transfer-Encoding:.*?\n/g, '')
|
||||
.replace(/Content-Type:.*?\n/g, '')
|
||||
.replace(/Content-Transfer-Encoding:.*?\n/g, '')
|
||||
.replace(/=C2=A0/g, ' ') // non-breaking space
|
||||
.replace(/=E2=80=(93|94)/g, '-') // dashes
|
||||
.replace(/=\n/g, '') // soft line breaks
|
||||
.replace(/=([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
|
||||
.replace(/\[IMG:(.*?)\]/g, '') // remove image placeholders
|
||||
.replace(/\[ ?LINK: ([^\]]+?) ?\]/g, '$1') // clean up links
|
||||
.replace(/\*(.*?)\*/g, '$1') // remove asterisk formatting
|
||||
.replace(/\n{3,}/g, '\n\n') // reduce multiple line breaks
|
||||
.replace(/^\s+|\s+$/gm, '') // trim each line
|
||||
.trim();
|
||||
|
||||
return `-------- Forwarded message ----------\n${headers}\n\n${messageBody}`;
|
||||
}
|
||||
}
|
||||
|
||||
// Regular email content cleaning
|
||||
return content
|
||||
.replace(/^This is a multi-part message.*?charset="utf-8"/s, '')
|
||||
.replace(/---InfomaniakPhpMail.*?Content-Transfer-Encoding:.*?\n/g, '')
|
||||
.replace(/Content-Type:.*?\n/g, '')
|
||||
.replace(/Content-Transfer-Encoding:.*?\n/g, '')
|
||||
// Clean up special characters and encoding
|
||||
.replace(/=C2=A0/g, ' ') // non-breaking space
|
||||
.replace(/=E2=80=(93|94)/g, '-') // dashes
|
||||
.replace(/=\n/g, '') // soft line breaks
|
||||
.replace(/=([0-9A-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
|
||||
// Format links and content markers
|
||||
.replace(/\[IMG:(.*?)\]/g, '') // remove image placeholders
|
||||
.replace(/\[ ?LINK: ([^\]]+?) ?\]/g, (_, url) => url) // clean up links
|
||||
.replace(/\[ ?LINK: ([^\]]+?) ?\]/g, '$1') // clean up links
|
||||
.replace(/\*(.*?)\*/g, '$1') // remove asterisk formatting
|
||||
// Clean up whitespace
|
||||
.replace(/\n{3,}/g, '\n\n') // reduce multiple line breaks
|
||||
.replace(/^\s+|\s+$/gm, '') // trim each line
|
||||
.trim();
|
||||
|
||||
return cleanContent;
|
||||
} catch (error) {
|
||||
console.error('Error decoding MIME content:', error);
|
||||
return content;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user