From 1af4275aab4c0bf5ee4a5b93521093950416d0d5 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sat, 5 Sep 2009 17:38:12 +0000 Subject: [PATCH] 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 --- browser/common.py | 5 +++++ browser/resource_macros.pt | 1 + integrator/README.txt | 2 +- integrator/mail/browser.py | 40 ++++++++++++++++++++++++++++++++++ integrator/mail/configure.zcml | 10 +++++++++ integrator/mail/imap.py | 12 +++++++--- integrator/mail/mail_macros.pt | 26 ++++++++++++++++++++++ 7 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 integrator/mail/browser.py create mode 100644 integrator/mail/mail_macros.pt diff --git a/browser/common.py b/browser/common.py index cbf456b..ac304db 100644 --- a/browser/common.py +++ b/browser/common.py @@ -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) diff --git a/browser/resource_macros.pt b/browser/resource_macros.pt index 9172377..5f5ad01 100644 --- a/browser/resource_macros.pt +++ b/browser/resource_macros.pt @@ -15,6 +15,7 @@

Description

+
diff --git a/integrator/README.txt b/integrator/README.txt index 43af8fa..d166874 100644 --- a/integrator/README.txt +++ b/integrator/README.txt @@ -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 - '

Blogging from ...
\n' + u'

Blogging from ...
\n' >>> aMail.externalAddress u'imap://jim@merz12/20081208171745.e4ce2xm96cco80cg@cy55.de' diff --git a/integrator/mail/browser.py b/integrator/mail/browser.py new file mode 100644 index 0000000..116bcd9 --- /dev/null +++ b/integrator/mail/browser.py @@ -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'] + diff --git a/integrator/mail/configure.zcml b/integrator/mail/configure.zcml index 2594c6d..352bad2 100644 --- a/integrator/mail/configure.zcml +++ b/integrator/mail/configure.zcml @@ -31,4 +31,14 @@ set_schema="loops.integrator.mail.interfaces.IMailResource" /> + + + + diff --git a/integrator/mail/imap.py b/integrator/mail/imap.py index 94ec66a..d35d1f1 100644 --- a/integrator/mail/imap.py +++ b/integrator/mail/imap.py @@ -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 diff --git a/integrator/mail/mail_macros.pt b/integrator/mail/mail_macros.pt new file mode 100644 index 0000000..48ba3bf --- /dev/null +++ b/integrator/mail/mail_macros.pt @@ -0,0 +1,26 @@ + + + + + + +


+ + + + + + + +
From: +
To: +
Date: +

+
+ + + + + + + \ No newline at end of file