Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Created January 21, 2025 11:02
Show Gist options
  • Save alonsoir/ef01cac4a14e008322be7c3ee26a94a4 to your computer and use it in GitHub Desktop.
Save alonsoir/ef01cac4a14e008322be7c3ee26a94a4 to your computer and use it in GitHub Desktop.
import email
import quopri
from email import policy
from email.parser import BytesParser
def parse_email(file_path):
with open(file_path, 'rb') as file:
msg = BytesParser(policy=policy.default).parse(file)
print("From:", msg.get("From", "N/A"))
print("To:", msg.get("To", "N/A"))
print("Subject:", msg.get("Subject", "N/A"))
print("Date:", msg.get("Date", "N/A"))
print("Message ID:", msg.get("Message-ID", "N/A"))
print("X-Mailer:", msg.get("X-Mailer", "N/A"))
# Additional Information
print("\n--- Additional Information ---\n")
print("SPF:", msg.get("Received-SPF", "N/A"))
print("DKIM:", msg.get("DKIM-Signature", "N/A"))
print("DMARC:", msg.get("DMARC-Filter", "N/A"))
print("SENDERIP:", msg.get("X-Sender-IP", "N/A"))
print("RETURN PATH:", msg.get("Return-Path", "N/A"))
print("Reply-To:", msg.get("Reply-To", "N/A"))
print('Authentication Results:\n', msg.get('Authentication-Results','N/A'))
print('Message ID', msg.get('Message-Id','N/A'))
''' Print Email Headers '''
#print('\n\n\n\n')
#print("\n--- Email Headers ---\n")
#print(msg.as_string())
def main():
email_file_path = "test.eml" ## Email File
parse_email(email_file_path)
if __name__ == "__main__":
main()

/Users/aironman/Library/Caches/pypoetry/virtualenvs/attendance-system-SYPtwedO-py3.10/bin/python3.10 -X pycache_prefix=/Users/aironman/Library/Caches/JetBrains/PyCharmCE2024.2/cpython-cache /Users/aironman/Applications/PyCharm Community.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 53668 --file /Users/aironman/git/attendance_system/email_headers.py Connected to pydev debugger (build 242.23339.19) From: Filipi da Silva Fuchter [email protected] To: pipecat-ai/pipecat [email protected] Subject: Re: [pipecat-ai/pipecat] Some warnings when using v0.0.53 (Issue #1040) Date: Tue, 21 Jan 2025 02:58:31 -0800 Message ID: pipecat-ai/pipecat/issues/1040/[email protected] X-Mailer: N/A

--- Additional Information ---

SPF: pass (google.com: domain of [email protected] designates 192.30.252.208 as permitted sender) client-ip=192.30.252.208; DKIM: v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=pf2023; t=1737457111; bh=/5u89iBToMzhnNhPWP/D5QD1fuIRKhXTbQH+NIAcdN8=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:List-ID: List-Archive:List-Post:List-Unsubscribe:List-Unsubscribe-Post: From; b=GDzDwAngEkD9nfeN4o00JbIUOPgosmBOSCgU/76Eiz6KQPaGjHECl5sy/6B1peRYr fk93uXcjIh/7AvuBR4d45anR6xdd8mETJpsCWl2Td7Z275hPJ1KSPqfG7V996B0mLi VBiozu2ORXOkvUbXqLmoH8I9+gBgEs4J6VbZWFDM= DMARC: N/A SENDERIP: N/A RETURN PATH: [email protected] Reply-To: pipecat-ai/pipecat reply+AASLMOSJCAR5EKUPRMUK2IOFTNPNPEVBNHHKNPG2TE@reply.github.com Authentication Results: mx.google.com; dkim=pass [email protected] header.s=pf2023 header.b=GDzDwAng; spf=pass (google.com: domain of [email protected] designates 192.30.252.208 as permitted sender) smtp.mailfrom=[email protected]; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=github.com Message ID pipecat-ai/pipecat/issues/1040/[email protected]

Process finished with exit code 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment