HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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