[GH-ISSUE #28] [bug] not working as in docs described #15

Closed
opened 2026-03-04 00:58:23 +03:00 by kerem · 1 comment
Owner

Originally created by @celevra on GitHub (Nov 15, 2024).
Original GitHub issue: https://github.com/spamscanner/spamscanner/issues/28

Describe the bug

Node.js version: v20.18.0

OS version: Ubuntu 20.04

Description: example code does not work it complains

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object
const SMTPServer = require('smtp-server').SMTPServer;

const SpamScanner = require('spamscanner');
const scanner = new SpamScanner();

var streamContent = {};
var sessions = {};

const server = new SMTPServer({
    onData(stream, session, callback) {
        sessions[session.id] = {...session}
        stream.on('data', function(d) {
            if (typeof streamContent[session.id] == "undefined") {
                streamContent[session.id] = {}
                streamContent[session.id].msg = d.toString('utf8');
            } else
                streamContent[session.id].msg += d.toString('utf8');
        })
        stream.on('end', function() {
            callback(false)
            process(session.id)
        });
    },
    authOptional: true
});

function process(session) {
    console.log(typeof streamContent[session].msg)
    console.log(streamContent[session].msg)
    scanner.scan(streamContent[session].msg, (err, scan) => {
      if (err) 
        console.error(err);
    });
}

server.listen(20024, function(){
    console.log('running')
});

example result output:

running
string
Received: by mx01.xxxx.com (Postfix, from userid 0)
        id 718F041789; Fri, 15 Nov 2024 17:39:27 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xxxx.com;
        s=mailer; t=;
        bh=g3zLYH4xKxcPrHOD18z9YfpQcnk/GaJedfustWU5uGs=;
        h=Subject:To:Date:From:From;
        b=fwUBTovFAXu1B54QJ1B8M7CcarR0hFprFb6ErjiPmyNmqjV1R9IS0ss29JotVXeJW
         b3CQLh2B/wD7AbvbUNnP8rcvClCLAs97y+35lqw6+ejNsf9qPpSSQ1y3LCM/ionM3H
         Taki7SCMJVVirFKzx+vOGEcaABS1Zvt0jUNVCaeieKAVzD0yKUREcqxnQc0/zkQrCc
         BzV7M4Hg+TW9B4/yiyS+WcELQP9+CNhZF5CtqF92FUCQdepv53ewsneFH6YnuToGfM
         /oDV3MKyJizcP9NO+C1khNC87cM3ZBk/udvpsuNmYbcdtuXNXNdkP7rhdm5ZnodwV8
         VXIRC4WPrwJPA==
Subject: test
To: <philipp@xxxx.com>
X-Mailer: mail (GNU Mailutils 3.7)
Message-Id: <20241115163927.718F041789@mx01.xxxx.com>
Date: Fri, 15 Nov 2024 17:39:27 +0100 (CET)
From: root <root@xxxx.com>

test

node:internal/streams/writable:480
      throw new ERR_INVALID_ARG_TYPE(
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object
    at _write (node:internal/streams/writable:480:13)
    at Writable.end (node:internal/streams/writable:821:17)
    at Immediate.<anonymous> (/node/postfix/node_modules/nodemailer/lib/mime-node/index.js:977:46)
    at process.processImmediate (node:internal/timers:483:21) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v20.18.0

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
Originally created by @celevra on GitHub (Nov 15, 2024). Original GitHub issue: https://github.com/spamscanner/spamscanner/issues/28 ## Describe the bug **Node.js version:** v20.18.0 **OS version:** Ubuntu 20.04 **Description:** example code does not work it complains ``` TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object ``` ``` const SMTPServer = require('smtp-server').SMTPServer; const SpamScanner = require('spamscanner'); const scanner = new SpamScanner(); var streamContent = {}; var sessions = {}; const server = new SMTPServer({ onData(stream, session, callback) { sessions[session.id] = {...session} stream.on('data', function(d) { if (typeof streamContent[session.id] == "undefined") { streamContent[session.id] = {} streamContent[session.id].msg = d.toString('utf8'); } else streamContent[session.id].msg += d.toString('utf8'); }) stream.on('end', function() { callback(false) process(session.id) }); }, authOptional: true }); function process(session) { console.log(typeof streamContent[session].msg) console.log(streamContent[session].msg) scanner.scan(streamContent[session].msg, (err, scan) => { if (err) console.error(err); }); } server.listen(20024, function(){ console.log('running') }); ``` example result output: ``` running string Received: by mx01.xxxx.com (Postfix, from userid 0) id 718F041789; Fri, 15 Nov 2024 17:39:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xxxx.com; s=mailer; t=; bh=g3zLYH4xKxcPrHOD18z9YfpQcnk/GaJedfustWU5uGs=; h=Subject:To:Date:From:From; b=fwUBTovFAXu1B54QJ1B8M7CcarR0hFprFb6ErjiPmyNmqjV1R9IS0ss29JotVXeJW b3CQLh2B/wD7AbvbUNnP8rcvClCLAs97y+35lqw6+ejNsf9qPpSSQ1y3LCM/ionM3H Taki7SCMJVVirFKzx+vOGEcaABS1Zvt0jUNVCaeieKAVzD0yKUREcqxnQc0/zkQrCc BzV7M4Hg+TW9B4/yiyS+WcELQP9+CNhZF5CtqF92FUCQdepv53ewsneFH6YnuToGfM /oDV3MKyJizcP9NO+C1khNC87cM3ZBk/udvpsuNmYbcdtuXNXNdkP7rhdm5ZnodwV8 VXIRC4WPrwJPA== Subject: test To: <philipp@xxxx.com> X-Mailer: mail (GNU Mailutils 3.7) Message-Id: <20241115163927.718F041789@mx01.xxxx.com> Date: Fri, 15 Nov 2024 17:39:27 +0100 (CET) From: root <root@xxxx.com> test node:internal/streams/writable:480 throw new ERR_INVALID_ARG_TYPE( ^ TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Object at _write (node:internal/streams/writable:480:13) at Writable.end (node:internal/streams/writable:821:17) at Immediate.<anonymous> (/node/postfix/node_modules/nodemailer/lib/mime-node/index.js:977:46) at process.processImmediate (node:internal/timers:483:21) { code: 'ERR_INVALID_ARG_TYPE' } Node.js v20.18.0 ``` ## Checklist - [x] I have searched through GitHub issues for similar issues. - [x] I have completely read through the README and documentation. - [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
kerem 2026-03-04 00:58:23 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@titanism commented on GitHub (Dec 22, 2025):

v6 released, we will update classifier.json (there's one published now with sha256) after @fwdemail integration (we're on older v5). the current classifier.json is not that accurate, but we will improve after integration (since we process millions of emails daily, it'll be very accurate soon enough).

https://github.com/spamscanner/spamscanner

https://github.com/spamscanner/spamscanner/releases

X post/announcement @ https://x.com/fwdemail/status/2002872581402063281

we also support TypeScript now in the project (thx to AI, we despise TS internally tho)

<!-- gh-comment-id:3679766336 --> @titanism commented on GitHub (Dec 22, 2025): v6 released, we will update classifier.json (there's one published now with sha256) after @fwdemail integration (we're on older v5). the current classifier.json is not that accurate, but we will improve after integration (since we process millions of emails daily, it'll be very accurate soon enough). <https://github.com/spamscanner/spamscanner> <https://github.com/spamscanner/spamscanner/releases> X post/announcement @ <https://x.com/fwdemail/status/2002872581402063281> we also support TypeScript now in the project (thx to AI, we despise TS internally tho)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spamscanner#15
No description provided.