Skip to content

Commit

Permalink
chore(require): Use node: prefix when loading native packages
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Feb 23, 2024
1 parent fe6525c commit 11b1c99
Show file tree
Hide file tree
Showing 44 changed files with 240 additions and 155 deletions.
8 changes: 4 additions & 4 deletions bin/mailauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const os = require('os');
const assert = require('assert');
const os = require('node:os');
const assert = require('node:assert');

const commandReport = require('../lib/commands/report');
const commandSign = require('../lib/commands/sign');
Expand All @@ -14,8 +14,8 @@ const commandSpf = require('../lib/commands/spf');
const commandVmc = require('../lib/commands/vmc');
const commandBodyhash = require('../lib/commands/bodyhash');

const fs = require('fs');
const pathlib = require('path');
const fs = require('node:fs');
const pathlib = require('node:path');

const argv = yargs(hideBin(process.argv))
.command(
Expand Down
4 changes: 2 additions & 2 deletions examples/authenticate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { authenticate } = require('../lib/mailauth');
const dns = require('dns');
const dns = require('node:dns');

const fs = require('fs');
const fs = require('node:fs');

const main = async () => {
let message = await fs.promises.readFile(process.argv[2] || __dirname + '/../test/fixtures/message4.eml');
Expand Down
4 changes: 2 additions & 2 deletions examples/seal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { authenticate, sealMessage } = require('..');
const dns = require('dns');
const dns = require('node:dns');

const fs = require('fs');
const fs = require('node:fs');

const main = async () => {
let message = await fs.promises.readFile(process.argv[2] || __dirname + '/../test/fixtures/message4.eml');
Expand Down
5 changes: 3 additions & 2 deletions examples/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

// sends some crappy signed messages to Gmail for verification

const { promisify } = require('util');
const { Buffer } = require('node:buffer');
const { promisify } = require('node:util');
const MailComposer = require('nodemailer/lib/mail-composer');
const nodemailer = require('nodemailer');
const { dkimSign } = require('../lib/dkim/sign');
const fs = require('fs');
const fs = require('node:fs');

const transport = nodemailer.createTransport({
host: 'gmail-smtp-in.l.google.com',
Expand Down
4 changes: 2 additions & 2 deletions examples/sign-and-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// sign and verify:
// $ node sign-and-verify.js /path/to/message.eml

const fs = require('fs');

const fs = require('node:fs');
const { Buffer } = require('node:buffer');
const { dkimSign } = require('../lib/dkim/sign');
const { dkimVerify } = require('../lib/dkim/verify');

Expand Down
4 changes: 2 additions & 2 deletions examples/sign-l.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// sign and verify:
// $ node sign-and-verify.js /path/to/message.eml

const fs = require('fs');

const fs = require('node:fs');
const { Buffer } = require('node:buffer');
const { dkimSign } = require('../lib/dkim/sign');

let file = process.argv[2];
Expand Down
2 changes: 1 addition & 1 deletion examples/spf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { spf } = require('../lib/spf');
const util = require('util');
const util = require('node:util');

const main = async () => {
let tests = [
Expand Down
4 changes: 2 additions & 2 deletions examples/use-existing.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { authenticate } = require('../lib/mailauth');
const dns = require('dns');
const dns = require('node:dns');

const fs = require('fs');
const fs = require('node:fs');

const main = async () => {
let message = await fs.promises.readFile(process.argv[2] || __dirname + '/../test/fixtures/message4.eml');
Expand Down
3 changes: 2 additions & 1 deletion examples/verify-dkim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// verify signed message:
// $ node verify-dkim.js /path/to/message.eml

const fs = require('fs');
const fs = require('node:fs');
const { Buffer } = require('node:buffer');
const { dkimVerify } = require('../lib/dkim/verify');

let file = process.argv[2];
Expand Down
5 changes: 3 additions & 2 deletions examples/verify-mbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

const { eachMessage } = require('mbox-reader');

const fs = require('fs');
const fs = require('node:fs');
const { Buffer } = require('node:buffer');
const { dkimVerify } = require('../lib/dkim/verify');
const pathlib = require('path');
const pathlib = require('node:path');

let file = process.argv[2];
let mbox = fs.createReadStream(file);
Expand Down
3 changes: 2 additions & 1 deletion lib/arc/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { Buffer } = require('node:buffer');
const {
parseDkimHeaders,
formatRelaxedLine,
Expand All @@ -9,7 +10,7 @@ const {
writeToStream,
validateAlgorithm
} = require('../../lib/tools');
const crypto = require('crypto');
const crypto = require('node:crypto');
const { DkimSigner } = require('../dkim/dkim-signer');

const verifyAS = async (chain, opts) => {
Expand Down
5 changes: 3 additions & 2 deletions lib/bimi/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const crypto = require('crypto');
const dns = require('dns');
const { Buffer } = require('node:buffer');
const crypto = require('node:crypto');
const dns = require('node:dns');
const { formatAuthHeaderRow, parseDkimHeaders, formatDomain, getAlignment } = require('../tools');
const Joi = require('joi');
//const packageData = require('../../package.json');
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/bodyhash.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { DkimSigner } = require('../dkim/dkim-signer');
const { writeToStream } = require('../tools');
const fs = require('fs');
const fs = require('node:fs');

const cmd = async argv => {
let source = argv.email;
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const { authenticate } = require('../mailauth');
const fs = require('fs');
const { resolve } = require('dns').promises;
const fs = require('node:fs');
const { resolve } = require('node:dns').promises;

const cmd = async argv => {
let source = argv.email;
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/seal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

const { authenticate } = require('../mailauth');
const fs = require('fs');
const fs = require('node:fs');
const { GathererStream } = require('../gatherer-stream');
const { resolve } = require('dns').promises;
const { resolve } = require('node:dns').promises;

const cmd = async argv => {
let source = argv.email;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { dkimSign } = require('../dkim/sign');
const { GathererStream } = require('../gatherer-stream');
const fs = require('fs');
const fs = require('node:fs');

const cmd = async argv => {
let source = argv.email;
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/spf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const { spf } = require('../spf');
const fs = require('fs');
const { resolve } = require('dns').promises;
const fs = require('node:fs');
const { resolve } = require('node:dns').promises;

const cmd = async argv => {
let address = argv.sender;
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/vmc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { validateVMC } = require('../bimi');

const fs = require('fs').promises;
const fs = require('node:fs').promises;

const cmd = async argv => {
let bimiData = {};
Expand Down
3 changes: 2 additions & 1 deletion lib/dkim/body/relaxed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

'use strict';

const crypto = require('crypto');
const { Buffer } = require('node:buffer');
const crypto = require('node:crypto');
const { MimeStructureStartFinder } = require('../mime-structure-start-finder');

const CHAR_CR = 0x0d;
Expand Down
3 changes: 2 additions & 1 deletion lib/dkim/body/simple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const crypto = require('crypto');
const { Buffer } = require('node:buffer');
const crypto = require('node:crypto');
const { MimeStructureStartFinder } = require('../mime-structure-start-finder');

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/dkim/dkim-signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
const { MessageParser } = require('./message-parser');
const { dkimBody } = require('./body');
const { generateCanonicalizedHeader } = require('./header');
const crypto = require('crypto');
const crypto = require('node:crypto');

class DkimSigner extends MessageParser {
constructor(options) {
Expand Down
8 changes: 5 additions & 3 deletions lib/dkim/dkim-verifier.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const { Buffer } = require('node:buffer');
const { getSigningHeaderLines, getPublicKey, parseDkimHeaders, formatAuthHeaderRow, getAlignment, getCurTime } = require('../../lib/tools');
const { MessageParser } = require('./message-parser');
const { dkimBody } = require('./body');
const { generateCanonicalizedHeader } = require('./header');
const { getARChain } = require('../arc');
const addressparser = require('nodemailer/lib/addressparser');
const crypto = require('crypto');
const crypto = require('node:crypto');
const { v4: uuidv4 } = require('uuid');
const libmime = require('libmime');

Expand Down Expand Up @@ -324,8 +325,9 @@ class DkimVerifier extends MessageParser {
signatureHeader.sourceBodyLength = this.bodyHashes.get(signatureHeader.bodyHashKey)?.byteLength;

if (typeof signatureHeader.maxBodyLength === 'number' && signatureHeader.maxBodyLength !== signatureHeader.bodyHashedBytes) {
status.result = 'fail';
status.comment = `invalid body length ${signatureHeader.bodyHashedBytes}`;
console.log('TOTAL', signatureHeader.bodyHashedBytes, 'EXPECTING', signatureHeader.maxBodyLength);
//status.result = 'fail';
//status.comment = `invalid body length ${signatureHeader.bodyHashedBytes}`;
}

let result = {
Expand Down
1 change: 1 addition & 0 deletions lib/dkim/header/relaxed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { Buffer } = require('node:buffer');
const { formatSignatureHeaderLine, formatRelaxedLine, getCurTime } = require('../../../lib/tools');

// generate headers for signing
Expand Down
1 change: 1 addition & 0 deletions lib/dkim/header/simple.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { Buffer } = require('node:buffer');
const { formatSignatureHeaderLine, getCurTime } = require('../../../lib/tools');

const formatSimpleLine = (line, suffix) => Buffer.from(line.toString('binary') + (suffix ? suffix : ''), 'binary');
Expand Down
3 changes: 2 additions & 1 deletion lib/dkim/message-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

// Calculates relaxed body hash for a message body stream

const { Buffer } = require('node:buffer');
const { parseHeaders } = require('../../lib/tools');
const Writable = require('stream').Writable;
const Writable = require('node:stream').Writable;

/**
* Class for separating header from body
Expand Down
2 changes: 2 additions & 0 deletions lib/dkim/mime-structure-start-finder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { Buffer } = require('node:buffer');

class MimeStructureStartFinder {
constructor() {
this.byteCache = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/dmarc/get-dmarc-record.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const psl = require('psl');
const dns = require('dns').promises;
const dns = require('node:dns').promises;

const resolveTxt = async (domain, resolver) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/dmarc/verify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const dns = require('dns').promises;
const dns = require('node:dns').promises;
const punycode = require('punycode/');
const psl = require('psl');
const { formatAuthHeaderRow, getAlignment } = require('../tools');
Expand Down
3 changes: 2 additions & 1 deletion lib/gatherer-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { Transform, PassThrough } = require('stream');
const { Buffer } = require('node:buffer');
const { Transform, PassThrough } = require('node:stream');

class GathererStream extends Transform {
constructor(opts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mailauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { validateSvg: validateBimiSvg } = require('./bimi/validate-svg');
const { parseReceived } = require('./parse-received');
const { sealMessage } = require('./arc');
const libmime = require('libmime');
const os = require('os');
const os = require('node:os');
const { isIP } = require('net');

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/mta-sts.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const { Buffer } = require('node:buffer');
const punycode = require('punycode/');
const dns = require('dns');
const dns = require('node:dns');
const parseDkimHeaders = require('./parse-dkim-headers');
const https = require('https');
const https = require('node:https');

const HTTP_REQUEST_TIMEOUT = 15 * 1000;

Expand Down
4 changes: 2 additions & 2 deletions lib/spf/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const { spfVerify } = require('./spf-verify');
const os = require('os');
const dns = require('dns');
const os = require('node:os');
const dns = require('node:dns');
const libmime = require('libmime');
const Joi = require('joi');
const domainSchema = Joi.string().domain({ allowUnicode: false, tlds: false });
Expand Down
2 changes: 1 addition & 1 deletion lib/spf/macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const net = require('net');
const ipaddr = require('ipaddr.js');
const os = require('os');
const os = require('node:os');

/**
* Renders macro into an output string.
Expand Down
2 changes: 1 addition & 1 deletion lib/spf/spf-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const punycode = require('punycode/');
const net = require('net');
const macro = require('./macro');
const dns = require('dns').promises;
const dns = require('node:dns').promises;
const ipaddr = require('ipaddr.js');
const { getPtrHostname, formatDomain } = require('../tools');

Expand Down
7 changes: 4 additions & 3 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

'use strict';

const { Buffer } = require('node:buffer');
const punycode = require('punycode/');
const libmime = require('libmime');
const dns = require('dns').promises;
const crypto = require('crypto');
const https = require('https');
const dns = require('node:dns').promises;
const crypto = require('node:crypto');
const https = require('node:https');
const packageData = require('../package');
const parseDkimHeaders = require('./parse-dkim-headers');
const psl = require('psl');
Expand Down
Loading

0 comments on commit 11b1c99

Please sign in to comment.