<%!
from baruwa.lib.crypto.hashing import md5
%>
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span10">
		<ul id="msgops">
			% if c.message and c.message['is_multipart']:
			% if c.richformat:
			<li>${h.link_to(_('Text Alternative'), url('message-archive-preview', msgid=c.msgid) if c.archived else url('message-preview', msgid=c.msgid), id='altformat', class_='textformat')}</li>
			% else:
			<li>${h.link_to(_('HTML Alternative'), url('message-archive-preview-html', msgid=c.msgid) if c.archived else url('message-preview-html', msgid=c.msgid), id='altformat', class_='htmlformat')}</li>
			% endif
			% endif
	      <li>${h.link_to(_('Release message'), url('message-archive', anchor="q", msgid=c.msgid) if c.archived else url('message-detail', msgid=c.msgid, anchor="q"))}</li>
		  <li>${h.link_to(_('Return to message'), url('message-archive', msgid=c.msgid) if c.archived else url('message-detail', msgid=c.msgid))}</li>
		</ul>
	</div>
	<div class="span1 hidden-phone"></div>
</div>
<!-- <div class="space-6"></div> -->
<div class="row-fluid">
	<div class="span1 hidden-phone"></div>
	<div class="span10">
		% if c.message:
		<div class="row-fluid">
			<div class="span12">
				<h3 class="head smaller lighter blue">${_('Message headers')}</h3>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12">
				<table class="table table-hover table-condensed table-striped">
				% for header in c.message['headers']:
					<tr>
						<td class="hidden-phone"><strong>${header.capitalize()}:</strong></td>
						<td class="lh">${h.wrap_paragraphs(c.message['headers'][header], 60) if c.message['headers'][header] else ''}</td>
					</tr>
				% endfor
				% if c.message['attachments']:
					<tr>
						<td colspan="2">&nbsp;</td>
					</tr>
					<tr>
						<td class="hidden-phone"><strong>${_('Attachments')}:</strong></td>
						<td class="lh">
							% for name in c.message['attachments']:
								% if c.isdangerous:
								${h.literal('<i class="icon-download"></i>') + h.literal('&nbsp;') + name['filename']}&nbsp;
								% else:
								${h.link_to(h.literal('<i class="icon-download"></i>') + h.literal('&nbsp;') + name['filename'], url('messages-archived-attach-dw', msgid=c.msgid, attachment=md5(name['filename'])) if c.archived else url('messages-attach-dw', msgid=c.msgid, attachment=md5(name['filename'])))}&nbsp;
								% endif
							% endfor
						</td>
					</tr>
				% endif
				</table>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12">
				<h3 class="head smaller lighter blue">${_('Message content')}</h3>
			</div>
		</div>
		<div class="row-fluid">
			% if c.message['has_html']:
			% for m in c.message['parts']:
			% if m['is_body'] and m['type'] == 'text/html' and m['style']:
			<style type="text/css">\
			${m['style']|n}
			</style>
			<% break %>
			% endif
			% endfor
			% endif
			<div class="span12" id="mailpreview">
				% if c.message['has_text'] and c.message['has_html']:
				<div id="email-text-part" class="${'hide' if c.richformat else 'show'}">
					% for m in c.message['parts']:
					% if m['type'] == 'text/plain' and m['is_body']:
					${h.linebreaksbr(m['content'])}
					<% break %>
					% endif
					% endfor
				</div>
				<div id="email-html-part" class="${'show' if c.richformat else 'hide'}">
					% for m in c.message['parts']:
					% if m['type'] == 'text/html' and m['is_body']:
					${m['content']|n}
					<% break %>
					% endif
					% endfor
				</div>
				% elif c.message['has_text']:
				<div id="email-text-part">
					% for m in c.message['parts']:
					% if m['type'] == 'text/plain' and m['is_body']:
					${h.linebreaksbr(m['content'])}
					<% break %>
					% endif
					% endfor
				</div>
				% elif c.message['has_html']:
				<div id="email-html-part">
					% for m in c.message['parts']:
					% if m['type'] == 'text/html' and m['is_body']:
					${m['content']|n}
					<% break %>
					% endif
					% endfor
				</div>
				% else:
				${_('Message has no content')}
				% endif
				% for m in c.message['parts']:
				% if not m['is_body'] and m['type'] == 'text/plain' and m['content']:
				<hr/>
				${h.linebreaksbr(m['content'])}
				% elif not m['is_body'] and m['type'] in ['text/html', 'message/delivery-status'] and m['content']:
				% if m['style']:
				<style type="text/css">
				${m['style']}
				</style>
				% endif
				<hr/>
				<div>
					% if m['type'] == 'text/html':
					${m['content']|n}
					% else:
					${h.linebreaksbr(m['content'])}
					% endif
				</div>
				% endif
				% endfor
			</div>
		</div>
		% else:
		<div class="row-fluid">
			<div class="span12">
				${_('Message: %(msgid)s could not be previewed') % dict(msgid=c.messageid)}
			</div>
		</div>
		% endif
	</div>
	<div class="span1 hidden-phone"></div>
</div>

<%def name="title()">
 ${_('Messages :: Previewing message : %(msgid)s') % dict(msgid=c.messageid)}
</%def>

<%def name="heading()">
${_('Messages :: Previewing message : %(msgid)s') % dict(msgid=h.wrap_paragraphs(c.messageid, 70))}
</%def>

<%def name="submenu()">\
<div class="navbar navbar-static-top">
    <div class="navbar-inner">
        <div class="nav-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="nav_item">${h.link_to(_('Full message list'), url(controller='messages', action='listing'))}</li>
				<li class="nav_item">${h.link_to(_('Quarantine'), url(controller='messages', action='quarantine'))}</li>
				<li class="nav_item">${h.link_to(_('Archive'), url(controller='messages', action='archive'))}</li>
            </ul>
        </div>
    </div>
</div>
</%def>

<%def name="headers()">\
</%def>
<%def name="localscripts()">\
<script type="text/javascript">
var preview_with_imgs_url = "${url('message-preview-archived-with-imgs', msgid=c.msgid) if c.archived else url('message-preview-with-imgs', msgid=c.msgid)}";
</script>
${h.javascript_link(h.media_url() + 'js/vendor/trunk8.min.js',
h.media_url() + 'js/baruwa/messages.preview.min.js')}
</%def>
<%inherit file="../base.html"/>
