fix: Remove style tags from email content (#2515)
This commit is contained in:
parent
bed1979986
commit
ac657e3bf9
3 changed files with 31 additions and 6 deletions
|
@ -76,6 +76,8 @@ import contentTypeMixin from 'shared/mixins/contentTypeMixin';
|
||||||
import BubbleActions from './bubble/Actions';
|
import BubbleActions from './bubble/Actions';
|
||||||
import { MESSAGE_TYPE, MESSAGE_STATUS } from 'shared/constants/messages';
|
import { MESSAGE_TYPE, MESSAGE_STATUS } from 'shared/constants/messages';
|
||||||
import { generateBotMessageContent } from './helpers/botMessageContentHelper';
|
import { generateBotMessageContent } from './helpers/botMessageContentHelper';
|
||||||
|
import { stripStyleCharacters } from './helpers/EmailContentParser';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
BubbleActions,
|
BubbleActions,
|
||||||
|
@ -116,12 +118,10 @@ export default {
|
||||||
} = this.contentAttributes;
|
} = this.contentAttributes;
|
||||||
|
|
||||||
if ((replyHTMLContent || fullHTMLContent) && this.isIncoming) {
|
if ((replyHTMLContent || fullHTMLContent) && this.isIncoming) {
|
||||||
let parsedContent = new DOMParser().parseFromString(
|
let contentToBeParsed = replyHTMLContent || fullHTMLContent || '';
|
||||||
replyHTMLContent || fullHTMLContent || '',
|
const parsedContent = stripStyleCharacters(contentToBeParsed);
|
||||||
'text/html'
|
if (parsedContent) {
|
||||||
);
|
return parsedContent;
|
||||||
if (!parsedContent.getElementsByTagName('parsererror').length) {
|
|
||||||
return parsedContent.body.innerHTML;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
export const stripStyleCharacters = emailContent => {
|
||||||
|
let contentToBeParsed = emailContent.replace(/<style(.|\s)*?<\/style>/g, '');
|
||||||
|
contentToBeParsed = contentToBeParsed.replace(/style="(.*?)"/g, '');
|
||||||
|
let parsedContent = new DOMParser().parseFromString(
|
||||||
|
contentToBeParsed,
|
||||||
|
'text/html'
|
||||||
|
);
|
||||||
|
if (!parsedContent.getElementsByTagName('parsererror').length) {
|
||||||
|
return parsedContent.body.innerHTML;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
};
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { stripStyleCharacters } from '../EmailContentParser';
|
||||||
|
|
||||||
|
describe('#stripStyleCharacters', () => {
|
||||||
|
it('remove style characters', () => {
|
||||||
|
expect(
|
||||||
|
stripStyleCharacters(
|
||||||
|
`<html><body><style type="text/css"> \n<!-- \nimg \n {max-width:100%} \ndiv \n {width:100%!important; \n height:100%; \n line-height:1.6em} \ndiv \n {background-color:#f6f6f6} \n--> \n</style>\n<div itemscope="" itemtype="http://schema.org/EmailMessage" style="font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing:border-box; font-size:14px; width:100%!important; height:100%; line-height:1.6em; background-color:#f6f6f6; margin:0; background-color:#f6f6f6">Test Content</div>\n</body></html>`
|
||||||
|
)
|
||||||
|
).toEqual(
|
||||||
|
'\n<div itemscope="" itemtype="http://schema.org/EmailMessage">Test Content</div>\n'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue