feat: enhance email body handling by prioritizing textBody for minimal HTML and expanding JMAPClient properties
This commit is contained in:
@@ -1925,7 +1925,16 @@ export function EmailViewer({
|
||||
|
||||
if (email.htmlBody?.[0]?.partId && email.bodyValues[email.htmlBody[0].partId]) {
|
||||
htmlContent = email.bodyValues[email.htmlBody[0].partId].value;
|
||||
useHtmlVersion = !!htmlContent;
|
||||
// Prefer textBody when HTML is auto-generated minimal wrapper (no rich formatting).
|
||||
// Server-generated HTML from text/plain emails often lacks <br> tags, collapsing newlines.
|
||||
const hasTextBody = email.textBody?.[0]?.partId && email.bodyValues[email.textBody[0].partId];
|
||||
if (hasTextBody && htmlContent) {
|
||||
const stripped = htmlContent.replace(/<\/?(html|head|body|meta|!doctype|!DOCTYPE|br\s*\/?)[^>]*>/gi, '').trim();
|
||||
const hasRichContent = /<(table|tr|td|th|img|style|link|div\s+[^>]*class|span\s+[^>]*class|font|center|blockquote|ul|ol|li|h[1-6])\b/i.test(stripped);
|
||||
useHtmlVersion = hasRichContent;
|
||||
} else {
|
||||
useHtmlVersion = !!htmlContent;
|
||||
}
|
||||
}
|
||||
|
||||
// If we should use HTML version and it exists
|
||||
|
||||
@@ -316,7 +316,16 @@ function EmailCard({
|
||||
|
||||
if (email.htmlBody?.[0]?.partId && email.bodyValues[email.htmlBody[0].partId]) {
|
||||
htmlContent = email.bodyValues[email.htmlBody[0].partId].value;
|
||||
useHtmlVersion = !!htmlContent;
|
||||
// Prefer textBody when HTML is auto-generated minimal wrapper (no rich formatting).
|
||||
// Server-generated HTML from text/plain emails often lacks <br> tags, collapsing newlines.
|
||||
const hasTextBody = email.textBody?.[0]?.partId && email.bodyValues[email.textBody[0].partId];
|
||||
if (hasTextBody && htmlContent) {
|
||||
const stripped = htmlContent.replace(/<\/?(html|head|body|meta|!doctype|!DOCTYPE|br\s*\/?)[^>]*>/gi, '').trim();
|
||||
const hasRichContent = /<(table|tr|td|th|img|style|link|div\s+[^>]*class|span\s+[^>]*class|font|center|blockquote|ul|ol|li|h[1-6])\b/i.test(stripped);
|
||||
useHtmlVersion = hasRichContent;
|
||||
} else {
|
||||
useHtmlVersion = !!htmlContent;
|
||||
}
|
||||
}
|
||||
|
||||
if (useHtmlVersion && htmlContent) {
|
||||
|
||||
+10
-1
@@ -1088,7 +1088,16 @@ export class JMAPClient {
|
||||
["Email/get", {
|
||||
accountId: targetAccountId,
|
||||
ids: thread.emailIds,
|
||||
properties: [...EMAIL_LIST_PROPERTIES],
|
||||
properties: [
|
||||
...EMAIL_LIST_PROPERTIES,
|
||||
"textBody", "htmlBody", "bodyValues",
|
||||
"attachments", "blobId", "sentAt", "bcc", "replyTo",
|
||||
"messageId", "inReplyTo", "references", "headers", "bodyStructure",
|
||||
],
|
||||
fetchTextBodyValues: true,
|
||||
fetchHTMLBodyValues: true,
|
||||
fetchAllBodyValues: true,
|
||||
maxBodyValueBytes: 256000,
|
||||
}, "0"],
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user