fix removing html elements added by thunderai when extracting text or html from the email. see #710
This commit is contained in:
parent
29ed9e6df6
commit
2460e40bf7
2 changed files with 21 additions and 27 deletions
|
|
@ -26,11 +26,14 @@ const MZTA_INJECTED_SELECTORS = [
|
||||||
'.mzta_dialog',
|
'.mzta_dialog',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Mirrors removeMozMainHeader() from mzta-utils.js.
|
function getCleanBodyHtml() {
|
||||||
// Removes the Thunderbird-injected header table and any preceding divs.
|
const clone = document.body.cloneNode(true);
|
||||||
function removeMozMainHeader(root) {
|
for (const selector of MZTA_INJECTED_SELECTORS) {
|
||||||
const table = root.querySelector('table.moz-main-header');
|
for (const el of clone.querySelectorAll(selector)) {
|
||||||
if (!table) return;
|
el.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const table of clone.querySelectorAll('table.moz-main-header')) {
|
||||||
let sibling = table.previousElementSibling;
|
let sibling = table.previousElementSibling;
|
||||||
while (sibling && sibling.tagName === 'DIV') {
|
while (sibling && sibling.tagName === 'DIV') {
|
||||||
const toRemove = sibling;
|
const toRemove = sibling;
|
||||||
|
|
@ -39,15 +42,6 @@ function removeMozMainHeader(root) {
|
||||||
}
|
}
|
||||||
table.remove();
|
table.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCleanBodyClone() {
|
|
||||||
const clone = document.body.cloneNode(true);
|
|
||||||
for (const selector of MZTA_INJECTED_SELECTORS) {
|
|
||||||
for (const el of clone.querySelectorAll(selector)) {
|
|
||||||
el.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
removeMozMainHeader(clone);
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,7 +168,7 @@ switch (message.command) {
|
||||||
|
|
||||||
case "getText": {
|
case "getText": {
|
||||||
let t = '';
|
let t = '';
|
||||||
const children = getCleanBodyClone().childNodes;
|
const children = getCleanBodyHtml().childNodes;
|
||||||
for (const node of children) {
|
for (const node of children) {
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
if (node.classList.contains('moz-signature')) {
|
if (node.classList.contains('moz-signature')) {
|
||||||
|
|
@ -187,11 +181,11 @@ switch (message.command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getTextOnly": {
|
case "getTextOnly": {
|
||||||
return Promise.resolve(getCleanBodyClone().innerText);
|
return Promise.resolve(getCleanBodyHtml().innerText);
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getFullHtml": {
|
case "getFullHtml": {
|
||||||
return Promise.resolve(getCleanBodyClone().innerHTML);
|
return Promise.resolve(getCleanBodyHtml().innerHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getOnlyTypedText": {
|
case "getOnlyTypedText": {
|
||||||
|
|
|
||||||
|
|
@ -272,8 +272,7 @@ export function htmlBodyToPlainText(htmlString) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeMozMainHeader(root) {
|
export function removeMozMainHeader(root) {
|
||||||
const table = root.querySelector('table.moz-main-header');
|
for (const table of root.querySelectorAll('table.moz-main-header')) {
|
||||||
if (!table) return;
|
|
||||||
let sibling = table.previousElementSibling;
|
let sibling = table.previousElementSibling;
|
||||||
while (sibling && sibling.tagName === 'DIV') {
|
while (sibling && sibling.tagName === 'DIV') {
|
||||||
const toRemove = sibling;
|
const toRemove = sibling;
|
||||||
|
|
@ -282,6 +281,7 @@ export function removeMozMainHeader(root) {
|
||||||
}
|
}
|
||||||
table.remove();
|
table.remove();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function cleanupNewlines(text) {
|
export function cleanupNewlines(text) {
|
||||||
return text
|
return text
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue