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:
parent
2877742faf
commit
d0cc8acbc0
1 changed files with 13 additions and 21 deletions
|
@ -113,27 +113,19 @@ class IMAPCollectionProvider(object):
|
||||||
notify(ObjectModifiedEvent(obj))
|
notify(ObjectModifiedEvent(obj))
|
||||||
yield obj
|
yield obj
|
||||||
|
|
||||||
def getPayload(msg, parts=None):
|
|
||||||
if parts is None:
|
def getPayload(msg):
|
||||||
parts = {}
|
parts = {}
|
||||||
if msg.is_multipart():
|
for msg in msg.walk():
|
||||||
for part in msg.get_payload():
|
ct = msg.get_content_type()
|
||||||
getPayload(part, parts)
|
if ct == 'text/html':
|
||||||
else:
|
parts.setdefault('html', []).append(getText(msg))
|
||||||
ct = msg['Content-Type']
|
elif ct == 'text/plain':
|
||||||
if ct:
|
parts.setdefault('plain', []).append(getText(msg))
|
||||||
if ct.startswith('text/html'):
|
|
||||||
parts.setdefault('html', []).append(getText(msg, ct))
|
|
||||||
elif ct.startswith('text/plain'):
|
|
||||||
parts.setdefault('plain', []).append(getText(msg, ct))
|
|
||||||
return parts
|
return parts
|
||||||
|
|
||||||
def getText(msg, ct):
|
def getText(msg):
|
||||||
return msg.get_payload(decode=True).decode(getCharset(ct))
|
return msg.get_payload(decode=True).decode(getCharset(msg))
|
||||||
|
|
||||||
def getCharset(ct):
|
def getCharset(msg):
|
||||||
if 'charset=' in ct:
|
return dict(msg.get_params()).get('charset') or 'ISO8859-1'
|
||||||
cs = ct.split('charset=', 1)[1]
|
|
||||||
if ';' in cs:
|
|
||||||
cs = cs.split(';', 1)[0]
|
|
||||||
return cs.replace('"', '')
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue