Skip to content

parsedmarc.parser ๐Ÿ”—

InvalidAggregateReport ๐Ÿ”—

Bases: InvalidDMARCReport

Raised when an invalid DMARC aggregate report is encountered

InvalidDMARCReport ๐Ÿ”—

Bases: ParserError

Raised when an invalid DMARC report is encountered

InvalidForensicReport ๐Ÿ”—

Bases: InvalidDMARCReport

Raised when an invalid DMARC forensic report is encountered

ParserError ๐Ÿ”—

Bases: RuntimeError

Raised whenever the parser fails for some reason

ReportParser ๐Ÿ”—

ReportParser(
    offline: bool = False,
    ip_db_path: str | None = None,
    nameservers: list[str] | None = None,
    dns_timeout: float = 2.0,
    strip_attachment_payloads: bool = False,
)

Report Parser

Parses reports from messages and files.

Can handled the following types of reports:

  • DMARC
    • Aggregate
    • Forensic

New in 9.0.

Args: offline: ip_db_path: nameservers: dns_timeout: strip_attachment_payloads: Remove attachment payloads from forensic report results

parse_aggregate_report_file ๐Ÿ”—

parse_aggregate_report_file(
    source: bytes | str | BinaryIO,
    keep_alive: Callable | None = None,
) -> AggregateReport

Parse a file at the given path, a file-like object. or bytes as an aggregate DMARC report

PARAMETER DESCRIPTION
source

A path to a file, a file like object, or bytes

TYPE: bytes | str | BinaryIO

keep_alive

Keep alive function

TYPE: Callable | None DEFAULT: None

RETURNS DESCRIPTION
AggregateReport

The parsed DMARC aggregate report

parse_aggregate_report_xml ๐Ÿ”—

parse_aggregate_report_xml(
    xml: str, keep_alive: Callable | None = None
) -> AggregateReport

Parses a DMARC XML report string and returns an AggregateReport

PARAMETER DESCRIPTION
xml

A string of DMARC aggregate report XML

TYPE: str

keep_alive

Keep alive function

TYPE: Callable | None DEFAULT: None

RETURNS DESCRIPTION
AggregateReport

The parsed aggregate DMARC report

parse_forensic_report ๐Ÿ”—

parse_forensic_report(
    feedback_report: str, sample: str, msg_date: datetime
) -> ForensicReport

Converts a DMARC forensic report and sample to a ForensicReport

PARAMETER DESCRIPTION
feedback_report

A message's feedback report as a string

TYPE: str

sample

The RFC 822 headers or RFC 822 message sample

TYPE: str

msg_date

The message's date header

TYPE: datetime

RETURNS DESCRIPTION
ForensicReport

A parsed report and sample

parse_report_email ๐Ÿ”—

parse_report_email(
    source: bytes | str, keep_alive: Callable | None = None
) -> Report

Parse a DMARC report from an email

PARAMETER DESCRIPTION
source

An emailed DMARC report in RFC 822 format, as bytes or a string

TYPE: bytes | str

keep_alive

keep alive function

TYPE: Callable | None DEFAULT: None

RETURNS DESCRIPTION
Report

the report parsed from the email

parse_report_file ๐Ÿ”—

parse_report_file(
    source: str | bytes | BinaryIO,
    keep_alive: Callable | None = None,
) -> Report

Parse a DMARC aggregate or forensic file at the given path, a file-like object. or bytes

PARAMETER DESCRIPTION
source

A path to a file, a file like object, or bytes

TYPE: str | bytes | BinaryIO

keep_alive

Keep alive function

TYPE: Callable | None DEFAULT: None

RETURNS DESCRIPTION
Report

The parsed DMARC report