diff --git a/SyncerWeb.js b/SyncerWeb.js index a28ab21..8b1c54e 100644 --- a/SyncerWeb.js +++ b/SyncerWeb.js @@ -139,7 +139,19 @@ function* getBody(pg, messages, boxId) p.on('end', gen.cb()); p.write(msg[0].headers); let [ obj ] = yield p.end(); - obj.html = htmlawed.sanitize(obj.html||'', { safe: 1, elements: '* +style' }); + let styles = ''; + obj.html = (obj.html||'').replace(/]*>([\s\S]*?)<\/style\s*>/ig, function(m, m1) + { + styles += m1+'\n'; + return ''; + }); + obj.html = obj.html.replace(/^[\s\S]*?]*>([\s\S]*)<\/body>[\s\S]*$/i, '$1'); + obj.html = obj.html.replace(/^[\s\S]*?]*>([\s\S]*)<\/html>[\s\S]*$/i, '$1'); + if (styles) + { + obj.html = '\n'+obj.html; + } + obj.html = htmlawed.sanitize(obj.html||'', { safe: 1, elements: '* +style', keep_bad: 2, comment: 1 }); let upd = { body_text: obj.text||'', body_html: obj.html }; upd.body_html_text = obj.html.replace(/]*>.*<\/style\s*>|<\/?[^>]*>/g, ''); yield pg.update('messages m', upd).where({ folder_id: boxId, uid: msg[0].uid }).run(gen.ef());