Last active
October 15, 2020 11:14
-
-
Save Bas-Man/7c7a6c9a7c141033063efc879d5be46e to your computer and use it in GitHub Desktop.
Extract Email Subject Line, Single line only support.
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
import email.parser | |
from email import policy | |
def openFromFile(fp) -> email.message.EmailMessage: | |
""" | |
Read in the open file pointer | |
:param fp: file pointer to open file. | |
:type fp: file pointer | |
:returns: msg which is an email.message.EmailMessage | |
:rtype: email.message.EmailMessage | |
""" | |
msg = email.parser.Parser(policy=policy.default) | |
return msg.parse(fp) | |
def openFromStr(string) -> email.message.EmailMessage: | |
""" | |
Read in the email from string. | |
:param string: | |
:type string: str | |
:returns: msg which is an email.message.EmailMessage | |
:rtype: email.message.EmailMessage | |
""" | |
msg = email.parser.Parser(policy=policy.default) | |
return msg.parsestr(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment