Commit b262f65c authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

F [views] improve display of email headers

parent 624f1793eb0f
from cubicweb.web import uicfg
uicfg.primaryview_section.tag_object_of(('Email', 'in_thread', 'EmailThread'), 'hidden')
......@@ -7,7 +7,7 @@
__docformat__ = "restructuredtext en"
_ = unicode
from logilab.mtconverter import html_escape
from logilab.mtconverter import xml_escape
from cubicweb.selectors import implements
from cubicweb.common.uilib import soup2xhtml
......@@ -34,34 +34,42 @@ def formated_sender(email):
# sender address has been removed, look in email's headers
message = email.umessage_headers()
if message:
return html_escape(message.get('From'))
return xml_escape(message.get('From'))
return email.req._('unknown sender')
class EmailPrimaryView(primary.PrimaryView):
__select__ = implements('Email')
def render_entity_attributes(self, entity):
self.field('from', formated_sender(entity))
self.field('to', ', '.join(ea.view('oneline') for ea in entity.recipients))
self.w(u'<div class="emailheader"><table>')
self.w(u'<tr><td>%s</td><td>%s</td></tr>' %
(self.req._('From'), formated_sender(entity)))
self.w(u'<tr><td>%s</td><td>%s</td></tr>' %
(self.req._('To'), ', '.join(ea.view('oneline') for ea in entity.recipients)))
if entity.cc:
self.field('cc', ', '.join(ea.view('oneline') for ea in entity.cc))
self.field('subject', html_escape(entity.subject))
self.field('date', self.format_date(entity.date, time=True))
self.w(u'<tr><td>%s</td><td>%s</td></tr>' %
(self.req._('CC'), ', '.join(ea.view('oneline') for ea in entity.cc)))
self.w(u'<tr><td>%s</td><td>%s</td></tr>' %
(self.req._('Date'), self.format_date(entity.date, time=True)))
self.w(u'<tr><td>%s</td><td>%s</td></tr>' %
(self.req._('Subject'), xml_escape(entity.subject)))
self.w(u'</table></div><div class="emailcontent">')
for part in entity.parts_in_order():
content, mime = part.content, part.content_format
if mime == 'text/html':
content = soup2xhtml(content, self.req.encoding)
elif mime != 'text/xhtml':
content = html_escape(content)
content = xml_escape(content)
if mime == 'text/plain':
content = content.replace('\n', '<br/>').replace(' ', '&nbsp;')
# XXX some headers to skip if html ?
self.w(content)
self.w(u'<br class="partseparator"/>')
self.w(u'</div>')
def render_entity_title(self, entity):
self.w(u'<h1><span class="etype">%s</span> %s</h1>'
% (entity.dc_type().capitalize(), html_escape(entity.dc_title())))
% (entity.dc_type().capitalize(), xml_escape(entity.dc_title())))
class EmailHeadersView(baseviews.EntityView):
......@@ -98,7 +106,7 @@ class EmailOneLineView(baseviews.OneLineView):
self.w(u'<b>%s</b>&nbsp;%s'
% (self.req._('email_to'), recipients))
self.w(u'<br/>\n<a href="%s">%s</a>' % (
html_escape(entity.absolute_url()), html_escape(entity.subject)))
xml_escape(entity.absolute_url()), xml_escape(entity.subject)))
self.w(u'</div>')
......@@ -134,7 +142,7 @@ class EmailThreadPrimaryView(primary.PrimaryView):
def cell_call(self, row, col):
entity = self.complete_entity(row, col)
self.w(u'<h1>%s</h1>' % html_escape(entity.title))
self.w(u'<h1>%s</h1>' % xml_escape(entity.title))
# get top level emails in this thread (ie message which are not a reply
# of a message in this thread)
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment