Commit e6b236ad authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

use sender from headers if no more linked

parent 56f5e28bb201
......@@ -4,7 +4,6 @@
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
import re
......
......@@ -4,6 +4,8 @@
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
_ = unicode
from logilab.mtconverter import html_escape
......@@ -25,11 +27,21 @@ uicfg.actionbox_appearsin_addmenu.tag_subject_of(('Email', 'attachment', '*'),
uicfg.actionbox_appearsin_addmenu.tag_object_of(('EmailThread', 'forked_from', 'EmailThread'),
True)
def formated_sender(email):
if email.sender:
return email.sender[0].view('oneline')
# sender address has been removed, look in email's headers
message = email.umessage_headers()
if message:
return html_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', entity.sender[0].view('oneline'))
self.field('from', formated_sender(entity))
self.field('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))
......@@ -74,19 +86,19 @@ class EmailOneLineView(baseviews.OneLineView):
def cell_call(self, row, col, contexteid=None):
entity = self.entity(row, col)
sender = entity.sender[0]
self.w(u'<div class="email">')
self.w(u'<i>%s&nbsp;%s</i> '
% (self.req._('email_date'), self.format_date(entity.date, time=True)))
if contexteid != sender.eid:
self.w(u'<i>%s&nbsp;%s</i> ' % (
self.req._('email_date'), self.format_date(entity.date, time=True)))
sender = entity.senderaddr
if sender is None or contexteid != sender.eid:
self.w(u'<b>%s</b>&nbsp;%s '
% (self.req._('email_from'), sender.view('oneline')))
% (self.req._('email_from'), formated_sender(entity)))
if contexteid not in (r.eid for r in entity.recipients):
recipients = ', '.join(r.view('oneline') for r in entity.recipients)
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)))
self.w(u'<br/>\n<a href="%s">%s</a>' % (
html_escape(entity.absolute_url()), html_escape(entity.subject)))
self.w(u'</div>')
......@@ -95,6 +107,7 @@ class EmailOutOfContextView(EmailOneLineView):
id = 'outofcontext'
title = _('out of context')
class EmailInContextView(EmailOneLineView):
"""short view inside the context of the email"""
id = 'incontext'
......@@ -115,6 +128,7 @@ class EmailThreadView(TreeViewMixIn, baseviews.ListView):
item_vid = 'outofcontext'
class EmailThreadPrimaryView(primary.PrimaryView):
__select__ = implements('EmailThread')
......
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