mailauth 4.5.0 → 4.5.1

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/lib/bimi/index.js CHANGED
@@ -4,18 +4,19 @@ const crypto = require('crypto');
4
4
  const dns = require('dns');
5
5
  const { formatAuthHeaderRow, parseDkimHeaders, formatDomain, getAlignment } = require('../tools');
6
6
  const Joi = require('joi');
7
- const packageData = require('../../package.json');
7
+ //const packageData = require('../../package.json');
8
8
  const httpsSchema = Joi.string().uri({
9
9
  scheme: ['https']
10
10
  });
11
11
 
12
- const https = require('https');
13
- const http = require('http');
12
+ const FETCH_TIMEOUT = 5 * 1000;
13
+
14
+ const { fetch: fetchCmd, Agent } = require('undici');
15
+ const fetchAgent = new Agent({ connect: { timeout: FETCH_TIMEOUT } });
16
+
14
17
  const { vmc } = require('@postalsys/vmc');
15
18
  const { validateSvg } = require('./validate-svg');
16
19
 
17
- const HTTP_REQUEST_TIMEOUT = 15 * 1000;
18
-
19
20
  const lookup = async data => {
20
21
  let { dmarc, headers, resolver, bimiWithAlignedDkim } = data;
21
22
  let headerRows = (headers && headers.parsed) || [];
@@ -177,7 +178,7 @@ const lookup = async data => {
177
178
  return response;
178
179
  };
179
180
 
180
- const downloadPromise = (url, cachedFile) => {
181
+ const downloadPromise = async (url, cachedFile) => {
181
182
  if (cachedFile) {
182
183
  return cachedFile;
183
184
  }
@@ -186,76 +187,24 @@ const downloadPromise = (url, cachedFile) => {
186
187
  return false;
187
188
  }
188
189
 
189
- const parsedUrl = new URL(url);
190
-
191
- const options = {
192
- protocol: parsedUrl.protocol,
193
- host: parsedUrl.host,
190
+ let res = await fetchCmd(url, {
194
191
  headers: {
195
- host: parsedUrl.host,
196
- 'User-Agent': `mailauth/${packageData.version} (+${packageData.homepage}`
192
+ // Comment: AKAMAI does some strange UA based filtering that messes up the request
193
+ // 'User-Agent': `mailauth/${packageData.version} (+${packageData.homepage}`
197
194
  },
198
- servername: parsedUrl.hostname,
199
- port: 443,
200
- path: parsedUrl.pathname,
201
- method: 'GET',
202
- rejectUnauthorized: true,
203
-
204
- timeout: HTTP_REQUEST_TIMEOUT
205
- };
206
-
207
- return new Promise((resolve, reject) => {
208
- let protoHandler;
209
- switch (parsedUrl.protocol) {
210
- case 'https:':
211
- protoHandler = https;
212
- break;
213
- case 'http:':
214
- protoHandler = http;
215
- break;
216
- default:
217
- reject(new Error(`Unknown protocol ${parsedUrl.protocol}`));
218
- }
219
- const req = protoHandler.request(options, res => {
220
- let chunks = [],
221
- chunklen = 0;
222
- res.on('readable', () => {
223
- let chunk;
224
- while ((chunk = res.read()) !== null) {
225
- chunks.push(chunk);
226
- chunklen += chunk.length;
227
- }
228
- });
229
- res.on('end', () => {
230
- let data = Buffer.concat(chunks, chunklen);
231
- if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
232
- let err = new Error(`Invalid response code ${res.statusCode || '-'}`);
233
- err.code = 'http_status_' + (res.statusCode || 'na');
234
- if (res.headers.location && res.statusCode >= 300 && res.statusCode < 400) {
235
- err.redirect = {
236
- code: res.statusCode,
237
- location: res.headers.location
238
- };
239
- }
240
- return reject(err);
241
- }
242
- resolve(data);
243
- });
244
- res.on('error', err => reject(err));
245
- });
246
-
247
- req.on('timeout', () => {
248
- req.destroy(); // cancel request
249
- let error = new Error(`Request timeout for ${parsedUrl.href}`);
250
- error.code = 'HTTP_SOCKET_TIMEOUT';
251
- reject(error);
252
- });
253
-
254
- req.on('error', err => {
255
- reject(err);
256
- });
257
- req.end();
195
+ dispatcher: fetchAgent
258
196
  });
197
+
198
+ if (!res.ok) {
199
+ let error = new Error(`Request failed with status ${res.status}`);
200
+ error.code = 'HTTP_REQUEST_FAILED';
201
+ throw error;
202
+ }
203
+
204
+ let ab = await res.arrayBuffer();
205
+ process.stdout.write(Buffer.from(ab));
206
+
207
+ return Buffer.from(ab);
259
208
  };
260
209
 
261
210
  const validateVMC = async (bimiData, opts) => {
package/licenses.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  name license type link installed version author
2
2
  ---- ------------ ---- ----------------- ------
3
3
  @postalsys/vmc MIT https://registry.npmjs.org/@postalsys/vmc/-/vmc-1.0.6.tgz 1.0.6 Postal Systems OÜ
4
- fast-xml-parser MIT git+https://github.com/NaturalIntelligence/fast-xml-parser.git 4.2.6 Amit Gupta (https://amitguptagwl.github.io)
4
+ fast-xml-parser MIT git+https://github.com/NaturalIntelligence/fast-xml-parser.git 4.2.7 Amit Gupta (https://amitguptagwl.github.io)
5
5
  ipaddr.js MIT git://github.com/whitequark/ipaddr.js.git 2.1.0 whitequark <whitequark@whitequark.org>
6
6
  joi BSD-3-Clause git://github.com/hapijs/joi.git 17.9.2 n/a
7
7
  libmime MIT git://github.com/andris9/libmime.git 5.2.1 Andris Reinman <andris@kreata.ee>
package/man/mailauth.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH "MAILAUTH" "1" "July 2023" "v4.4.2" "Mailauth Help"
1
+ .TH "MAILAUTH" "1" "July 2023" "v4.5.0" "Mailauth Help"
2
2
  .SH "NAME"
3
3
  \fBmailauth\fR
4
4
  .QP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailauth",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "description": "Email authentication library for Node.js",
5
5
  "main": "lib/mailauth.js",
6
6
  "scripts": {
@@ -35,7 +35,7 @@
35
35
  "chai": "4.3.7",
36
36
  "eslint": "8.46.0",
37
37
  "eslint-config-nodemailer": "1.2.0",
38
- "eslint-config-prettier": "8.9.0",
38
+ "eslint-config-prettier": "8.10.0",
39
39
  "js-yaml": "4.1.0",
40
40
  "license-report": "6.4.0",
41
41
  "marked": "0.7.0",
@@ -53,6 +53,7 @@
53
53
  "nodemailer": "6.9.4",
54
54
  "psl": "1.9.0",
55
55
  "punycode": "2.3.0",
56
+ "undici": "5.23.0",
56
57
  "yargs": "17.7.2"
57
58
  },
58
59
  "engines": {