mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Bugfix: HTMLTemplateElement never has a <body> element
This commit is contained in:
parent
6f2f5bce86
commit
0106751e64
2 changed files with 28 additions and 27 deletions
|
|
@ -102,9 +102,11 @@ export const
|
||||||
.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/gi, aMatches => {
|
.replace(/(<pre[^>]*>)([\s\S]*?)(<\/pre>)/gi, aMatches => {
|
||||||
return (aMatches[1] + aMatches[2].trim() + aMatches[3].trim()).replace(/\r?\n/g, '<br>');
|
return (aMatches[1] + aMatches[2].trim() + aMatches[3].trim()).replace(/\r?\n/g, '<br>');
|
||||||
})
|
})
|
||||||
// \MailSo\Base\HtmlUtils::ClearFastTags
|
.replace(/<!doctype[^>]*>/gi, '')
|
||||||
.replace(/<!doctype[^>]*>/i, '')
|
.replace(/<\?xml[^>]*\?>/gi, '')
|
||||||
.replace(/<\?xml [^>]*\?>/i, '')
|
// Not supported by <template> element
|
||||||
|
.replace(/<(\/?)body(\s[^>]*)?>/gi, '<$1div class="mail-body"$2>')
|
||||||
|
.replace(/<\/?(html|head)[^>]*>/gi, '')
|
||||||
.trim();
|
.trim();
|
||||||
html = '';
|
html = '';
|
||||||
|
|
||||||
|
|
@ -117,11 +119,7 @@ export const
|
||||||
|
|
||||||
tpl.content.querySelectorAll('*').forEach(oElement => {
|
tpl.content.querySelectorAll('*').forEach(oElement => {
|
||||||
const name = oElement.tagName,
|
const name = oElement.tagName,
|
||||||
oStyle = oElement.style,
|
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);
|
|
||||||
|
|
||||||
// \MailSo\Base\HtmlUtils::ClearTags()
|
// \MailSo\Base\HtmlUtils::ClearTags()
|
||||||
if (disallowedTags.includes(name)
|
if (disallowedTags.includes(name)
|
||||||
|
|
@ -151,7 +149,23 @@ export const
|
||||||
return;
|
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()) {
|
if (oElement.hasAttributes()) {
|
||||||
let i = oElement.attributes.length;
|
let i = oElement.attributes.length;
|
||||||
|
|
@ -164,16 +178,7 @@ export const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('BODY' === name) {
|
if ('TABLE' === name) {
|
||||||
forEachObjectEntry(tasks, (name, cb) => {
|
|
||||||
if (hasAttribute(name)) {
|
|
||||||
cb(getAttribute(name), oElement);
|
|
||||||
delAttribute(name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ('TABLE' === name) {
|
|
||||||
if (hasAttribute('width')) {
|
if (hasAttribute('width')) {
|
||||||
oStyle.width = getAttribute('width');
|
oStyle.width = getAttribute('width');
|
||||||
delAttribute('width');
|
delAttribute('width');
|
||||||
|
|
@ -328,6 +333,9 @@ export const
|
||||||
oStyle.removeProperty('background-image');
|
oStyle.removeProperty('background-image');
|
||||||
oStyle.removeProperty('color');
|
oStyle.removeProperty('color');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drop Microsoft Office style properties
|
||||||
|
// oStyle.cssText = oStyle.cssText.replace(/mso-[^:;]+:[^;]+/gi, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug && aAttrsForRemove.length) {
|
if (debug && aAttrsForRemove.length) {
|
||||||
|
|
@ -336,7 +344,7 @@ export const
|
||||||
});
|
});
|
||||||
|
|
||||||
// return tpl.content.firstChild;
|
// return tpl.content.firstChild;
|
||||||
result.html = tpl.innerHTML;
|
result.html = tpl.innerHTML.trim();
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -409,13 +409,6 @@ export class MessageModel extends AbstractModel {
|
||||||
body.classList.toggle('html', 1);
|
body.classList.toggle('html', 1);
|
||||||
body.classList.toggle('plain', 0);
|
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
|
// showInternalImages
|
||||||
const findAttachmentByCid = cid => this.attachments().findByCid(cid);
|
const findAttachmentByCid = cid => this.attachments().findByCid(cid);
|
||||||
body.querySelectorAll('[data-x-src-cid],[data-x-src-location],[data-x-style-cid]').forEach(el => {
|
body.querySelectorAll('[data-x-src-cid],[data-x-src-location],[data-x-style-cid]').forEach(el => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue