Created
July 19, 2010 22:34
-
-
Save PanosJee/482151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _process_body(pl): | |
"""find the final payload (body) of an email""" | |
if type(pl)==StringType: | |
return pl.replace('\r\n>',' ').replace('\r\n',' ').replace('\n\n',' ') | |
elif type(pl)==list: | |
return _process_body(pl[0]) | |
elif type(pl)==InstanceType: | |
return _process_body(pl._payload) | |
else: | |
print type(pl) | |
def _decode_body(subject,body): | |
"""decode body if in base64""" | |
try: | |
if re.search("(ISO-\d+-\d)", subject): | |
iso = re.search("(ISO-\d+-\d)", subject).group(0) | |
body = base64.b64decode(body).decode(iso) | |
body = text.replace('\r\n>',' ').replace('\r\n',' ').replace('\n\n',' ') | |
return body.encode('utf-8') if type(body)==unicode else body | |
except: | |
return body.encode('utf-8') if type(body)==unicode else body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment