use more standard methods from the email module

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3540 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-09-06 09:50:10 +00:00
parent 2877742faf
commit d0cc8acbc0

View file

@ -113,27 +113,19 @@ class IMAPCollectionProvider(object):
notify(ObjectModifiedEvent(obj))
yield obj
def getPayload(msg, parts=None):
if parts is None:
parts = {}
if msg.is_multipart():
for part in msg.get_payload():
getPayload(part, parts)
else:
ct = msg['Content-Type']
if ct:
if ct.startswith('text/html'):
parts.setdefault('html', []).append(getText(msg, ct))
elif ct.startswith('text/plain'):
parts.setdefault('plain', []).append(getText(msg, ct))
def getPayload(msg):
parts = {}
for msg in msg.walk():
ct = msg.get_content_type()
if ct == 'text/html':
parts.setdefault('html', []).append(getText(msg))
elif ct == 'text/plain':
parts.setdefault('plain', []).append(getText(msg))
return parts
def getText(msg, ct):
return msg.get_payload(decode=True).decode(getCharset(ct))
def getText(msg):
return msg.get_payload(decode=True).decode(getCharset(msg))
def getCharset(ct):
if 'charset=' in ct:
cs = ct.split('charset=', 1)[1]
if ';' in cs:
cs = cs.split(';', 1)[0]
return cs.replace('"', '')
def getCharset(msg):
return dict(msg.get_params()).get('charset') or 'ISO8859-1'