email.message_from_binary_file
Up: email | Next: email.message_from_bytes
Rel: email.message_from_bytes, email.message_from_file, email.message_from_string
Ref: docs.python.org — email.message_from_binary_file
Tags: #public #python3 #stdlib #email
Import
import email
from email import message_from_binary_file
Signature & Overview
email.message_from_binary_file(fp, *args, **kws)
Read a binary file and parse its contents into a Message object model.
Usage
import email
from email import policy
import io
raw = io.BytesIO(b"From: a@example.com\r\nSubject: Hi\r\n\r\nBody")
msg = email.message_from_binary_file(raw, policy=policy.default)
assert msg["Subject"] == "Hi" and msg.get_content().strip() == "Body"
Gotchas
- Always pass
policy=email.policy.default: Without it,emailreturns legacyMessageobjects instead of modernEmailMessage.
REPL Inspect
from email import message_from_binary_file
help(message_from_binary_file)
Linked from
Related notes
- tuts/python3/stdlib_module/email/message_from_bytes Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email/message_from_file Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email/message_from_string Linked here; links to this page; shared tags: #email, #stdlib
- tuts/python3/stdlib_module/email Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib