Scan your whole stack
Are you using mail-parser?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v4.14.0
mail-parser was last scanned on 4 Dec 2026 at version 4.14.0. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 4.14.0 LATEST | 4 Dec 2026 | No rules fired |
| 4.13.0 | 1 Dec 2026 | No rules fired |
| 4.12.0 | 26 Nov 2026 | No rules fired |
| 4.11.0 | 15 Nov 2026 | Not shown |
| 4.10.0 | 30 Oct 2026 | Not shown |
Findings for v4.14.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 4.14.0; other versions have their own rules, not their own score.
0 CRITICAL 2 HIGH 4 MEDIUM 0 LOW
The publisher’s own README, as collected from the registry.

Project website: spamscope.ai/en/mail-parser/
mail-parser is a production-grade, RFC-compliant email parsing library that goes far beyond a simple wrapper for Python's email module. It turns a raw email into structured Python objects, draws its structure, and reports every defect it finds, so that malformed mail becomes evidence instead of a silent misread.
mail-parser is the battle-tested foundation of SpamScope, an email security and threat analysis platform, and has proven itself in production environments where accuracy and security matter most.
.msg files are parsed alongside standard .eml messages.Use the latest patch release of your Python series. mail-parser parses with Python's email
package, and older patch releases take quadratic time on a header with many parameters: an 80 KB
Content-Type value takes more than a second on Python 3.9.6, 3.11.11, 3.12.8 and 3.13.2, and
under 0.1 seconds on 3.10.22, 3.12.16, 3.13.18, 3.14.10 and 3.15.2.
pip install mail-parser
Outlook .msg files are converted to .eml before parsing. Two backends exist:
extract-msg (recommended, pure Python): pip install mail-parser[outlook].msgconvert (deprecated, external Perl tool): the libemail-outlook-message-perl system
package (apt-get install libemail-outlook-message-perl on Debian-based systems).When extract-msg is installed it is used first; only when it is not available does mail-parser
fall back to msgconvert, logging a deprecation warning. With neither backend,
parse_from_file_msg() raises MailParserOSError. A malformed .msg (not OLE, truncated,
corrupt) read with extract-msg raises MailParserOutlookError, with the library's exception as
__cause__.
⚠️ Deprecated: the
msgconvertbackend will be removed in a future release. Migrate withpip install mail-parser[outlook].
💥 Breaking change: the default .msg backend changed. The two converters produce different
intermediate .eml output, so some parsed fields (header ordering, encoding edge cases, attachment
naming) can differ from the previous msgconvert-only behaviour. Downstream code asserting on exact
.msg-derived output may need updating.
git clone https://github.com/SpamScope/mail-parser.git
cd mail-parser
uv sync
AGENTS.md holds the commands, the architecture notes and the review requirements.
import mailparser
mail = mailparser.parse_from_file("example_mail")
mail.from_ # [('Sender Name', 'sender@example.com')]
mail.to # [('Recipient', 'recipient@example.com')]
mail.subject # 'Invoice'
mail.date # datetime with timezone
mail.attachments # [{'filename': 'invoice.pdf', 'payload': '...base64...', ...}]
mail.received # one dict per hop, first hop first
mail.mime_tree # one dict per MIME part
mail.has_defects # True when anything needed recovery or broke a rule
mail.defects_categories # {'AddressHeaderDefect', ...}
mail.mail_json # the whole parsed mail as JSON
print(mailparser.render_structure(mail)) # headers, delivery path and MIME tree as text
From the command line:
mail-parser -f example_mail -j # parsed mail as JSON
mail-parser -f example_mail -st # draw the structure
mail-parser -f example_mail -j --mime-tree # JSON of the mail, then JSON of the MIME tree
import mailparser
mail = mailparser.parse_from_bytes(byte_mail) # bytes
mail = mailparser.parse_from_file(f) # file path, read as bytes
mail = mailparser.parse_from_file_obj(fp) # file object, opened in binary mode
mail = mailparser.parse_from_string(raw_mail) # text already decoded by the caller
mail = mailparser.parse_from_file_msg(outlook_mail) # Outlook .msg
mail = mailparser.MailParser(message) # an email.message.Message the caller parsed
parse_from_bytes(). Declared charsets apply
to the body; UTF-8 recovery applies when the declared decode fails, not by guessing which valid
interpretation the sender intended. Undecodable header octets appear as Python's
surrogateescape code points (\udcff is the byte FF).parse_from_string() accepts text the caller decoded. It may hold lone
surrogates, which are reported as evidence rather than failing the parse.parse_from_file_obj() reads a binary file object
(open(path, "rb"), sys.stdin.buffer) as bytes. A text file object has already decoded the
message, so it is read as a string: an 8-bit attachment is then no longer the octets of the
message, its hash differs, and PayloadEncodingDefect reports it. The command line reads
--stdin as bytes.MailParser(message) reads a message parsed with the
email package under any policy; message_as_string and the attached containers are flattened
through a copy. One limit lies in the email package itself: with the default compat32
policy, email.message_from_string() raises UnicodeEncodeError before mail-parser is involved
when Content-Type or Content-Transfer-Encoding holds a lone surrogate. Pass the text to
parse_from_string() instead.Every parsed element is available in three forms:
mail.to: the Python object (list, dict, string or datetime);mail.to_json: the same value as JSON;mail.to_raw: the original header text, exactly as it appears in the message.Standard headers are properties: bcc, cc, date, delivered_to, from_ (from is a
Python keyword), message_id, received, reply_to, subject, to. Address headers return a
list of (display_name, address) tuples.
Any other header is reached by replacing hyphens with underscores: mail.X_MSMail_Priority
reads X-MSMail-Priority. This convenience, and the _json / _raw suffixes, apply only to
attribute access written by you. Names read out of a message, the keys of mail and headers, are
looked up literally: a header genuinely named X_Spam_Flag or Subject_json keeps its own name
and its own value, and a header named like a method (Parse, Headers_json) is still a header.
Attribute names beginning with an underscore are not headers and raise AttributeError.
Computed components:
| Property | Content |
|---|---|
body |
The text parts (text_plain, then text_html, then text_not_managed) joined with --- mail_boundary --- lines. |
text_plain, text_html |
Lists of the plain-text and HTML body parts. HTML is returned as text, never rendered. |
text_not_managed |
Text parts of other subtypes. |
headers |
One key per header name as written, with its decoded value: address headers as (name, address) tuples (first occurrence), the others as a string, or a list when the header repeats. |
attachments |
One dict per attachment, see Attachments. |
received |
One dict per hop, see Delivery path. |
get_server_ipaddress(trust) |
The sender's IP as seen by the first Received header that contains trust, or None. Never falls back to older, forgeable hops. |
to_domains |
The recipient domains. |
timezone |
The offset of date from UTC in hours, as text ('+1.0'); 0 without a date. |
mime_tree |
One dict per MIME part, see Message structure. |
has_defects, defects, defects_categories |
The defect summary, see Defects. |
address_header_defects, received_header_defects, date_header_defects, header_decoding_defects, resource_limit_defects, parser_error_defects |
The structured diagnostics, always lists. |
mail, mail_json |
Everything above in one dict / JSON document (the structured diagnostics only when nonempty). |
mail_partial |
The same with the main headers only. |
message, message_as_string |
The underlying email.message.Message and the message flattened back to text. |
mail.subject removes folding CRLF followed by a space or tab
(RFC 5322 section 2.2.3) before
decoding encoded words; LF-only folds are accepted too. mail.subject_raw and mail.message
keep the original folding. If an encoded word cannot be decoded, the complete literal Subject is
kept and header_decoding_defects says why.
Each entry of mail.attachments is a dict:
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.