On this page
  1. email.message_from_binary_file
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from email import message_from_binary_file
help(message_from_binary_file)

Linked from

Related notes