provide view for mail resource; decode message when importing

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3538 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-09-05 17:38:12 +00:00
parent a78ec01d5c
commit 1af4275aab
7 changed files with 92 additions and 4 deletions

View file

@ -72,6 +72,7 @@ from loops.versioning.interfaces import IVersionable
concept_macros = ViewPageTemplateFile('concept_macros.pt')
conceptMacrosTemplate = concept_macros #
resource_macros = ViewPageTemplateFile('resource_macros.pt')
class NameField(schema.ASCIILine):
@ -131,6 +132,10 @@ class BaseView(GenericView, I18NView):
concept_macros = conceptMacros
@Lazy
def resource_macros(self):
return resource_macros.macros
@Lazy
def name(self):
return getName(self.context)

View file

@ -15,6 +15,7 @@
<p tal:define="description description|item/description"
tal:condition="description">
<i tal:content="description">Description</i></p>
<div metal:define-slot="fields" />
<div class="content-1" id="1.body"
tal:attributes="id id;"
tal:content="structure item/render">

View file

@ -176,7 +176,7 @@ to the external system:
>>> aMail.date, aMail.sender, aMail.receiver, aMail.title
(datetime.datetime(...), 'ceo@cy55.de', 'ceo@example.org', 'Blogging from Munich')
>>> aMail.data
'<p><b>Blogging from ...</b><br />\n'
u'<p><b>Blogging from ...</b><br />\n'
>>> aMail.externalAddress
u'imap://jim@merz12/20081208171745.e4ce2xm96cco80cg@cy55.de'

View file

@ -0,0 +1,40 @@
#
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
View class(es) for mail objects.
$Id$
"""
from zope import interface, component
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
from loops.browser.resource import DocumentView
from loops.common import adapted
class MailView(DocumentView):
macro_template = ViewPageTemplateFile('mail_macros.pt')
@property
def macro(self):
return self.macro_template.macros['email']

View file

@ -31,4 +31,14 @@
set_schema="loops.integrator.mail.interfaces.IMailResource" />
</zope:class>
<!-- views -->
<zope:adapter
name="email.html"
for="loops.interfaces.IResource
zope.publisher.interfaces.browser.IBrowserRequest"
provides="zope.interface.Interface"
factory="loops.integrator.mail.browser.MailView"
permission="zope.View" />
</configure>

View file

@ -113,13 +113,19 @@ class IMAPCollectionProvider(object):
yield obj
def getPayload(self, msg, parts):
def getCharset(ct):
if 'charset=' in ct:
cs = ct.split('charset=', 1)[1]
if ';' in cs:
cs = cs.split(';', 1)[0]
return cs.replace('"', '')
if msg.is_multipart():
for part in msg.get_payload():
self.getPayload(part, parts)
else:
ct = msg['Content-Type']
if ct and ct.startswith('text/html'):
parts['html'] = msg.get_payload()
if ct and ct.startswith('text/plain'):
parts['plain'] = msg.get_payload()
parts['html'] = msg.get_payload(decode=True).decode(getCharset(ct))
elif ct and ct.startswith('text/plain'):
parts['plain'] = msg.get_payload(decode=True).decode(getCharset(ct))
return parts

View file

@ -0,0 +1,26 @@
<html i18n:domain="loops">
<metal:block define-macro="email">
<metal:block tal:define="description nothing">
<metal:render use-macro="item/resource_macros/render_base">
<div metal:fill-slot="fields"><br />
<table>
<tr>
<td><b>From:</b></td><td tal:content="item/adapted/sender" />
</tr>
<tr>
<td><b>To:</b></td><td tal:content="item/adapted/receiver" />
</tr>
<tr>
<td><b>Date:</b></td><td tal:content="item/adapted/date" />
</tr>
</table><br />
</div>
</metal:render>
</metal:block>
<metal:fields use-macro="view/comment_macros/comments" />
</metal:block>
</html>