diff --git a/dev/Common/Html.js b/dev/Common/Html.js index 58a27321c..53f9c94e7 100644 --- a/dev/Common/Html.js +++ b/dev/Common/Html.js @@ -102,9 +102,11 @@ export const .replace(/(
]*>)([\s\S]*?)(<\/pre>)/gi, aMatches => { return (aMatches[1] + aMatches[2].trim() + aMatches[3].trim()).replace(/\r?\n/g, '
'); }) - // \MailSo\Base\HtmlUtils::ClearFastTags - .replace(/]*>/i, '') - .replace(/<\?xml [^>]*\?>/i, '') + .replace(/]*>/gi, '') + .replace(/<\?xml[^>]*\?>/gi, '') + // Not supported by element + .replace(/<(\/?)body(\s[^>]*)?>/gi, '<$1div class="mail-body"$2>') + .replace(/<\/?(html|head)[^>]*>/gi, '') .trim(); html = ''; @@ -117,11 +119,7 @@ export const tpl.content.querySelectorAll('*').forEach(oElement => { const name = oElement.tagName, - oStyle = oElement.style, - hasAttribute = name => oElement.hasAttribute(name), - getAttribute = name => hasAttribute(name) ? oElement.getAttribute(name).trim() : '', - setAttribute = (name, value) => oElement.setAttribute(name, value), - delAttribute = name => oElement.removeAttribute(name); + oStyle = oElement.style; // \MailSo\Base\HtmlUtils::ClearTags() if (disallowedTags.includes(name) @@ -151,7 +149,23 @@ export const return; } */ - const aAttrsForRemove = []; + const aAttrsForRemove = [], + hasAttribute = name => oElement.hasAttribute(name), + getAttribute = name => hasAttribute(name) ? oElement.getAttribute(name).trim() : '', + setAttribute = (name, value) => oElement.setAttribute(name, value), + delAttribute = name => oElement.removeAttribute(name); + + if ('mail-body' === oElement.className) { + forEachObjectEntry(tasks, (name, cb) => { + if (hasAttribute(name)) { + cb(getAttribute(name), oElement); + delAttribute(name); + } + }); + result.css = oElement.style.cssText; + replaceWithChildren(oElement); + return; + } if (oElement.hasAttributes()) { let i = oElement.attributes.length; @@ -164,16 +178,7 @@ export const } } - if ('BODY' === name) { - forEachObjectEntry(tasks, (name, cb) => { - if (hasAttribute(name)) { - cb(getAttribute(name), oElement); - delAttribute(name); - } - }); - } - - else if ('TABLE' === name) { + if ('TABLE' === name) { if (hasAttribute('width')) { oStyle.width = getAttribute('width'); delAttribute('width'); @@ -328,6 +333,9 @@ export const oStyle.removeProperty('background-image'); oStyle.removeProperty('color'); } + + // Drop Microsoft Office style properties +// oStyle.cssText = oStyle.cssText.replace(/mso-[^:;]+:[^;]+/gi, ''); } if (debug && aAttrsForRemove.length) { @@ -336,7 +344,7 @@ export const }); // return tpl.content.firstChild; - result.html = tpl.innerHTML; + result.html = tpl.innerHTML.trim(); return result; }, diff --git a/dev/Model/Message.js b/dev/Model/Message.js index d5a1c978f..094599373 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -409,13 +409,6 @@ export class MessageModel extends AbstractModel { body.classList.toggle('html', 1); body.classList.toggle('plain', 0); - // Drop Microsoft Office style properties - const rgbRE = /rgb\((\d+),\s*(\d+),\s*(\d+)\)/g, - hex = n => ('0' + parseInt(n).toString(16)).slice(-2); - body.querySelectorAll('[style*=mso]').forEach(el => - el.setAttribute('style', el.style.cssText.replace(rgbRE, (m,r,g,b) => '#' + hex(r) + hex(g) + hex(b))) - ); - // showInternalImages const findAttachmentByCid = cid => this.attachments().findByCid(cid); body.querySelectorAll('[data-x-src-cid],[data-x-src-location],[data-x-style-cid]').forEach(el => {