def extract_text_body()

in workmail-salesforce-python/src/email_utils.py [0:0]


def extract_text_body(parsed_email):
     text_content = None
     text_charset = None
     if parsed_email.is_multipart():
         # Walk over message parts of this multipart email.
         for part in parsed_email.walk():
             content_type = part.get_content_type()
             content_disposition = str(part.get_content_disposition())
             if content_type == 'text/plain' and 'attachment' not in content_disposition:
                 text_content = part.get_payload(decode=True)
                 text_charset = part.get_content_charset()
                 break
     else:
         text_content = parsed_email.get_payload(decode=True)
         text_charset = parsed_email.get_content_charset()

     if text_content and text_charset:
         return text_content.decode(text_charset)
     return None