import React from 'react'; import _ from "underscore"; import {EventedIFrame} from 'nylas-component-kit'; import {Utils, QuotedHTMLTransformer} from 'nylas-exports'; import {autolink} from './autolinker'; import EmailFrameStylesStore from './email-frame-styles-store'; export default class EmailFrame extends React.Component { static displayName = 'EmailFrame'; static propTypes = { content: React.PropTypes.string.isRequired, showQuotedText: React.PropTypes.bool, }; componentDidMount() { this._mounted = true; this._writeContent(); this._unlisten = EmailFrameStylesStore.listen(this._writeContent); } shouldComponentUpdate(nextProps, nextState) { return (!Utils.isEqualReact(nextProps, this.props) || !Utils.isEqualReact(nextState, this.state)); } componentDidUpdate() { this._writeContent(); } componentWillUnmount() { this._mounted = false; if (this._unlisten) { this._unlisten(); } } _emailContent = () => { // When showing quoted text, always return the pure content if (this.props.showQuotedText) { return this.props.content; } return QuotedHTMLTransformer.removeQuotedHTML(this.props.content, { keepIfWholeBodyIsQuote: true, }); } _writeContent = () => { this._lastComputedHeight = 0; const domNode = React.findDOMNode(this); const doc = domNode.contentDocument; if (!doc) { return; } doc.open(); // NOTE: The iframe must have a modern DOCTYPE. The lack of this line // will cause some bizzare non-standards compliant rendering with the // message bodies. This is particularly felt with