File: //proc/self/root/home/arjun/projects/buyercall/buyercall/blueprints/email/utils.py
from email.parser import BytesParser
from email import policy
def parse_raw_email(raw_email):
msg = BytesParser(policy=policy.SMTP).parsebytes(raw_email)
# get the plain text version of the email
plain = ''
try:
plain = msg.get_body(preferencelist=('plain'))
plain = ''.join(plain.get_content().splitlines(keepends=True))
plain = '' if not plain else plain
except:
print('Inbound mail does not have a plain text part.')
# get the HTML version of the email
html = ''
try:
html = msg.get_body(preferencelist=('html'))
html = ''.join(html.get_content().splitlines(keepends=True))
html = '' if not html else html
except:
print('Inbound mail does not have an HTML part.')
return (plain)
def get_pid_from_topic_arn(topic_arn=None):
if topic_arn:
x, y, z = topic_arn.rpartition("-")
a,b, pid = x.rpartition(':')
return pid
return