Download the PHP package avvertix/dmarc-report-parser without Composer
On this page you can find all versions of the php package avvertix/dmarc-report-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download avvertix/dmarc-report-parser
More information about avvertix/dmarc-report-parser
Files in avvertix/dmarc-report-parser
Package dmarc-report-parser
Short Description Parse DMARC xml reports
License MIT
Homepage https://github.com/avvertix/dmarc-report-parser
Informations about the package dmarc-report-parser
DMARC Report Parser
DMARC Report Parser is designed to simplify the analysis of DMARC (Domain-based Message Authentication, Reporting & Conformance) reports:
- Parse the XML-based report into fully typed classes
- Read reports from GZip/Zip files without decompressing first
- Support both RFC 7489 and RFC 9990
Installation
You can install the package via composer:
Require PHP 8.3 with xsl and sodium extensions.
Usage
It is possible to parse reports from XML files or strings. The output is fully typed instance of DmarcReport.
from file
See the DmarcReport class below for the full structure.
You can pass directly zip or gzip compressed reports. It is assumed that the XML report file is the first file in the compressed archive.
When working with compressed reports we cap expansion at 10MB by default. An archive that expands past the cap
throws Avvertix\DmarcReportParser\Exception\DecompressionLimitException. If necessary you can adjust the
expansion limit by providing a ParserConfiguration.
from string
Reading the authentication results of every record, which is what most of a report is about:
DmarcReport class
The DmarcReport class represent the report in a fully typed manner.
A few differences with respect to the spec:
- Report generator metadata are directly accessible from the
DmarcReportclass and not encapsulated in an object - Records are exposed using the
records(array) property - When the spec report an element to be available multiple times we represent it as an array property
Two things catch people out: the published policy is publishedPolicy, in camel case, while every
other property is snake case to match the XML; and the override reasons in PolicyEvaluated property is reasons, plural, because a record may carry more than one.
Common questions to ask a report
Reading a report filename
RFC 9990 standardizes the attachment filename, which yields the policy domain and the reporting window without decompressing or parsing anything:
In case the attachment filename is not following the convention the parse() method returns null.
RFC 7489 vs RFC 9990
DMARC was originally defined in RFC 7489.
RFC 9990 revises it.
The DmarcReport supports both definitions without indicating if a report satisfy one or the other version
as it is possible that sender will take time to move to the new RFC.
Elements RFC 9990 adds are nullable, indicating that the report did not carry them:
| Property | Element | Type |
|---|---|---|
DmarcReport::$generator |
report_metadata/generator |
?string |
DmarcReport::$extensions |
feedback/extension |
list<Extension>, empty when absent |
Policy::$discovery_method |
policy_published/discovery_method |
?DiscoveryMethod — psl or treewalk |
Policy::$testing |
policy_published/testing |
?TestingMode — the t tag, y or n |
Policy::$np |
policy_published/np |
?DispositionType |
Record::$extensions |
namespaced elements after auth_results |
list<Extension>, empty when absent |
RFC 9990 deprecate or remove few fields and values. Other behaviour worth knowing:
Policy::$pctstays nullable. RFC 9990 removes thepctelement, but RFC 7489-era reports carry it.DkimAuthResult::$selectorstays nullable. RFC 9990 makes it mandatory; RFC 7489 did not, and real reports from that era omit it.AuthResult::$spfmay be an empty array. RFC 9990 makes thespfelement optional.DispositionTypegained aPASScase. RFC 9990 allowspassinpolicy_evaluated/disposition, though never in a published policy.PolicyOverrideTypekeepsFORWARDEDandSAMPLED_OUT, which RFC 9990 removed, and gainedPOLICY_TEST_MODE. An unrecognised value becomesUNKNOWNinstead of throwing, as do unrecognisedDiscoveryMethodandTestingModevalues, so a later revision adding one does not break parsing.report_idis never rejected. RFC 9990 gives it an ABNF, but malformed identifiers are common and the raw value always reaches the caller.
Testing
DMARC Report Parser is covered in unit test. The PestPHP framework is used. To run the whole test suite execute the test script.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Alessio Vertemati
- All Contributors
License
The MIT License (MIT). Please see License File for more information.