From 027b1bac39584abec813df660581e54a379f7ca9 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 15 May 2024 11:34:30 -0700 Subject: [PATCH] style: prefix node libs, arrow fns (#3359) - prefix node libs with `node:` - conn: replace a fn with arrow function - contrib/plugin2npm.sh: fix path to package.json - config/plugins: consistent formatting - fix(mf.resolv): this -> plugin, fixes #3361 --- .github/workflows/coverage.yml | 2 +- Changes.md | 3 ++ bin/haraka | 12 ++--- config/plugins | 71 +++++++++++++------------ connection.js | 20 ++++--- contrib/plugin2npm.sh | 3 +- endpoint.js | 2 +- host_pool.js | 2 +- line_socket.js | 2 +- logger.js | 4 +- outbound/fsync_writestream.js | 2 +- outbound/hmail.js | 8 +-- outbound/index.js | 4 +- outbound/qfile.js | 2 +- outbound/queue.js | 6 +-- outbound/tls.js | 7 +-- package.json | 12 ++--- plugins.js | 25 +++++---- plugins/auth/auth_base.js | 2 +- plugins/auth/auth_vpopmaild.js | 2 +- plugins/block_me.js | 2 +- plugins/data.signatures.js | 6 +-- plugins/early_talker.js | 3 +- plugins/mail_from.is_resolvable.js | 4 +- plugins/queue/qmail-queue.js | 4 +- plugins/queue/quarantine.js | 4 +- plugins/queue/smtp_forward.js | 2 +- plugins/queue/test.js | 4 +- plugins/relay.js | 13 +++-- plugins/reseed_rng.js | 2 +- plugins/status.js | 5 +- plugins/xclient.js | 5 +- server.js | 17 +++--- smtp_client.js | 15 +++--- test/endpoint.js | 4 +- test/fixtures/line_socket.js | 2 +- test/outbound/hmail.js | 6 +-- test/outbound_bounce_rfc3464.js | 4 +- test/plugins/mail_from.is_resolvable.js | 2 +- test/plugins/tls.js | 6 +-- test/server.js | 2 +- test/transaction.js | 5 +- transaction.js | 2 +- 43 files changed, 156 insertions(+), 154 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b8411d1aa..57ac96042 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -33,4 +33,4 @@ jobs: - name: Coveralls uses: coverallsapp/github-action@master with: - github-token: ${{ secrets.github_token }} + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Changes.md b/Changes.md index c0dc00140..819b63628 100644 --- a/Changes.md +++ b/Changes.md @@ -8,17 +8,20 @@ #### Changed +- prefix node libs with 'node:' #3359 - .gitignore: add config/me and config/*.pem - auth_base: enable disabling constrain_sender at runtime #3298 - auth_base: skip constrain_sender when auth user has no domain #3319 - avg: repackaged as NPM module #3347 - bounce: repackaged plugin as NPM module #3341 - clamd: repackaged plugin as NPM module +- config/plugins: consistent formatting #3359 - connection: check remote is connected before queue #3338 - improve log message for queue* hooks, fixes #2998 - support IPv6 when setting remote.is_private #3295 - in setTLS, replace forEach with for...of - NOTE: remove a handful of 3.0 sunset property names #3315 +- contrib/plugin2npm.sh: fix path to package.json #3359 - deps: bump all versions to latest #3303, #3344 - dkim: repackaged as NPM module #3311 - esets: repackaged as NPM module #3353 diff --git a/bin/haraka b/bin/haraka index fb1b8f493..1ab666ece 100755 --- a/bin/haraka +++ b/bin/haraka @@ -3,13 +3,13 @@ // this script takes inspiration from: // https://github.com/tnantoka/LooseLeaf/blob/master/bin/looseleaf -const child = require('child_process'); -const fs = require('fs'); -const net = require('net'); -const nopt = require('nopt'); -const path = require('path'); -const os = require('os'); +const child = require('node:child_process'); +const fs = require('node:fs'); +const net = require('node:net'); +const path = require('node:path'); +const os = require('node:os'); +const nopt = require('nopt'); const utils = require('haraka-utils'); const sprintf = require('sprintf-js').sprintf; const base = path.join(__dirname, '..'); diff --git a/config/plugins b/config/plugins index 6f18dd294..f2ebee677 100644 --- a/config/plugins +++ b/config/plugins @@ -1,71 +1,72 @@ # This file lists plugins that Haraka will run # # Plugin ordering often matters, run 'haraka -o -c /path/to/haraka/config' -# to see the order plugins (and their hooks) will run in. +# to see the order plugins (and their hooks) will run. # -# To see a list of all plugins, run 'haraka -l' +# To see a list of installed plugins, run 'haraka -l' # -# To see the help docs for a particular plugin, run 'haraka -h plugin.name' +# The plugin registry: https://github.com/haraka/Haraka/blob/master/Plugins.md +# +# To see the docs for a plugin, run 'haraka -h plugin.name' -#status -#process_title -# Log to syslog (see 'haraka -h syslog') +# status +# process_title # syslog +# watch # CONNECT -#toobusy -#karma -#relay -# control which IPs, rDNS hostnames, HELO hostnames, MAIL FROM addresses, and -# RCPT TO address you accept mail from. See 'haraka -h access'. +# ---------- +# toobusy +# karma +# relay # access # p0f # geoip # asn # fcrdns -# block & allow lists (see config/dns-list.ini) -dns-list +# dns-list # HELO -#early_talker -# see config/helo.checks.ini for configuration -helo.checks -# see 'haraka -h tls' for config instructions before enabling! +# ---------- +# early_talker +# helo.checks +# see 'haraka -h tls' before enabling! # tls # # AUTH plugins require TLS before AUTH is advertised, see # https://github.com/haraka/Haraka/wiki/Require-SSL-TLS +# ---------- # auth/flat_file # auth/auth_proxy # auth/auth_ldap # MAIL FROM -# Only accept mail where the MAIL FROM domain is resolvable to an MX record +# ---------- mail_from.is_resolvable -#spf +# spf # RCPT TO -# At least one rcpt_to plugin is REQUIRED for inbound email. The simplest -# plugin is in_host_list, see 'haraka -h rcpt_to.in_host_list' to configure. +# ---------- +# At least one rcpt_to plugin is REQUIRED for inbound email. rcpt_to.in_host_list -#qmail-deliverable -#rcpt_to.ldap -#rcpt_to.routes +# qmail-deliverable +# rcpt_to.ldap +# rcpt_to.routes # DATA -#bounce -# Check mail headers are valid -headers -#uribl -#attachment -#clamd -#spamassassin -#dkim -#limit +# ---------- +# attachment +# bounce +# clamd +# dkim +# headers +# limit +# rspamd +# spamassassin +# uribl # QUEUE +# ---------- # queues: discard qmail-queue quarantine smtp_forward smtp_proxy # Queue mail via smtp - see config/smtp_forward.ini for where your mail goes queue/smtp_forward - -#watch diff --git a/connection.js b/connection.js index 2b4cf446b..ef70e0f2c 100644 --- a/connection.js +++ b/connection.js @@ -1,10 +1,9 @@ 'use strict'; // a single connection -// node.js built-in libs -const dns = require('dns'); -const net = require('net'); -const os = require('os'); +const dns = require('node:dns'); +const net = require('node:net'); +const os = require('node:os'); // npm libs const ipaddr = require('ipaddr.js'); @@ -959,7 +958,6 @@ class Connection { }) } mail_respond (retval, msg) { - const self = this; if (!this.transaction) { this.logerror("mail_respond found no transaction!"); return; @@ -974,12 +972,12 @@ class Connection { } ); - function store_results (action) { + const store_results = (action) => { let addr = sender.format(); if (addr.length > 2) { // all but null sender addr = addr.substr(1, addr.length -2); // trim off < > } - self.transaction.results.add({name: 'mail_from'}, { + this.transaction.results.add({name: 'mail_from'}, { action, code: constants.translate(retval), address: addr, @@ -990,25 +988,25 @@ class Connection { case constants.deny: this.respond(550, msg || `${dmsg} denied`, () => { store_results('reject'); - self.reset_transaction(); + this.reset_transaction(); }); break; case constants.denydisconnect: this.respond(550, msg || `${dmsg} denied`, () => { store_results('reject'); - self.disconnect(); + this.disconnect(); }); break; case constants.denysoft: this.respond(450, msg || `${dmsg} denied`, () => { store_results('tempfail'); - self.reset_transaction(); + this.reset_transaction(); }); break; case constants.denysoftdisconnect: this.respond(450, msg || `${dmsg} denied`, () => { store_results('tempfail'); - self.disconnect(); + this.disconnect(); }); break; default: diff --git a/contrib/plugin2npm.sh b/contrib/plugin2npm.sh index 1aed72085..24d134a2d 100755 --- a/contrib/plugin2npm.sh +++ b/contrib/plugin2npm.sh @@ -32,7 +32,8 @@ if grep template "$PLUGIN_REPO/README.md"; then -e "s/template\.ini/$1.ini/" \ "$PLUGIN_REPO/test/index.js" - sed -i '' -e "s/template/${1}/g" package.json + sed -i '' -e "s/template/${1}/g" "$PLUGIN_REPO/package.json" + sed -i '' \ -e "s/_template/_${1}/g" \ -e "s/template\.ini/$1.ini/" \ diff --git a/endpoint.js b/endpoint.js index 6968f77e7..8154aef1e 100644 --- a/endpoint.js +++ b/endpoint.js @@ -1,7 +1,7 @@ 'use strict'; // Socket address parser/formatter and server binding helper -const fs = require('fs'); +const fs = require('node:fs'); const sockaddr = require('sockaddr'); module.exports = function endpoint (addr, defaultPort) { diff --git a/host_pool.js b/host_pool.js index 15dd8987d..dab16922d 100644 --- a/host_pool.js +++ b/host_pool.js @@ -1,6 +1,6 @@ 'use strict'; -const net = require('net'); +const net = require('node:net'); const utils = require('haraka-utils'); /* HostPool: diff --git a/line_socket.js b/line_socket.js index db4836bf6..d38eecabc 100644 --- a/line_socket.js +++ b/line_socket.js @@ -1,7 +1,7 @@ 'use strict'; // A subclass of Socket which reads data by line -const net = require('net'); +const net = require('node:net'); const utils = require('haraka-utils'); const tls_socket = require('./tls_socket'); diff --git a/logger.js b/logger.js index 0bb9362c7..98355eb44 100644 --- a/logger.js +++ b/logger.js @@ -1,8 +1,8 @@ 'use strict'; // Log class -const util = require('util'); -const tty = require('tty'); +const util = require('node:util'); +const tty = require('node:tty'); const config = require('haraka-config'); const constants = require('haraka-constants'); diff --git a/outbound/fsync_writestream.js b/outbound/fsync_writestream.js index 99eff2664..d952047e8 100644 --- a/outbound/fsync_writestream.js +++ b/outbound/fsync_writestream.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs'); +const fs = require('node:fs'); class FsyncWriteStream extends fs.WriteStream { constructor (path, options) { diff --git a/outbound/hmail.js b/outbound/hmail.js index aeaab6463..7a7205499 100644 --- a/outbound/hmail.js +++ b/outbound/hmail.js @@ -1,9 +1,9 @@ 'use strict'; -const events = require('events'); -const fs = require('fs'); -const dns = require('dns'); -const path = require('path'); +const events = require('node:events'); +const fs = require('node:fs'); +const dns = require('node:dns'); +const path = require('node:path'); const { Address } = require('address-rfc2821'); const config = require('haraka-config'); diff --git a/outbound/index.js b/outbound/index.js index 64f85cb33..d2410ece1 100644 --- a/outbound/index.js +++ b/outbound/index.js @@ -1,7 +1,7 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const async = require('async'); const { Address } = require('address-rfc2821'); diff --git a/outbound/qfile.js b/outbound/qfile.js index 4001ced1a..f474d8991 100644 --- a/outbound/qfile.js +++ b/outbound/qfile.js @@ -1,6 +1,6 @@ 'use strict'; -const os = require('os'); +const os = require('node:os'); const platform_dot = `${(['win32','win64'].includes(process.platform)) ? '' : '__tmp__'}.`; let QFILECOUNTER = 0; diff --git a/outbound/queue.js b/outbound/queue.js index 74a9355cc..fee9669ea 100644 --- a/outbound/queue.js +++ b/outbound/queue.js @@ -1,8 +1,8 @@ 'use strict'; -const child_process = require('child_process'); -const fs = require('fs'); -const path = require('path'); +const child_process = require('node:child_process'); +const fs = require('node:fs'); +const path = require('node:path'); const async = require('async'); const { Address } = require('address-rfc2821'); diff --git a/outbound/tls.js b/outbound/tls.js index 09be865e4..e576dd6e0 100644 --- a/outbound/tls.js +++ b/outbound/tls.js @@ -1,12 +1,13 @@ 'use strict'; -const net = require('net') +const net = require('node:net') -const logger = require('../logger'); -const tls_socket = require('../tls_socket'); const config = require('haraka-config'); const hkredis = require('haraka-plugin-redis'); +const logger = require('../logger'); +const tls_socket = require('../tls_socket'); + const inheritable_opts = [ 'key', 'cert', 'ciphers', 'minVersion', 'dhparam', 'requestCert', 'honorCipherOrder', 'rejectUnauthorized', diff --git a/package.json b/package.json index ad44b6bbb..b732fb9e9 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ "address-rfc2822": "^2.2.2", "async": "^3.2.5", "daemon": "~1.1.0", - "haraka-config": "^1.3.0", - "haraka-constants": "^1.0.6", - "haraka-dsn": "^1.0.5", + "haraka-config": "^1.4.0", + "haraka-constants": "^1.0.7", + "haraka-dsn": "^1.1.0", "haraka-email-message": "^1.2.3", "haraka-message-stream": "^1.2.1", "haraka-net-utils": "^1.7.0", @@ -37,17 +37,17 @@ "haraka-utils": "^1.1.3", "ipaddr.js": "~2.2.0", "node-gyp": "^10.1.0", - "nopt": "~7.2.0", + "nopt": "^7.2.1", "npid": "~0.4.0", "redis": "~4.6.13", - "semver": "^7.6.0", + "semver": "^7.6.2", "sockaddr": "^1.0.1", "sprintf-js": "~1.1.3" }, "optionalDependencies": { "haraka-plugin-access": "^1.1.6", "haraka-plugin-aliases": "^1.0.2", - "haraka-plugin-asn": "^2.0.2", + "haraka-plugin-asn": "^2.0.3", "haraka-plugin-attachment": "^1.1.2", "haraka-plugin-auth-ldap": "^1.1.0", "haraka-plugin-avg": "^1.1.0", diff --git a/plugins.js b/plugins.js index cf7f04a1f..a95bef454 100644 --- a/plugins.js +++ b/plugins.js @@ -2,9 +2,9 @@ // load all defined plugins // node built-ins -const fs = require('fs'); -const path = require('path'); -const vm = require('vm'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); // npm modules exports.config = require('haraka-config'); @@ -480,10 +480,8 @@ plugins.run_next_hook = (hook, object, params) => { const respond_method = `${hook}_respond`; if (item && is_deny_retval(retval) && hook.substr(0,5) !== 'init_') { - object.deny_respond = - get_denyfn(object, hook, params, retval, msg, respond_method); - plugins.run_hooks('deny', object, - [retval, msg, item[0].name, item[1], params, hook]); + object.deny_respond = get_denyfn(object, hook, params, retval, msg, respond_method); + plugins.run_hooks('deny', object, [retval, msg, item[0].name, item[1], params, hook]); } else { object.hooks_to_run = []; @@ -570,11 +568,16 @@ function log_run_item (item, hook, retval, object, params, msg) { function sanitize (msg) { if (!msg) return '' - const sanitized = { ...msg }; // copy the message - for (const priv of ['password','auth_pass']) { - delete sanitized[priv] + if (typeof msg === 'string') return msg + if (typeof msg === 'object') { + if (msg.constructor.name === 'DSN') return msg.reply + const sanitized = { ...msg }; // copy the message + for (const priv of ['password','auth_pass']) { + delete sanitized[priv] + } + return JSON.stringify(sanitized) } - return sanitized + logger.logerror(`what is ${msg} (typeof ${typeof msg})?`) } function is_deny_retval (val) { diff --git a/plugins/auth/auth_base.js b/plugins/auth/auth_base.js index dc09a1637..dd59f0b71 100644 --- a/plugins/auth/auth_base.js +++ b/plugins/auth/auth_base.js @@ -4,7 +4,7 @@ // Note: You can disable setting `connection.notes.auth_passwd` by `plugin.blankout_password = true` -const crypto = require('crypto'); +const crypto = require('node:crypto'); const tlds = require('haraka-tld') const utils = require('haraka-utils'); diff --git a/plugins/auth/auth_vpopmaild.js b/plugins/auth/auth_vpopmaild.js index dc6c08a34..6d135a4c5 100644 --- a/plugins/auth/auth_vpopmaild.js +++ b/plugins/auth/auth_vpopmaild.js @@ -1,6 +1,6 @@ // Auth against vpopmaild -const net = require('net'); +const net = require('node:net'); exports.register = function () { this.inherits('auth/auth_base'); diff --git a/plugins/block_me.js b/plugins/block_me.js index a4a26654e..f024479bb 100644 --- a/plugins/block_me.js +++ b/plugins/block_me.js @@ -3,7 +3,7 @@ // in the mail_from.blocklist file. You need to be running the // mail_from.blocklist plugin for this to work fully. -const fs = require('fs'); +const fs = require('node:fs'); const utils = require('haraka-utils'); exports.hook_data = (next, connection) => { diff --git a/plugins/data.signatures.js b/plugins/data.signatures.js index 4a1f6e2a6..e1418e6f6 100644 --- a/plugins/data.signatures.js +++ b/plugins/data.signatures.js @@ -3,9 +3,7 @@ exports.hook_data = (next, connection) => { // enable mail body parsing - if (!connection?.transaction) return next(); - - connection.transaction.parse_body = true; + if (connection?.transaction) connection.transaction.parse_body = true; next(); } @@ -17,7 +15,7 @@ exports.hook_data_post = function (next, connection) { if (check_sigs(sigs, connection.transaction.body)) { return next(DENY, "Mail matches a known spam signature"); } - return next(); + next(); } function check_sigs (sigs, body) { diff --git a/plugins/early_talker.js b/plugins/early_talker.js index 09fdaf735..4ccfd5e36 100644 --- a/plugins/early_talker.js +++ b/plugins/early_talker.js @@ -1,7 +1,8 @@ // This plugin checks for clients that talk before we sent a response +const { isIPv6 } = require('node:net'); + const ipaddr = require('ipaddr.js'); -const { isIPv6 } = require('net'); exports.register = function () { this.load_config(); diff --git a/plugins/mail_from.is_resolvable.js b/plugins/mail_from.is_resolvable.js index b59b0d32e..6a9928419 100644 --- a/plugins/mail_from.is_resolvable.js +++ b/plugins/mail_from.is_resolvable.js @@ -1,7 +1,7 @@ 'use strict'; // Check MAIL FROM domain is resolvable to an MX -const net = require('net'); +const net = require('node:net'); const net_utils = require('haraka-net-utils'); @@ -70,7 +70,7 @@ exports.hook_mail = function (next, connection, params) { function mxErr (err) { if (!connection.transaction) return; - results.add(this, {err: `${domain}:${err.message}`}); + results.add(plugin, {err: `${domain}:${err.message}`}); mxDone(DENYSOFT, `Temp. resolver error (${err.code})`); } diff --git a/plugins/queue/qmail-queue.js b/plugins/queue/qmail-queue.js index 1e194385d..e03c7ed63 100644 --- a/plugins/queue/qmail-queue.js +++ b/plugins/queue/qmail-queue.js @@ -1,7 +1,7 @@ // Queue to qmail-queue -const childproc = require('child_process'); -const fs = require('fs'); +const childproc = require('node:child_process'); +const fs = require('node:fs'); exports.register = function () { diff --git a/plugins/queue/quarantine.js b/plugins/queue/quarantine.js index 472118787..af33d7f81 100644 --- a/plugins/queue/quarantine.js +++ b/plugins/queue/quarantine.js @@ -1,7 +1,7 @@ // quarantine -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); exports.register = function () { diff --git a/plugins/queue/smtp_forward.js b/plugins/queue/smtp_forward.js index 9fbb055b2..b296a67b3 100644 --- a/plugins/queue/smtp_forward.js +++ b/plugins/queue/smtp_forward.js @@ -4,7 +4,7 @@ // and passes back any errors seen on the ongoing server to the // originating server. -const url = require('url'); +const url = require('node:url'); const smtp_client_mod = require('./smtp_client'); diff --git a/plugins/queue/test.js b/plugins/queue/test.js index c71a6f97c..0b8616b20 100644 --- a/plugins/queue/test.js +++ b/plugins/queue/test.js @@ -1,5 +1,5 @@ -const fs = require('fs'); -const os = require('os'); +const fs = require('node:fs'); +const os = require('node:os'); const tempDir = os.tmpdir(); diff --git a/plugins/relay.js b/plugins/relay.js index 9499ead40..5aa19992f 100644 --- a/plugins/relay.js +++ b/plugins/relay.js @@ -2,8 +2,9 @@ // // documentation via: haraka -h relay +const net = require('node:net'); + const ipaddr = require('ipaddr.js'); -const net = require('net'); exports.register = function () { @@ -89,11 +90,9 @@ exports.acl = function (next, connection) { } exports.pass_relaying = (next, connection) => { - if (connection.relaying) { - return next(OK); - } + if (connection.relaying) return next(OK); - return next(); + next(); } exports.is_acl_allowed = function (connection) { @@ -172,7 +171,7 @@ exports.dest_domains = function (next, connection, params) { } transaction.results.add(this, {fail: 'relay_dest_domain'}); - return next(DENY, "Mail for that recipient is not accepted here."); + next(DENY, "Mail for that recipient is not accepted here."); } exports.force_routing = function (next, hmail, domain) { @@ -196,7 +195,7 @@ exports.force_routing = function (next, hmail, domain) { } this.logdebug(this, `using ${nexthop} for: ${domain}`); - return next(OK, nexthop); + next(OK, nexthop); } exports.all = function (next, connection, params) { diff --git a/plugins/reseed_rng.js b/plugins/reseed_rng.js index 3cf474291..2c38e1dd3 100644 --- a/plugins/reseed_rng.js +++ b/plugins/reseed_rng.js @@ -1,4 +1,4 @@ -const crypto = require('crypto'); +const crypto = require('node:crypto'); exports.hook_init_child = function (next) { Math.seedrandom(crypto.randomBytes(256).toString('hex')); diff --git a/plugins/status.js b/plugins/status.js index d617f1ea7..39b7e3b53 100644 --- a/plugins/status.js +++ b/plugins/status.js @@ -1,7 +1,8 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); + const async = require('async'); exports.register = function () { diff --git a/plugins/xclient.js b/plugins/xclient.js index f2bf8416a..47c418be2 100644 --- a/plugins/xclient.js +++ b/plugins/xclient.js @@ -1,9 +1,10 @@ // Implementation of XCLIENT protocol // See http://www.postfix.org/XCLIENT_README.html +const net = require('node:net'); + const utils = require('haraka-utils'); const DSN = require('haraka-dsn'); -const net = require('net'); let allowed_hosts = {}; exports.register = function () { @@ -119,5 +120,5 @@ exports.hook_unrecognized_command = function (next, connection, params) { connection.xclient = true; if (!xclient.name) return next(NEXT_HOOK, 'lookup_rdns'); - return next(NEXT_HOOK, 'connect'); + next(NEXT_HOOK, 'connect'); } diff --git a/server.js b/server.js index 69834e4a1..ccda7140b 100644 --- a/server.js +++ b/server.js @@ -1,20 +1,19 @@ 'use strict'; // smtp network server -const daemon = require('daemon'); -const fs = require('fs'); -const os = require('os'); -const path = require('path'); -const tls = require('tls'); +const cluster = require('node:cluster'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); +const tls = require('node:tls'); -// let log = require('why-is-node-running'); +const async = require('async'); +const daemon = require('daemon'); const tls_socket = require('./tls_socket'); const conn = require('./connection'); const outbound = require('./outbound'); -const async = require('async'); -const cluster = require('cluster'); -const constants = require('haraka-constants'); const endpoint = require('./endpoint'); +const constants = require('haraka-constants'); const Server = exports; Server.logger = require('./logger'); diff --git a/smtp_client.js b/smtp_client.js index ce34b0851..bca77c728 100644 --- a/smtp_client.js +++ b/smtp_client.js @@ -7,18 +7,15 @@ // than a bunch of connections to a single host from the configuration values // in "host" and "port" (see host_pool.js). -// node.js builtins -const events = require('events'); +const events = require('node:events'); -// npm deps -const ipaddr = require('ipaddr.js'); -const net_utils = require('haraka-net-utils'); -const utils = require('haraka-utils'); +const ipaddr = require('ipaddr.js'); +const net_utils = require('haraka-net-utils'); +const utils = require('haraka-utils'); -// haraka libs const tls_socket = require('./tls_socket') -const logger = require('./logger'); -const HostPool = require('./host_pool'); +const logger = require('./logger'); +const HostPool = require('./host_pool'); const smtp_regexp = /^(\d{3})([ -])(.*)/; const STATE = { diff --git a/test/endpoint.js b/test/endpoint.js index 0d9404668..8599d65f2 100644 --- a/test/endpoint.js +++ b/test/endpoint.js @@ -64,13 +64,13 @@ describe('endpoint', () => { }, }; - mock('fs', this.mockfs); + mock('node:fs', this.mockfs); this.endpoint = mock.reRequire('../endpoint'); done(); }) afterEach((done) => { - mock.stop('fs'); + mock.stop('node:fs'); done(); }) diff --git a/test/fixtures/line_socket.js b/test/fixtures/line_socket.js index 280cee1e0..66c6170c4 100644 --- a/test/fixtures/line_socket.js +++ b/test/fixtures/line_socket.js @@ -1,6 +1,6 @@ 'use strict'; -const events = require('events'); +const events = require('node:events'); const fixtures = require('haraka-test-fixtures'); const { stub } = fixtures.stub; diff --git a/test/outbound/hmail.js b/test/outbound/hmail.js index 9f7973bac..9cbfac25f 100644 --- a/test/outbound/hmail.js +++ b/test/outbound/hmail.js @@ -1,7 +1,7 @@ -const assert = require('assert') -const fs = require('fs') -const path = require('path') +const assert = require('node:assert') +const fs = require('node:fs') +const path = require('node:path') const Hmail = require('../../outbound/hmail'); const outbound = require('../../outbound/index'); diff --git a/test/outbound_bounce_rfc3464.js b/test/outbound_bounce_rfc3464.js index c8370a382..6edd8381e 100644 --- a/test/outbound_bounce_rfc3464.js +++ b/test/outbound_bounce_rfc3464.js @@ -12,8 +12,8 @@ // * or, in case of 4XX: that temp_fail is called and dsn vars are available) const assert = require('node:assert') -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const util_hmailitem = require('./fixtures/util_hmailitem'); const TODOItem = require('../outbound/todo'); diff --git a/test/plugins/mail_from.is_resolvable.js b/test/plugins/mail_from.is_resolvable.js index ca11b640f..fb94fe465 100644 --- a/test/plugins/mail_from.is_resolvable.js +++ b/test/plugins/mail_from.is_resolvable.js @@ -1,8 +1,8 @@ 'use strict'; const assert = require('node:assert') +const dns = require('node:dns'); const fixtures = require('haraka-test-fixtures'); -const dns = require('dns'); const Address = require('address-rfc2821').Address const _set_up = (done) => { diff --git a/test/plugins/tls.js b/test/plugins/tls.js index 2eb3ccbf3..68cfc26db 100644 --- a/test/plugins/tls.js +++ b/test/plugins/tls.js @@ -1,10 +1,10 @@ 'use strict'; const assert = require('node:assert') -const path = require('path'); +const path = require('node:path'); -const fixtures = require('haraka-test-fixtures'); -const Plugin = fixtures.plugin; +const fixtures = require('haraka-test-fixtures'); +const Plugin = fixtures.plugin; const _set_up = (done) => { this.plugin = new Plugin('tls') diff --git a/test/server.js b/test/server.js index 4467ae23c..ed199073b 100644 --- a/test/server.js +++ b/test/server.js @@ -1,6 +1,6 @@ const assert = require('node:assert') +const path = require('node:path'); -const path = require('path'); const endpoint = require('../endpoint'); const message = require('haraka-email-message') diff --git a/test/transaction.js b/test/transaction.js index 88a61c6dc..e9eabcb45 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -1,7 +1,6 @@ const assert = require('node:assert') - -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const config = require('haraka-config') const transaction = require('../transaction'); diff --git a/transaction.js b/transaction.js index b02ce06b3..f23b85976 100644 --- a/transaction.js +++ b/transaction.js @@ -1,7 +1,7 @@ 'use strict'; // An SMTP Transaction -const util = require('util'); +const util = require('node:util'); const Notes = require('haraka-notes'); const utils = require('haraka-utils');