import React from 'react'; import DropDownButton from './DropDownButton.js'; import Util from './Util.js'; export default class MessageView extends React.PureComponent { state = { showImages: false } formatLongDate(dt) { if (!(dt instanceof Date)) dt = new Date(dt.replace(' ', 'T')); let h = dt.getHours(); let m = dt.getMinutes(); let s = dt.getSeconds(); return Util.WeekDays[dt.getDay()]+' '+dt.getDate()+' '+Util.Months[dt.getMonth()]+' '+ dt.getFullYear()+' '+(h < 10 ? '0' : '')+h+':'+(m < 10 ? '0' : '')+m+':'+(s < 10 ? '0' : '')+s; } componentWillReceiveProps(nextProps) { if (nextProps.msg != this.props.msg) { let ns = { showImages: false, blockedImages: false }; if (nextProps.msg && /]*>/i.exec(nextProps.msg.body_html)) { ns.blockedImages = true; } this.setState(ns); } } showImages = () => { this.setState({ showImages: true }); } render() { let showImages = this.state.showImages; let msg = this.props.msg; let html; if (msg) { html = msg.body_html; if (!showImages) { html = html.replace(/(]*?src=)(["'])([^'"]*\2)/ig, '$1$2blocked:$3'); html = html.replace(/]*>(.*)<\/style\s*>/ig, function(m, m1) { m1 = m1.replace(/(url\(["']?|\@import\s*["'])([^"']*)/ig, '$1blocked:$2'); return ''; }); } } return
Reply All f == 'unread').length} checkedIcon="read_selected" icon="read" checkedText="Unread" text="Read" onClick={this.props.onToggleRead} /> Label
No message selected
{msg ? [
{this.formatLongDate(msg.time)}
{msg.subject}
To
{msg.props.to.map(a => ' : a[1]}>{a[0] || a[1]})}
{msg.props.cc.length ?
Cc
{msg.props.cc.map(a => ' : a[1]}>{a[0] || a[1]})}
: null} {msg.props.bcc.length ?
Bcc
{msg.props.bcc.map(a => ' : a[1]}>{a[0] || a[1]})}
: null} {msg.props.replyto ?
Reply-to
{[msg.props.replyto].map(a => ' : a[1]}>{a[0] || a[1]})}
: null} {msg.props.attachments && msg.props.attachments.length ?
Attachments
{msg.props.attachments.map(a => ( {a.name+' ('+Util.formatBytes(a.size)+')'} ))}
: null}
, (this.state.blockedImages && !this.state.showImages ?
This message contains blocked images. Load Images {(msg.props.from ? : null)}
: null), (html ?
:
{msg.body_text}
), (this.props.quickReply ?
: null), ] : null}
} }