@@ -12,8 +12,10 @@ import ButtonUnsend from './ButtonUnsendWrapper';
1212import AvatarImage from './AvatarImage' ;
1313import ButtonIcon from './ButtonIcon' ;
1414import { EmailStatus } from './../utils/const' ;
15+ import css from 'css' ;
1516import string from '../lang' ;
1617import './email.scss' ;
18+ import { logError } from '../utils/ipc' ;
1719
1820const DeletePermanenltyPopup = PopupHOC ( DialogPopup ) ;
1921const BlockRemotePopup = PopupHOC ( BlockRemoteContentPopup ) ;
@@ -105,7 +107,10 @@ const Email = props => (
105107 </ div >
106108 < hr />
107109 < div className = "email-body" >
108- < div disabled = { props . hideView || props . isUnsend } className = "email-text" >
110+ < div
111+ disabled = { props . hideView || props . isUnsend }
112+ className = { `email-text cptx-email-display-${ props . email . key } ` }
113+ >
109114 < div dangerouslySetInnerHTML = { { __html : theMail ( props ) } } />
110115 </ div >
111116 { ! ! props . files . length &&
@@ -331,10 +336,33 @@ const renderIconSecure = (onMouseEnterTooltip, onMouseLeaveTooltip, id) => {
331336} ;
332337
333338const theMail = props => {
334- const { content, blockImagesInline } = props ;
339+ const { content, blockImagesInline, email } = props ;
340+
341+ let newContent = content ;
342+ try {
343+ const wrapper = document . createElement ( 'div' ) ;
344+ wrapper . innerHTML = content ;
345+ const styles = wrapper . getElementsByTagName ( 'style' ) ;
346+ for ( const style of styles ) {
347+ const parsedCss = css . parse ( style . innerText ) ;
348+ const sheet = parsedCss . stylesheet ;
349+ for ( const rule in sheet . rules ) {
350+ const myRule = sheet . rules [ rule ] ;
351+ for ( const s in myRule . selectors ) {
352+ myRule . selectors [ s ] =
353+ `.cptx-email-display-${ email . key } ` + myRule . selectors [ s ] ;
354+ }
355+ }
356+ style . innerHTML = css . stringify ( parsedCss ) ;
357+ }
358+ newContent = wrapper . innerHTML ;
359+ } catch ( ex ) {
360+ logError ( ex ) ;
361+ }
362+
335363 if ( ! blockImagesInline )
336- return `<div class="email-container">${ content } </div>` ;
337- return getDOM ( content ) ;
364+ return `<div class="email-container">${ newContent } </div>` ;
365+ return getDOM ( newContent ) ;
338366} ;
339367
340368const getDOM = html => {
0 commit comments