Skip to content

Instantly share code, notes, and snippets.

@PanosJee
Created July 19, 2010 22:34
Show Gist options
  • Save PanosJee/482151 to your computer and use it in GitHub Desktop.
Save PanosJee/482151 to your computer and use it in GitHub Desktop.
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