mail page rest
This commit is contained in:
parent
1bfa98dcfd
commit
d88ffc12da
@ -187,6 +187,33 @@ function parseFullEmail(emailRaw: string): ParsedEmailContent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no content was found, try to extract content directly
|
||||||
|
if (!result.text && !result.html) {
|
||||||
|
// Try to extract HTML content
|
||||||
|
const htmlMatch = emailRaw.match(/<html[^>]*>[\s\S]*?<\/html>/i);
|
||||||
|
if (htmlMatch) {
|
||||||
|
result.html = decodeEmailBody(htmlMatch[0], 'text/html');
|
||||||
|
} else {
|
||||||
|
// Try to extract plain text
|
||||||
|
const textContent = emailRaw
|
||||||
|
.replace(/<[^>]+>/g, '')
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/\r\n/g, '\n')
|
||||||
|
.replace(/=\n/g, '')
|
||||||
|
.replace(/=3D/g, '=')
|
||||||
|
.replace(/=09/g, '\t')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
if (textContent) {
|
||||||
|
result.text = textContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,12 +481,44 @@ function renderEmailContent(email: Email) {
|
|||||||
hasAttachments: parsedContent.attachments.length > 0
|
hasAttachments: parsedContent.attachments.length > 0
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine content type
|
// Determine content type and get content
|
||||||
const isHtml = parsedContent.html !== null;
|
let content = null;
|
||||||
const content = isHtml ? parsedContent.html : parsedContent.text;
|
let isHtml = false;
|
||||||
|
|
||||||
|
if (parsedContent.html) {
|
||||||
|
content = parsedContent.html;
|
||||||
|
isHtml = true;
|
||||||
|
} else if (parsedContent.text) {
|
||||||
|
content = parsedContent.text;
|
||||||
|
isHtml = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!content) {
|
if (!content) {
|
||||||
console.log('No content available');
|
console.log('No content available from parsing, trying direct body');
|
||||||
|
// Try to extract content directly from body
|
||||||
|
const htmlMatch = email.body.match(/<html[^>]*>[\s\S]*?<\/html>/i);
|
||||||
|
if (htmlMatch) {
|
||||||
|
content = htmlMatch[0];
|
||||||
|
isHtml = true;
|
||||||
|
} else {
|
||||||
|
content = email.body
|
||||||
|
.replace(/<[^>]+>/g, '')
|
||||||
|
.replace(/ /g, ' ')
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/\r\n/g, '\n')
|
||||||
|
.replace(/=\n/g, '')
|
||||||
|
.replace(/=3D/g, '=')
|
||||||
|
.replace(/=09/g, '\t')
|
||||||
|
.trim();
|
||||||
|
isHtml = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
console.log('No content available after all attempts');
|
||||||
return <div className="text-gray-500">No content available</div>;
|
return <div className="text-gray-500">No content available</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user