mirror of
https://github.com/craigerl/aprsd.git
synced 2025-06-26 14:05:26 -04:00
some failed attempts at getting the first txt or html from a multipart message, currently sends the last
This commit is contained in:
parent
3c16149e71
commit
90fcb9973b
@ -159,8 +159,8 @@ def parse_email(msgid, data, server):
|
|||||||
html = None
|
html = None
|
||||||
# default in case body somehow isn't set below - happened once
|
# default in case body somehow isn't set below - happened once
|
||||||
body = "* unreadable msg received"
|
body = "* unreadable msg received"
|
||||||
for part in msg.get_payload():
|
for part in msg.get_payload(): # FIXME this uses the last text or html part in the email, want the first, reverse order somehow?
|
||||||
if part.get_content_charset() is None:
|
if part.get_content_charset() is None: # or BREAK when we hit a text or html?
|
||||||
# We cannot know the character set,
|
# We cannot know the character set,
|
||||||
# so return decoded "something"
|
# so return decoded "something"
|
||||||
text = part.get_payload(decode=True)
|
text = part.get_payload(decode=True)
|
||||||
@ -184,7 +184,7 @@ def parse_email(msgid, data, server):
|
|||||||
body = text.strip()
|
body = text.strip()
|
||||||
else:
|
else:
|
||||||
body = html.strip()
|
body = html.strip()
|
||||||
else:
|
else: # message is not multipart
|
||||||
# email.uscc.net sends no charset, blows up unicode function below
|
# email.uscc.net sends no charset, blows up unicode function below
|
||||||
if msg.get_content_charset() is None:
|
if msg.get_content_charset() is None:
|
||||||
text = six.text_type(
|
text = six.text_type(
|
||||||
@ -198,7 +198,6 @@ def parse_email(msgid, data, server):
|
|||||||
'ignore').encode('utf8', 'replace')
|
'ignore').encode('utf8', 'replace')
|
||||||
body = text.strip()
|
body = text.strip()
|
||||||
|
|
||||||
# message is not multipart
|
|
||||||
# FIXED: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 6: ordinal not in range(128)
|
# FIXED: UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 6: ordinal not in range(128)
|
||||||
# decode with errors='ignore'. be sure to encode it before we return it below, also with errors='ignore'
|
# decode with errors='ignore'. be sure to encode it before we return it below, also with errors='ignore'
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user