tsdmarc 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +201 -0
- package/NOTICE +61 -0
- package/README.md +137 -2
- package/dist/index.d.ts +2700 -0
- package/dist/index.js +3146 -0
- package/dist/index.js.map +1 -0
- package/dist/parallel-worker.d.ts +1 -0
- package/dist/parallel-worker.js +42 -0
- package/dist/parallel-worker.js.map +1 -0
- package/dist/report-file-C6u0I5I1.js +27271 -0
- package/dist/report-file-C6u0I5I1.js.map +1 -0
- package/package.json +92 -3
- package/resources/base_reverse_dns_map.csv +38629 -0
- package/resources/known_unknown_base_reverse_dns.txt +31882 -0
- package/resources/psl_overrides.txt +298 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# tsdmarc
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- a1c5fad: First release: a 1:1 TypeScript port of parsedmarc 11.2.1 and of the parts of mailsuite 2.3.4 it uses, for Node.js 24+, Bun and Deno.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [a1c5fad]
|
|
12
|
+
- @tsdmarc/ipinfo-lite@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
tsdmarc
|
|
2
|
+
Copyright 2026 tsdmarc contributors
|
|
3
|
+
|
|
4
|
+
This product is a TypeScript port of parsedmarc
|
|
5
|
+
(https://github.com/domainaware/parsedmarc), Copyright Sean Whalen and
|
|
6
|
+
parsedmarc contributors, licensed under the Apache License, Version 2.0.
|
|
7
|
+
Ported from parsedmarc 11.2.1, commit 7bbc405c01a1c4c37811b2a3746e8881c00cda39.
|
|
8
|
+
|
|
9
|
+
The mailbox connection and SMTP code is a port of mailsuite
|
|
10
|
+
(https://github.com/seanthegeek/mailsuite), Copyright Sean Whalen,
|
|
11
|
+
licensed under the Apache License, Version 2.0.
|
|
12
|
+
Ported from mailsuite 2.3.4, commit 3bd62831d137c9aa7884be33b83323ca3a1bd1de.
|
|
13
|
+
|
|
14
|
+
All source files were translated from Python to TypeScript; this is a
|
|
15
|
+
modification of the original works within the meaning of section 4(b) of
|
|
16
|
+
the Apache License.
|
|
17
|
+
|
|
18
|
+
Third-party data files in resources/:
|
|
19
|
+
- ipinfo_lite.mmdb: IPinfo Lite, (c) IPinfo (https://ipinfo.io/lite),
|
|
20
|
+
licensed under CC BY-SA 4.0.
|
|
21
|
+
- base_reverse_dns_map.csv: from parsedmarc, derived in part from IPinfo
|
|
22
|
+
Lite data, licensed under CC BY-SA 4.0.
|
|
23
|
+
|
|
24
|
+
Ported third-party code in packages/tsdmarc/src (behavior reimplemented in
|
|
25
|
+
TypeScript to reproduce parsedmarc's output exactly):
|
|
26
|
+
- xml/expat.ts, xml/expat-names.ts: port of parts of Expat 2.9.0
|
|
27
|
+
(https://libexpat.github.io/), Copyright (c) 1997-2000 Thai Open Source
|
|
28
|
+
Software Center Ltd and Copyright (c) 2000-2026 Expat development team,
|
|
29
|
+
licensed under the MIT License.
|
|
30
|
+
- xml/xmltodict.ts: port of xmltodict (https://github.com/martinblech/xmltodict),
|
|
31
|
+
Copyright (c) 2012 Martin Blech, licensed under the MIT License.
|
|
32
|
+
- xml/recover.ts: emulates the observable recovery behavior of libxml2
|
|
33
|
+
(https://gitlab.gnome.org/GNOME/libxml2), MIT License.
|
|
34
|
+
- utils/py-email/, utils/py-codecs*.ts, utils/py-binascii.ts, utils/py-str.ts,
|
|
35
|
+
csv.ts, utils/csv-reader.ts, utils/url-split.ts: ports of parts of the
|
|
36
|
+
CPython standard library (https://github.com/python/cpython), Copyright (c)
|
|
37
|
+
2001 Python Software Foundation, licensed under the PSF License Agreement.
|
|
38
|
+
- utils/mailparser/: port of mail-parser 4.8.0
|
|
39
|
+
(https://github.com/SpamScope/mail-parser), Copyright Fedele Mantuano,
|
|
40
|
+
licensed under the Apache License, Version 2.0.
|
|
41
|
+
- utils/dns*.ts: port of parts of dnspython (https://www.dnspython.org/),
|
|
42
|
+
Copyright (c) Dnspython Contributors, licensed under the ISC License.
|
|
43
|
+
- utils/timestamps.ts: date parsing compatible with python-dateutil
|
|
44
|
+
(https://github.com/dateutil/dateutil), Apache License 2.0 / BSD 3-Clause.
|
|
45
|
+
- internal/zipfile.ts and the decompressor wrappers in internal/bz2.ts,
|
|
46
|
+
internal/lzma.ts, internal/zstd.ts and internal/zlib.ts: ports of parts of
|
|
47
|
+
the CPython standard library (zipfile, bz2, lzma, compression.zstd, zlib
|
|
48
|
+
modules), Copyright (c) 2001 Python Software Foundation, licensed under the
|
|
49
|
+
PSF License Agreement.
|
|
50
|
+
- internal/zlib.ts: port of the inflate code of zlib 1.3 (https://zlib.net/),
|
|
51
|
+
Copyright (C) 1995-2023 Jean-loup Gailly and Mark Adler, licensed under the
|
|
52
|
+
zlib License.
|
|
53
|
+
- internal/bz2.ts: port of the libbzip2 1.0.8 decompressor
|
|
54
|
+
(https://sourceware.org/bzip2/), Copyright (C) 1996-2019 Julian R Seward,
|
|
55
|
+
licensed under the bzip2 license (BSD-style).
|
|
56
|
+
- internal/lzma.ts: port of the LZMA1 decoder of liblzma 5.8
|
|
57
|
+
(https://tukaani.org/xz/), by Igor Pavlov and Lasse Collin, licensed under
|
|
58
|
+
the BSD Zero Clause License (0BSD).
|
|
59
|
+
- internal/zstd.ts: port of the libzstd 1.5.7 decoder
|
|
60
|
+
(https://github.com/facebook/zstd), Copyright (c) Meta Platforms, Inc. and
|
|
61
|
+
affiliates, licensed under the BSD 3-Clause License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tsdmarc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DMARC report parser for Node.js, Bun and Deno: parses DMARC aggregate (RUA) reports, DMARC failure (RUF, formerly "forensic") reports and SMTP TLS (TLS-RPT) reports, enriches them with GeoIP, reverse DNS and base-domain data, and writes parsedmarc-compatible JSON and CSV.
|
|
4
|
+
|
|
5
|
+
This is the core package of [tsdmarc](https://github.com/helixnebulatech/tsdmarc#readme), a 1:1 TypeScript port of [parsedmarc](https://github.com/domainaware/parsedmarc) 11.2.1. Its output is checked against reference fixtures generated by parsedmarc itself.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install tsdmarc
|
|
11
|
+
# optional: the IPinfo Lite database (~25 MB), for GeoIP without downloads
|
|
12
|
+
npm install @tsdmarc/ipinfo-lite
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Node.js ≥ 24, Bun or Deno 2. ESM only.
|
|
16
|
+
|
|
17
|
+
## Parse a report file
|
|
18
|
+
|
|
19
|
+
`parseReportFile()` accepts a path, bytes or a stream, and detects the format: aggregate XML (plain, zip or gzip), SMTP TLS JSON, or a report email (`.eml`, including failure reports).
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
parsedAggregateReportsToCsv,
|
|
24
|
+
parseReportFile,
|
|
25
|
+
pyJsonDumps,
|
|
26
|
+
toSnakeCaseKeys,
|
|
27
|
+
} from 'tsdmarc';
|
|
28
|
+
|
|
29
|
+
const parsed = await parseReportFile('report.xml.gz', { offline: true });
|
|
30
|
+
|
|
31
|
+
if (parsed.reportType === 'aggregate') {
|
|
32
|
+
const { reportMetadata, policyPublished, records } = parsed.report;
|
|
33
|
+
console.log(reportMetadata.orgName, policyPublished.domain, records.length);
|
|
34
|
+
console.log(parsedAggregateReportsToCsv(parsed.report));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// parsedmarc's JSON: snake_case keys, big integers written exactly
|
|
38
|
+
console.log(pyJsonDumps(toSnakeCaseKeys(parsed), { indent: 2 }));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`parsed.reportType` is `'aggregate'`, `'failure'` or `'smtp_tls'`, and `parsed.report` is typed accordingly (`AggregateReport`, `FailureReport`, `SMTPTLSReport`).
|
|
42
|
+
|
|
43
|
+
## Process a mailbox
|
|
44
|
+
|
|
45
|
+
`getDmarcReportsFromMailbox()` reads every message in a folder, parses the reports, and moves the messages to `Archive/Aggregate`, `Archive/Failure`, `Archive/SMTP-TLS` or `Archive/Invalid`. `MaildirConnection` is in this package; IMAP, Gmail and Microsoft Graph are in `@tsdmarc/imap`, `@tsdmarc/gmail` and `@tsdmarc/msgraph`.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import {
|
|
49
|
+
getDmarcReportsFromMailbox,
|
|
50
|
+
MaildirConnection,
|
|
51
|
+
saveOutput,
|
|
52
|
+
} from 'tsdmarc';
|
|
53
|
+
|
|
54
|
+
const connection = new MaildirConnection('/var/mail/dmarc');
|
|
55
|
+
try {
|
|
56
|
+
const results = await getDmarcReportsFromMailbox(connection, {
|
|
57
|
+
archiveFolder: 'Archive',
|
|
58
|
+
batchSize: 10,
|
|
59
|
+
});
|
|
60
|
+
// aggregate.json, aggregate.csv, failure.json, failure.csv,
|
|
61
|
+
// smtp_tls.json, smtp_tls.csv
|
|
62
|
+
await saveOutput(results, { outputDirectory: 'output' });
|
|
63
|
+
} finally {
|
|
64
|
+
await connection.close();
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`watchInbox(connection, callback, options)` keeps watching the folder (IMAP IDLE or polling) and calls `callback(results)` for each batch; pass `signal` (an `AbortSignal`) to stop it.
|
|
69
|
+
|
|
70
|
+
## Parser options
|
|
71
|
+
|
|
72
|
+
Every parsing function (`parseReportFile`, `parseReportEmail`, `parseAggregateReportXml`, `getDmarcReportsFromMailbox`, `watchInbox`, ...) accepts these options, or a `config` built once with `createParserConfig()`:
|
|
73
|
+
|
|
74
|
+
| Option | Default | Description |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `offline` | `false` | No DNS queries and no downloads. GeoIP still works with a local database. |
|
|
77
|
+
| `ipDbPath` | `null` | Path to an MMDB file (IPinfo, MaxMind or DB-IP). |
|
|
78
|
+
| `alwaysUseLocalFiles` | `false` | Use the bundled reverse DNS map and PSL overrides instead of downloading them. |
|
|
79
|
+
| `reverseDnsMapPath` / `reverseDnsMapUrl` | `null` | A custom reverse DNS map (file or URL). |
|
|
80
|
+
| `nameservers` | `null` | DNS servers (plain IPs, `https://` for DoH, `tls://` for DoT). `null`: Cloudflare. |
|
|
81
|
+
| `dnsTimeout` | `2.0` | DNS query timeout, in seconds. |
|
|
82
|
+
| `dnsRetries` | `0` | Retries after a DNS timeout or transient error. |
|
|
83
|
+
| `stripAttachmentPayloads` | `false` | Remove attachment payloads from failure report samples. |
|
|
84
|
+
| `normalizeTimespanThresholdHours` | `24` | Aggregate records spanning more hours are split into daily buckets. |
|
|
85
|
+
| `maxEmailSize` | 50 MiB | Largest email accepted (`0`: no limit). Not in parsedmarc. |
|
|
86
|
+
| `maxMimeParts` | `10000` | Most MIME boundary lines accepted (`0`: no limit). Not in parsedmarc. |
|
|
87
|
+
| `maxHeaderLines` | `100000` | Most header lines in an email, over all its parts (`0`: no limit). Not in parsedmarc. |
|
|
88
|
+
| `maxExpandedEmailSize` | 512 MiB | Most text, in characters (twice for text beyond Latin-1), re-serializing one email's parts may produce (`0`: no limit). Not in parsedmarc. |
|
|
89
|
+
| `maxNormalizedRecords` | `250000` | Most records of an aggregate report once split into daily buckets (`0`: no limit). Not in parsedmarc. |
|
|
90
|
+
| `maxXmlDepth` / `maxXmlNodes` | `100000` / `5000000` | Deepest nesting, and most elements and attributes, in an aggregate report's XML (`0`: no limit). Not in parsedmarc. |
|
|
91
|
+
| `maxSmtpTlsReportSize` | 10 MiB | Largest SMTP TLS report JSON (`0`: no limit). Not in parsedmarc. |
|
|
92
|
+
| `maxLookupsPerReport` / `maxFailedLookupsPerReport` / `maxLookupTimePerReport` | `100000` / `256` / `600` | Network lookups, failed reverse DNS lookups, and seconds of lookups, per aggregate report; past any of them, the remaining IPs only get the IP database (`0`: no limit). Not in parsedmarc. |
|
|
93
|
+
| `jobTimeout` | `3600` | Seconds one email or file may take to parse (`0`: no limit). Not in parsedmarc. |
|
|
94
|
+
| `maxWorkerHeapMb` | `2048` | Heap limit of each parsing worker, in MiB (`0`: the runtime's). Not in parsedmarc. |
|
|
95
|
+
|
|
96
|
+
## GeoIP
|
|
97
|
+
|
|
98
|
+
IP lookups use, in this order: `ipDbPath`; the database chosen by `loadIpDb()`; the `@tsdmarc/ipinfo-lite` package when installed. `loadIpDb()` (what the `tsdmarc` CLI calls at startup) downloads the latest IPinfo Lite database into a per-user cache directory and falls back to the cached or bundled copy when offline. `await configureIpinfoApi(token)` makes the IPinfo Lite REST API the primary source, falling back to the database on errors.
|
|
99
|
+
|
|
100
|
+
## API overview
|
|
101
|
+
|
|
102
|
+
All exports are named exports of `tsdmarc`. Types are exported too (`AggregateReport`, `FailureReport`, `SMTPTLSReport`, `ParsingResults`, `ParserConfig`, ...).
|
|
103
|
+
|
|
104
|
+
- **Parsing:** `parseReportFile`, `parseReportEmail`, `parseAggregateReportXml`, `parseAggregateReportFile`, `parseAggregateReportFromFilePath`, `parseFailureReport`, `parseSmtpTlsReportJson`, `extractReport`, `getDmarcReportsFromMbox`
|
|
105
|
+
- **CSV:** `parsedAggregateReportsToCsv`, `parsedFailureReportsToCsv`, `parsedSmtpTlsReportsToCsv` (and `...ToCsvRows`), `rowsToCsv`, `CsvDictWriter`
|
|
106
|
+
- **Files:** `saveOutput`, `appendJson`, `appendCsv`, `getReportZip`
|
|
107
|
+
- **Mailboxes:** `MailboxConnection` (base class), `MaildirConnection`, `getDmarcReportsFromMailbox`, `watchInbox`
|
|
108
|
+
- **Outputs without an SDK:** `HECClient` (Splunk), `LokiClient` (Grafana Loki push API; throws `LokiError` when a push fails, redirects are not followed), `SyslogClient`, `GelfClient`, `WebhookClient` (pass `throwOnError: true` to throw on network errors, timeouts and non-2xx responses instead of logging them, as the CLI does)
|
|
109
|
+
- **Enrichment:** `getIpAddressInfo`, `loadIpDb`, `configureIpinfoApi`, `loadReverseDnsMap`, `getReverseDns`, `queryDns`, `reverseNameFromAddress`, `getBaseDomain`
|
|
110
|
+
- **Log safety:** `sanitizeForLog`, `redactUrlCredentials` (masks URL passwords as `user:***@`), `maskNameserverSecrets`
|
|
111
|
+
- **Parallel parsing:** `parallelMap`, `parseReportFileTask`, `parseReportEmailTask` (worker threads)
|
|
112
|
+
- **Serialization:** `toSnakeCaseKeys`, `toCamelCaseKeys`, `pyJsonDumps`
|
|
113
|
+
- **Logging:** `logger`, `configureLogging`, `captureLogs`, Python-style levels (`DEBUG`, `INFO`, ...)
|
|
114
|
+
- **Errors:** `ParserError`, `InvalidDMARCReport`, `InvalidAggregateReport`, `InvalidFailureReport`, `InvalidSMTPTLSReport`, `EmailTooLargeError`, `EnrichmentError` (`InvalidIPinfoAPIKey`, `IPDatabaseError`), `PrivilegeDropError`, `SyslogError`, `GelfError`, `JobTimeoutError`, `WorkerCrashedError`
|
|
115
|
+
|
|
116
|
+
Backward-compatible aliases kept from parsedmarc (`parseForensicReport`, `InvalidForensicReport`, `parsedForensicReportsToCsv`) are exported as well.
|
|
117
|
+
|
|
118
|
+
## camelCase in, snake_case out
|
|
119
|
+
|
|
120
|
+
Report objects use camelCase keys (`report.reportMetadata.orgName`). Every output (JSON and CSV files, Splunk, Loki, syslog, GELF, webhook, and the `@tsdmarc/*` outputs) uses parsedmarc's snake_case names, so existing dashboards and queries keep working. Convert a report yourself with `toSnakeCaseKeys()`.
|
|
121
|
+
|
|
122
|
+
## Other packages
|
|
123
|
+
|
|
124
|
+
| Package | For |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| [`@tsdmarc/cli`](https://www.npmjs.com/package/@tsdmarc/cli) | The `tsdmarc` command (parsedmarc-compatible INI config) |
|
|
127
|
+
| [`@tsdmarc/imap`](https://www.npmjs.com/package/@tsdmarc/imap), [`@tsdmarc/gmail`](https://www.npmjs.com/package/@tsdmarc/gmail), [`@tsdmarc/msgraph`](https://www.npmjs.com/package/@tsdmarc/msgraph) | Mailbox connections |
|
|
128
|
+
| [`@tsdmarc/smtp`](https://www.npmjs.com/package/@tsdmarc/smtp) | Email the results |
|
|
129
|
+
| [`@tsdmarc/elasticsearch`](https://www.npmjs.com/package/@tsdmarc/elasticsearch), [`@tsdmarc/opensearch`](https://www.npmjs.com/package/@tsdmarc/opensearch), [`@tsdmarc/postgres`](https://www.npmjs.com/package/@tsdmarc/postgres), [`@tsdmarc/kafka`](https://www.npmjs.com/package/@tsdmarc/kafka), [`@tsdmarc/s3`](https://www.npmjs.com/package/@tsdmarc/s3), [`@tsdmarc/loganalytics`](https://www.npmjs.com/package/@tsdmarc/loganalytics) | Outputs |
|
|
130
|
+
| [`@tsdmarc/ipinfo-lite`](https://www.npmjs.com/package/@tsdmarc/ipinfo-lite) | Offline GeoIP database |
|
|
131
|
+
|
|
132
|
+
Differences from parsedmarc (security hardening, size limits, camelCase API, ...) are listed in [architecture/README.md](https://github.com/helixnebulatech/tsdmarc/blob/main/architecture/README.md#differences-from-parsedmarc).
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
Part of [tsdmarc](https://github.com/helixnebulatech/tsdmarc#readme), a TypeScript port of [parsedmarc](https://github.com/domainaware/parsedmarc). Licensed under Apache-2.0.
|
|
137
|
+
|
|
138
|
+
Created by [HelixNebula](https://helixnebula.tech).
|