vmike read the docs & did some magic

master
anon_user 2019-11-20 23:15:21 +01:00
parent c2df1d83f8
commit 0a30876f19
1 changed files with 6 additions and 23 deletions

View File

@ -58,29 +58,12 @@ def make_report(msg, user):
date = get_date_from_header(msg['Date'])
author = msg['From'] # get mail author from email header
if msg.is_multipart():
text = []
for part in msg.get_payload():
if part.get_content_type() == "text":
text.append(part.get_payload())
elif part.get_content_type() == "application/pgp-signature":
pass # ignore PGP signatures
elif part.get_content_type() == "multipart/mixed":
for p in part:
if isinstance(p, str):
text.append(p)
elif p.get_content_type() == "text":
text.append(part.get_payload())
else:
logger.error("unknown MIMEtype: " +
p.get_content_type())
else:
logger.error("unknown MIMEtype: " +
part.get_content_type())
text = '\n'.join(text)
else:
text = msg.get_payload()
text = msg.get_body(('plain',))
if not text:
text = re.sub(r'<[^>]*>', '', msg.get_body(('html',)))
if not text:
logger.error('No suitable message body')
return
post = report.Report(author, "mail", text, None, date)
user.save_seen_mail(date)
return post