Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
spamscanner — Spam Scanner is a Node.js anti-spam, email filtering, and phishing prevention tool and service. Built for @ladjs, @forwardemail, @cabinjs, @breejs, and @lassjs. | Kitploit
Tools/GitHubGitHub/spamscanner/spamscanner
Static AnalysisVulnerability ScannersDynamic Analysis (Sandboxing)PhishingThreat IntelligenceMachine LearningIncident ResponseAnti-BotEmail Security
GitHubspamscanner/spamscanner

spamscanner

Spam Scanner is a Node.js anti-spam, email filtering, and phishing prevention tool and service. Built for @ladjs, @forwardemail, @cabinjs, @breejs, and @lassjs.

3743848 months agoReviewed by Kitploit
View RepositoryWebsite

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

spamscanner

build status code style styled with prettier made with lass license

Spam Scanner is the best anti-spam, , and service.
email filtering
phishing prevention

Spam Scanner is a drop-in replacement and the best alternative to SpamAssassin, rspamd, SpamTitan, and more.

[!NOTE] Spam Scanner is actively maintained and used in production at Forward Email to protect millions of emails daily.

Table of Contents

  • Foreword
  • Installation
    • npm (Recommended)
    • Standalone Binary (No Node.js Required)
    • ClamAV Installation (Optional)
  • CLI (Command Line Interface)
    • CLI Installation
    • Commands
    • Exit Codes
    • CLI Examples
  • Why Spam Scanner
    • Key Advantages
  • Features
    • Core Detection Features
    • Naive Bayes Classifier
    • Phishing Detection
    • Virus Scanning
    • Executable Detection
    • NSFW Image Detection
    • Toxicity Detection
    • Macro Detection
    • Language Detection
    • Pattern Recognition
    • URL Analysis
  • Comparison
    • Spam Scanner vs. Alternatives
  • Architecture
    • System Overview
    • Detection Flow
    • Component Architecture
  • Requirements
    • System Requirements
    • Dependencies
  • Quick Start
    • Basic Usage
    • With Configuration
    • Checking Specific Features
  • API Documentation
    • Constructor Options
    • Methods
    • Result Object
  • Advanced Usage
    • Custom Classifier
    • Custom Text Replacements
    • Language Filtering
    • Performance Monitoring
    • Selective Feature Disabling
    • Custom Timeout
    • Custom Logger
  • ARF (Abuse Reporting Format)
    • Parsing ARF Reports
    • Creating ARF Reports
    • ARF Result Object
  • Mail Server Integration
    • Postfix Integration
    • Dovecot Integration
    • TCP Server Mode
  • Performance
    • Benchmarks
    • Optimization Tips
    • Memory Usage
  • Contributing
    • Development Setup
    • Running Tests
  • License
  • Support
  • Acknowledgments

Foreword

Spam Scanner is a tool and service created after hitting countless roadblocks with existing spam-detection solutions. In other words, it's our current plan for spam and our better plan for spam.

Our goal is to build and utilize a scalable, performant, simple, easy to maintain, and powerful API for use in our service at Forward Email to limit spam and provide other measures to prevent attacks on our users.

Initially we tried using SpamAssassin, and later evaluated rspamd – but in the end we learned that all existing solutions (even ones besides these) are overtly complex, missing required features or documentation, incredibly challenging to configure; high-barrier to entry, or have proprietary storage backends (that could store and read your messages without your consent) that limit our scalability.

To us, we value privacy and the security of our data and users – specifically we have a "Zero-Tolerance Policy" on storing logs or metadata of any kind, whatsoever (see our Privacy Policy for more on that). None of these solutions honored this privacy policy (without removing essential spam-detection functionality), so we had to create our own tool – thus "Spam Scanner" was born.


Installation

npm (Recommended)

root@kitploit:~
npm install spamscanner

For CLI usage:

root@kitploit:~
# Install globally
npm install -g spamscanner

# Or use npx without installing
npx spamscanner scan email.eml

Standalone Binary (No Node.js Required)

Download a pre-built binary for your platform. These are self-contained executables that don't require Node.js.

See CLI Installation for download links and platform-specific instructions.

ClamAV Installation (Optional)

macOS

root@kitploit:~
brew install clamav
freshclam

Ubuntu/Debian

root@kitploit:~
sudo apt-get update
sudo apt-get install clamav clamav-daemon
sudo freshclam
sudo systemctl start clamav-daemon

CentOS/RHEL

root@kitploit:~
sudo yum install clamav clamav-update
sudo freshclam

[!TIP] See the ClamAV configuration guide for detailed installation instructions.


CLI (Command Line Interface)

SpamScanner provides a command-line interface for scanning emails directly from the terminal or integrating with mail servers.

CLI Installation

SpamScanner can be installed via npm or as a standalone binary. The standalone binary includes Node.js and all dependencies, so no additional runtime is required.

Install via npm (requires Node.js)

root@kitploit:~
# Install globally
npm install -g spamscanner

# Or use npx without installing
npx spamscanner --help

Install Standalone Binary

macOS
root@kitploit:~
# Download manually for Apple Silicon (M1/M2/M3)
curl -fsSL https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-darwin-arm64 -o /usr/local/bin/spamscanner
chmod +x /usr/local/bin/spamscanner
root@kitploit:~
# Download manually for Intel Mac
curl -fsSL https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-darwin-x64 -o /usr/local/bin/spamscanner
chmod +x /usr/local/bin/spamscanner
Linux
root@kitploit:~
# Download and install to /usr/local/bin
sudo curl -fsSL https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-linux-x64 -o /usr/local/bin/spamscanner
sudo chmod +x /usr/local/bin/spamscanner
# Add to PATH if not already: export PATH="$HOME/.local/bin:$PATH"
root@kitploit:~
# Or install to user directory (no sudo required)
mkdir -p ~/.local/bin
curl -fsSL https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-linux-x64 -o ~/.local/bin/spamscanner
chmod +x ~/.local/bin/spamscanner
# Add to PATH if not already: export PATH="$HOME/.local/bin:$PATH"
Windows
root@kitploit:~
# Using PowerShell (run as Administrator)
Invoke-WebRequest -Uri "https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-win-x64.exe" -OutFile "C:\Program Files\spamscanner\spamscanner.exe"
# Add to PATH via System Properties > Environment Variables
root@kitploit:~
# Or download to current directory
Invoke-WebRequest -Uri "https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-win-x64.exe" -OutFile ".\spamscanner.exe"
# Add to PATH via System Properties > Environment Variables
Verify Installation
root@kitploit:~
# Check version
spamscanner version

# Check for updates
spamscanner update

Automatic Updates

SpamScanner CLI automatically checks for updates once every 24 hours and displays a notification if a new version is available. You can also manually check for updates:

root@kitploit:~
# Check for updates
spamscanner update

# Disable automatic update checks
spamscanner scan email.eml --no-update-check

To update to the latest version, simply re-run the installation command for your platform or use npm:

root@kitploit:~
# Update via npm
npm update -g spamscanner

# Or re-download the binary (macOS/Linux)
curl -fsSL https://github.com/spamscanner/spamscanner/releases/latest/download/spamscanner-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/x64/' | sed 's/aarch64/arm64/') -o /usr/local/bin/spamscanner
chmod +x /usr/local/bin/spamscanner

Commands

CommandDescription
spamscanner scan <file>Scan an email file
spamscanner scan -Scan email from stdin
spamscanner serverStart TCP server mode
spamscanner helpShow help message
spamscanner versionShow version number
spamscanner updateCheck for updates

General Options

OptionDescription
-h, --helpShow help
-v, --versionShow version
-j, --jsonOutput results as JSON
--verboseShow detailed output
--debugEnable debug mode
--timeout <ms>Scan timeout in milliseconds (default: 30000)
--no-update-checkDisable automatic update check

Spam Detection Options

SpamScanner calculates a spam score based on multiple detection methods. You can configure which checks are included and customize the score weights.

OptionDescription
--threshold <score>Spam score threshold (default: 5.0)
--check-classifierInclude Bayesian classifier in scoring (default)
--check-phishingInclude phishing detection in scoring (default)
--check-executablesInclude executable detection in scoring (default)
--check-macrosInclude macro detection in scoring (default)
--check-virusInclude virus detection in scoring (default)
--check-nsfwInclude NSFW detection in scoring (disabled)
--check-toxicityInclude toxicity detection in scoring (disabled)
--no-classifierDisable Bayesian classifier scoring
--no-phishingDisable phishing scoring
--no-executablesDisable executable scoring
--no-macrosDisable macro scoring
--no-virusDisable virus scoring

Score Weights

Customize how much each detection type contributes to the total spam score:

OptionDescription
--score-classifier <n>Classifier spam score weight (default: 5.0)
--score-phishing <n>Phishing score per issue (default: 5.0)
--score-executable <n>Executable score per file (default: 10.0)
--score-macro <n>Macro score per detection (default: 5.0)
--score-virus <n>Virus score per detection (default: 100.0)
--score-nsfw <n>NSFW score per detection (default: 3.0)
--score-toxicity <n>Toxicity score per detection (default: 3.0)

Header Options

For mail server integration, SpamScanner can add X-Spam headers to emails (similar to SpamAssassin and Stalwart):

OptionDescription
--add-headersAdd X-Spam-* headers to output
--prepend-subjectPrepend [SPAM] to subject if spam detected
--subject-tag <tag>Custom subject tag (default: [SPAM])

X-Spam Headers Added:

HeaderDescription
X-Spam-StatusYes/No, score=X.X required=Y.Y tests=TEST1,TEST2,... version=X.X.X
X-Spam-ScoreNumeric spam score (e.g., 7.5)
X-Spam-FlagYES or NO
X-Spam-TestsComma-separated list of triggered tests

Scanner Configuration Options

These options configure the underlying SpamScanner engine:

OptionDescription
--languages <list>Comma-separated language codes (default: all languages)
--mixed-languageEnable mixed language detection in emails
--no-macro-detectionDisable macro detection in attachments
--no-pattern-recognitionDisable advanced pattern recognition
--strict-idnEnable strict IDN/homograph detection
--nsfw-threshold <n>NSFW detection threshold 0.0-1.0 (default: 0.6)
--toxicity-threshold <n>Toxicity detection threshold 0.0-1.0 (default: 0.7)
--clamscan-path <path>Path to clamscan binary (default: /usr/bin/clamscan)
--clamdscan-path <path>Path to clamdscan binary (default: /usr/bin/clamdscan)
Supported Languages

Use ISO 639-1 language codes with the --languages option. Pass an empty string or all to enable all languages (default).

CodeLanguageCodeLanguageCodeLanguage
enEnglishfrFrenchesSpanish
deGermanitItalianptPortuguese
ruRussianjaJapanesekoKorean
zhChinesearArabichiHindi
bnBengaliurUrdutrTurkish
plPolishnlDutchsvSwedish
noNorwegiandaDanishfiFinnish
huHungariancsCzechskSlovak
slSlovenianhrCroatiansrSerbian
bgBulgarianroRomanianelGreek
heHebrewthThaiviVietnamese
idIndonesianmsMalaytlTagalog

Server Options

OptionDescription
--port <port>TCP server port (default: 7830)
--host <host>TCP server host (default: 127.0.0.1)

Exit Codes

CodeMeaning
0Clean (not spam)
1Spam detected
2Error occurred

CLI Examples

root@kitploit:~
# Scan a file
spamscanner scan email.eml

# Scan from stdin (for Postfix integration)
cat email.eml | spamscanner scan -

# Scan with JSON output (includes score and tests)
spamscanner scan email.eml --json

# Scan with verbose output
spamscanner scan email.eml --verbose

# Scan with custom spam threshold
spamscanner scan email.eml --threshold 3.0

# Scan with only classifier and phishing checks
spamscanner scan email.eml --no-executables --no-macros --no-virus

# Scan and add X-Spam headers (for mail server integration)
spamscanner scan email.eml --add-headers

# Scan, add headers, and prepend [SPAM] to subject
spamscanner scan email.eml --add-headers --prepend-subject

# Scan with custom subject tag
spamscanner scan email.eml --add-headers --prepend-subject --subject-tag "[JUNK]"

# Enable NSFW and toxicity checks with custom weights
spamscanner scan email.eml --check-nsfw --check-toxicity --score-nsfw 5.0

# Start TCP server on custom port
spamscanner server --port 8080

# Start TCP server with custom threshold
spamscanner server --port 8080 --threshold 3.0

# Scan with specific language support (English, Spanish, French only)
spamscanner scan email.eml --languages en,es,fr

# Scan with mixed language detection enabled
spamscanner scan email.eml --mixed-language

# Scan with strict IDN/homograph detection
spamscanner scan email.eml --strict-idn

# Scan with custom NSFW threshold (more sensitive)
spamscanner scan email.eml --check-nsfw --nsfw-threshold 0.3

# Scan with custom ClamAV paths
spamscanner scan email.eml --clamscan-path /opt/clamav/bin/clamscan

Example JSON Output

root@kitploit:~
{
  "isSpam": true,
  "score": 7.5,
  "threshold": 5.0,
  "tests": ["BAYES_SPAM(5.0)", "PHISHING_DETECTED(2.5)"],
  "message": "Spam",
  "results": {
    "classification": { "category": "spam", "probability": 0.95 },
    "phishing": [{ "type": "suspicious_link", "url": "http://example.com" }]
  },
  "headers": {
    "X-Spam-Status": "Yes, score=7.5 required=5.0 tests=BAYES_SPAM(5.0),PHISHING_DETECTED(2.5) version=6.0.1",
    "X-Spam-Score": "7.5",
    "X-Spam-Flag": "YES",
    "X-Spam-Tests": "BAYES_SPAM(5.0), PHISHING_DETECTED(2.5)"
  }
}

Why Spam Scanner

[!TIP] Spam Scanner is the only modern, privacy-focused, Node.js-based spam detection solution with AI-powered features.

Key Advantages

  • 🔒 Privacy-First - Zero logging, zero metadata storage
  • 🚀 Modern - Built with Node.js 18+, ES modules, and latest AI models
  • 🎯 Accurate - 88%+ detection accuracy with Naive Bayes classifier
  • ⚡ Fast - Scans emails in under 3 seconds (with model caching)
  • 🛡️ Comprehensive - 10+ detection methods (virus, phishing, NSFW, toxicity, macros, etc.)
  • 🌍 Multilingual - Supports 40+ languages with automatic detection
  • 🔧 Easy to Use - Simple API, extensive documentation, TypeScript support
  • 📊 Battle-Tested - Used in production at Forward Email

Features

Spam Scanner includes modern, essential, and performant features that help reduce spam, phishing, and executable attacks.

Core Detection Features

FeatureDescriptionStatus
Naive Bayes ClassifierMachine learning spam classification trained on 100K+ emails✅ Production
Phishing DetectionIDN homograph detection, confusables, suspicious link analysis✅ Production
Virus ScanningClamAV integration for attachment scanning✅ Production
Executable DetectionDetects 195+ dangerous file extensions + magic number verification✅ Production
NSFW Image DetectionTensorFlow.js-powered image content analysis✅ Production
Toxicity DetectionAI-powered toxic language detection (threats, insults, harassment)✅ Production
Macro DetectionVBA, PowerShell, JavaScript, Batch script detection in attachments✅ Production
Language DetectionHybrid franc/lande detection for 40+ languages✅ Production
Pattern RecognitionCredit cards, phone numbers, IPs, Bitcoin addresses, etc.✅ Production
URL AnalysisTLD parsing, Cloudflare blocking detection, suspicious domains✅ Production

Naive Bayes Classifier

Our Naive Bayesian classifier is available in this repository, the npm package, and is updated frequently as it gains upstream, anonymous, SHA-256 hashed data from Forward Email.

  • Training Data: 100,000+ spam and ham emails
  • Accuracy: 88%+ classification accuracy
  • Languages: Supports 40+ languages with language-specific tokenization
  • Stemming: Porter Stemmer for English, Snowball for 15+ other languages
  • Privacy: All training data is anonymized and SHA-256 hashed

Phishing Detection

Advanced phishing detection using multiple techniques:

  • IDN Homograph Detection: Detects lookalike domains (e.g., аpple.com using Cyrillic "а")
  • Confusables Integration: Uses Unicode confusables database to detect character substitution
  • TLD Analysis: Validates TLDs and detects suspicious domain patterns
  • Link Analysis: Checks for mismatched display text and actual URLs
  • Cloudflare Detection: Identifies domains blocked by Cloudflare

Virus Scanning

Integrates with ClamAV for comprehensive virus detection:

  • Real-time Scanning: Scans all email attachments
  • Buffer Support: Direct buffer scanning without file I/O
  • Timeout Protection: Configurable scan timeouts
  • Virus Database: Uses ClamAV's regularly updated virus definitions

Executable Detection

Detects dangerous executable files:

  • 195+ File Extensions: exe, dll, bat, vbs, ps1, scr, pif, cmd, com, etc.
  • Magic Number Verification: Detects renamed executables by file content
  • Office Macros: Detects macro-enabled Office documents (docm, xlsm, pptm)
  • Legacy Office: Flags legacy Office formats (doc, xls, ppt) as high-risk
  • PDF JavaScript: Detects malicious JavaScript in PDF files
  • Archive Detection: Flags archives (zip, rar, 7z) that may hide executables

NSFW Image Detection

AI-powered image content analysis using TensorFlow.js:

  • Categories: Porn, Hentai, Sexy, Neutral, Drawing
  • Model: NSFWJS model trained on 60K+ images
  • Threshold: Configurable detection threshold (default: 0.7)
  • Performance: Model caching for fast subsequent scans
  • Formats: Supports JPEG, PNG, GIF, WebP, BMP

Toxicity Detection

Detects toxic language using TensorFlow.js Toxicity model:

  • Categories: Identity attack, insult, obscenity, severe toxicity, sexual explicit, threat
  • Threshold: Configurable toxicity threshold (default: 0.7)
  • Languages: Optimized for English, supports other languages
  • Performance: Model caching for fast subsequent scans

Macro Detection

Detects malicious macros in email content and attachments:

  • VBA Macros: Detects Visual Basic for Applications code
  • PowerShell: Detects PowerShell scripts and commands
  • JavaScript: Detects JavaScript code in emails
  • Batch Scripts: Detects Windows batch files
  • Office Documents: Scans docm, xlsm, pptm, xlam, dotm, xltm, potm
  • PDF JavaScript: Detects JavaScript in PDF attachments

Language Detection

Hybrid language detection using franc and lande:

  • 40+ Languages: Supports all major world languages
  • Automatic Detection: Detects language from email content
  • Fallback System: Uses lande when franc returns "undetermined"
  • Mixed Language Support: Optional mixed language detection
  • Language Filtering: Filter results to supported languages only

Pattern Recognition

Detects various patterns in email content:

  • Credit Cards: Visa, MasterCard, Amex, Discover, etc.
  • Phone Numbers: International phone number formats
  • Email Addresses: RFC-compliant email detection
  • IP Addresses: IPv4 and IPv6 addresses
  • URLs: Full URL extraction and analysis
  • Bitcoin Addresses: Cryptocurrency wallet addresses
  • MAC Addresses: Network hardware addresses
  • Hex Colors: Color codes (#RRGGBB)
  • Floating Point Numbers: Decimal numbers
  • Dates: Multiple date formats (MM/DD/YYYY, YYYY-MM-DD, etc.)
  • File Paths: Windows and Unix file paths

URL Analysis

Comprehensive URL analysis and validation:

  • TLD Parsing: Uses tldts for accurate TLD extraction
  • Domain Analysis: Extracts domain, subdomain, public suffix
  • IP Detection: Identifies IP-based URLs
  • Cloudflare Check: Detects Cloudflare-blocked domains
  • URL Normalization: Normalizes URLs for consistent analysis
  • Suspicious Pattern Detection: Identifies phishing URL patterns

Comparison

Spam Scanner vs. Alternatives

FeatureSpam ScannerSpamAssassinrspamdClamAV
LicenseBSL 1.1Apache 2.0Apache 2.0GPLv2
LanguageNode.jsPerlCC
Modern ArchitectureYesNoPartialNo
Easy to UseYesNoNoYes
Privacy-FocusedYesPartialPartialYes
Naive Bayes ClassifierYesYesYesNo
Virus ScanningYesYesYesYes
Phishing DetectionYesYesYesNo
IDN Homograph DetectionYesNoYesNo
NSFW Image DetectionYesNoNoNo
Toxicity DetectionYesNoNoNo
Macro DetectionYesYesYesYes
Language DetectionYes (40+)Yes (limited)

[!NOTE] Alternative to SpamAssassin: Spam Scanner provides a modern, Node.js-based alternative to SpamAssassin with AI-powered features and better privacy.

Alternative to rspamd: Spam Scanner offers easier configuration and better documentation than rspamd, with comparable detection accuracy.

Alternative to ClamAV: While Spam Scanner uses ClamAV for virus scanning, it provides comprehensive spam and phishing detection that ClamAV doesn't offer.


Architecture

System Overview

root@kitploit:~
graph TB
    A[Email Input] --> B{Spam Scanner}
    B --> C[Preprocessing]
    C --> D[Language Detection]
    D --> E[Tokenization]
    E --> F[Naive Bayes Classification]

    B --> G[Phishing Detection]
    G --> G1[IDN Homograph Check]
    G --> G2[Confusables Analysis]
    G --> G3[URL Analysis]

    B --> H[Attachment Scanning]
    H --> H1[Virus Scan]
    H --> H2[Executable Check]
    H --> H3[Macro Detection]
    H --> H4[NSFW Detection]

    B --> I[Content Analysis]
    I --> I1[Toxicity Detection]
    I --> I2[Pattern Recognition]

    F --> J[Result Aggregation]
    G --> J
    H --> J
    I --> J

    J --> K{Is Spam?}
    K -->|Yes| L[Spam Result]
    K -->|No| M[Ham Result]

Detection Flow

root@kitploit:~
sequenceDiagram
    participant Client
    participant Scanner
    participant Classifier
    participant ClamAV
    participant TensorFlow

    Client->>Scanner: scan(email)
    Scanner->>Scanner: Parse Email
    Scanner->>Scanner: Extract URLs
    Scanner->>Scanner: Detect Language

    par Parallel Detection
        Scanner->>Classifier: Classify Tokens
        Scanner->>ClamAV: Scan Attachments
        Scanner->>TensorFlow: Detect NSFW
        Scanner->>TensorFlow: Detect Toxicity
        Scanner->>Scanner: Check Phishing
        Scanner->>Scanner: Check Macros
    end

    Scanner->>Scanner: Aggregate Results
    Scanner->>Client: Return Result

Component Architecture

root@kitploit:~
graph LR
    A[Spam Scanner] --> B[Core Engine]
    A --> C[Classifiers]
    A --> D[Detectors]
    A --> E[Analyzers]

    B --> B1[Email Parser]
    B --> B2[Tokenizer]
    B --> B3[Preprocessor]

    C --> C1[Naive Bayes]
    C --> C2[TensorFlow NSFW]
    C --> C3[TensorFlow Toxicity]

    D --> D1[Phishing Detector]
    D --> D2[Virus Scanner]
    D --> D3[Macro Detector]
    D --> D4[Executable Detector]

    E --> E1[Language Analyzer]
    E --> E2[URL Analyzer]
    E --> E3[Pattern Analyzer]

Requirements

[!WARNING] ClamAV is required for virus scanning. If you do not have it installed, virus scanning will be disabled.

System Requirements

  • Node.js: >= 18.0.0
  • ClamAV: Latest version (for virus scanning)
  • Memory: 2GB+ RAM recommended (for TensorFlow models)
  • Disk Space: 500MB+ (for models and virus definitions)

Dependencies

  • @tensorflow/tfjs-node: For NSFW and toxicity detection
  • @ladjs/naivebayes: For spam classification
  • clamscan: For virus scanning
  • mailparser: For email parsing
  • natural: For NLP and tokenization
  • tldts: For TLD parsing
  • confusables: For Unicode confusables detection

Quick Start

Basic Usage

root@kitploit:~
import SpamScanner from 'spamscanner';

const scanner = new SpamScanner();

// Raw email string or Buffer
const email = `
From: [email protected]
To: [email protected]
Subject: Test Email

This is a test email.
`;

const result = await scanner.scan(email);

console.log(result);
// {
//   isSpam: false,
//   message: 'Ham',
//   results: { ... },
//   ...
// }

With Configuration

root@kitploit:~
import SpamScanner from 'spamscanner';

const scanner = new SpamScanner({
  // Enable performance metrics
  enablePerformanceMetrics: true,

  // Filter to supported languages
  supportedLanguages: ['en', 'es', 'fr', 'de'],

  // Enable macro detection
  enableMacroDetection: true,

  // Set scan timeout
  timeout: 30000,

  // Custom ClamAV configuration
  clamscan: {
    preference: 'clamdscan',
    clamdscanPath: '/usr/bin/clamdscan',
  },
});

const result = await scanner.scan(email);

Checking Specific Features

root@kitploit:~
// Check if email is spam
if (result.isSpam) {
  console.log('Spam detected!');
  console.log('Reason:', result.message);
}

// Check for viruses
if (result.results.viruses && result.results.viruses.length > 0) {
  console.log('Viruses found:', result.results.viruses);
}

// Check for phishing
if (result.results.phishing && result.results.phishing.length > 0) {
  console.log('Phishing detected:', result.results.phishing);
}

// Check for executables
if (result.results.executables && result.results.executables.length > 0) {
  console.log('Executables found:', result.results.executables);
}

// Check for NSFW content
if (result.results.nsfw && result.results.nsfw.length > 0) {
  console.log('NSFW content detected:', result.results.nsfw);
}

// Check for toxic language
if (result.results.toxicity && result.results.toxicity.length > 0) {
  console.log('Toxic language detected:', result.results.toxicity);
}

API Documentation

Constructor Options

new SpamScanner(options)

Creates a new Spam Scanner instance.

Options
OptionTypeDefaultDescription
enableMacroDetectionbooleantrueEnable macro detection in emails and attachments
enablePerformanceMetricsbooleanfalseTrack and return performance metrics
timeoutnumber30000Timeout in milliseconds for scans (virus, URL checks)
supportedLanguagesstring[]['en']Array of supported language codes. Empty array [] = all languages supported
enableMixedLanguageDetectionbooleanfalseEnable detection of mixed languages in emails
enableAdvancedPatternRecognitionbooleantrueEnable advanced pattern recognition (credit cards, phones, etc.)
toxicityThresholdnumber0.7Threshold for toxicity detection (0.0-1.0, higher = more strict)
nsfwThresholdnumber0.6Threshold for NSFW detection (0.0-1.0, higher = more strict)
debugbooleanfalseEnable debug logging
loggerobjectconsoleCustom logger object (must have log, error, warn methods)
clamscanobjectSee belowClamAV configuration options
ClamAV Options (clamscan)
OptionTypeDefaultDescription
removeInfectedbooleanfalseRemove infected files
quarantineInfectedbooleanfalseQuarantine infected files
scanLogstring|nullnullPath to scan log file
debugModebooleanfalseEnable ClamAV debug mode
fileListstring|nullnullPath to file list
scanRecursivelybooleantrueScan directories recursively
clamscanPathstring'/usr/bin/clamscan'Path to clamscan binary
clamdscanPathstring'/usr/bin/clamdscan'Path to clamdscan binary
preferencestring'clamdscan'Preferred scanner: 'clamdscan' or 'clamscan'
Example
root@kitploit:~
const scanner = new SpamScanner({
  enableMacroDetection: true,
  enablePerformanceMetrics: true,
  timeout: 60000,
  supportedLanguages: ['en', 'es', 'fr', 'de', 'ja', 'zh'],
  enableMixedLanguageDetection: false,
  enableAdvancedPatternRecognition: true,
  debug: false,
  logger: console,
  clamscan: {
    preference: 'clamdscan',
    clamdscanPath: '/usr/bin/clamdscan',
    scanRecursively: true,
    debugMode: false,
  },
});

Methods

scanner.scan(source)

Scans an email for spam, viruses, phishing, and other threats.

Parameters
  • source (string | Buffer) - Raw email content (RFC 822 format)
Returns

Promise<object> - Scan result object (see Result Object)

Example
root@kitploit:~
const result = await scanner.scan(emailString);
Edge Cases
  • Empty email: Returns isSpam: false with empty results
  • Invalid email format: Attempts to parse, may return partial results
  • Timeout: Returns partial results if scan exceeds timeout option
  • ClamAV unavailable: Skips virus scanning, continues with other checks
  • TensorFlow model loading: First scan may take 30+ seconds, subsequent scans are fast (models cached)

scanner.getTokensAndMailFromSource(source)

Parses email and extracts tokens for classification.

Parameters
  • source (string | Buffer) - Raw email content
Returns

Promise<object> - Object with tokens (array) and mail (parsed email object)

Example
root@kitploit:~
const {tokens, mail} = await scanner.getTokensAndMailFromSource(emailString);
console.log('Tokens:', tokens);
console.log('Subject:', mail.subject);

scanner.getClassification(tokens)

Classifies tokens as spam or ham using Naive Bayes classifier.

Parameters
  • tokens (string[]) - Array of tokens from email
Returns

Promise<object> - Classification result with category and probability

Example
root@kitploit:~
const classification = await scanner.getClassification(tokens);
console.log('Category:', classification.category); // 'spam' or 'ham'
console.log('Probability:', classification.probability); // 0.0 - 1.0

scanner.getPhishingResults(mail)

Detects phishing attempts in email.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of phishing detection results

Example
root@kitploit:~
const phishing = await scanner.getPhishingResults(mail);
// [
//   {
//     type: 'idn_homograph',
//     domain: 'аpple.com',
//     message: 'IDN homograph attack detected'
//   }
// ]

scanner.getExecutableResults(mail)

Detects executable files in email attachments.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of executable detection results

Example
root@kitploit:~
const executables = await scanner.getExecutableResults(mail);
// [
//   {
//     filename: 'malware.exe',
//     type: 'executable',
//     extension: 'exe',
//     risk: 'high'
//   }
// ]

scanner.getVirusResults(mail)

Scans email attachments for viruses using ClamAV.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of virus detection results

Example
root@kitploit:~
const viruses = await scanner.getVirusResults(mail);
// [
//   {
//     filename: 'infected.pdf',
//     virus: ['Trojan.PDF.Generic'],
//     type: 'virus'
//   }
// ]

scanner.getMacroResults(mail)

Detects macros in email content and attachments.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of macro detection results

Example
root@kitploit:~
const macros = await scanner.getMacroResults(mail);
// [
//   {
//     type: 'vba_macro',
//     message: 'VBA macro detected in email content'
//   }
// ]

scanner.getNSFWResults(mail)

Detects NSFW content in image attachments using TensorFlow.js.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of NSFW detection results

Example
root@kitploit:~
const nsfw = await scanner.getNSFWResults(mail);
// [
//   {
//     type: 'nsfw',
//     filename: 'image.jpg',
//     category: 'Porn',
//     probability: 0.85,
//     description: 'NSFW image detected: Porn (85.0%)'
//   }
// ]

scanner.getToxicityResults(mail)

Detects toxic language in email content using TensorFlow.js.

Parameters
  • mail (object) - Parsed email object from mailparser
Returns

Promise<array> - Array of toxicity detection results

Example
root@kitploit:~
const toxicity = await scanner.getToxicityResults(mail);
// [
//   {
//     type: 'toxicity',
//     category: 'threat',
//     probability: 0.92,
//     description: 'Toxic content detected: threat (92.0%)'
//   },
//   {
//     type: 'toxicity',
//     category: 'insult',
//     probability: 0.78,
//     description: 'Toxic content detected: insult (78.0%)'
//   }
// ]

scanner.getTokens(str, locale, isHTML)

Tokenizes text for classification.

Parameters
  • str (string) - Text to tokenize
  • locale (string) - Language code (e.g., "en", "es", "fr")
  • isHTML (boolean) - Whether text contains HTML (default: false)
Returns

Promise<string[]> - Array of tokens

Example
root@kitploit:~
const tokens = await scanner.getTokens('Hello world', 'en', false);
// ['hello', 'world']

scanner.parseLocale(locale)

Normalizes language codes to standard format.

Parameters
  • locale (string) - Language code or locale string
Returns

string - Normalized language code

Example
root@kitploit:~
const normalized = scanner.parseLocale('en-US');
// 'en'

scanner.detectLanguageHybrid(text)

Detects language using hybrid franc/lande approach.

Parameters
  • text (string) - Text to analyze
Returns

Promise<string> - Detected language code

Example
root@kitploit:~
const language = await scanner.detectLanguageHybrid('Bonjour le monde');
// 'fr'

scanner.extractAllUrls(mail, originalSource)

Extracts all URLs from email.

Parameters
  • mail (object) - Parsed email object
  • originalSource (string) - Original email source
Returns

string[] - Array of URLs

Example
root@kitploit:~
const urls = scanner.extractAllUrls(mail, emailString);
// ['https://example.com', 'http://test.com']

scanner.parseUrlWithTldts(url)

Parses URL using tldts for accurate TLD extraction.

Parameters
  • url (string) - URL to parse
Returns

object - Parsed URL components

Example
root@kitploit:~
const parsed = scanner.parseUrlWithTldts('https://subdomain.example.co.uk/path');
// {
//   domain: 'example.co.uk',
//   subdomain: 'subdomain',
//   hostname: 'subdomain.example.co.uk',
//   publicSuffix: 'co.uk',
//   isIp: false
// }

Result Object

The scan() method returns a comprehensive result object:

root@kitploit:~
{
  // Overall spam classification
  isSpam: boolean,
  message: string, // 'Ham' or 'Spam: <reasons>'

  // Detection results
  results: {
    // Classification details
    classification: {
      category: 'spam' | 'ham',
      probability: number
    },

    // Phishing detection
    phishing: [
      {
        type: 'idn_homograph' | 'suspicious_link' | 'confusables',
        domain: string,
        message: string
      }
    ],

    // Executable detection
    executables: [
      {
        filename: string,
        type: 'executable' | 'office_document' | 'legacy_office' | 'pdf_javascript' | 'archive',
        extension: string,
        risk: 'high' | 'medium' | 'low'
      }
    ],

    // Macro detection
    macros: [
      {
        type: 'vba_macro' | 'powershell' | 'javascript' | 'batch',
        message: string
      }
    ],

    // Arbitrary results (custom detections)
    arbitrary: [],

    // Virus scanning
    viruses: [
      {
        filename: string,
        virus: string[],
        type: 'virus'
      }
    ],

    // Pattern recognition
    patterns: {
      credit_cards: number,
      phone_numbers: number,
      emails: number,
      ips: number,
      urls: number,
      bitcoin: number,
      dates: number,
      file_paths: number
    },

    // IDN homograph attack detection
    idnHomographAttack: [],

    // Toxicity detection (array of results)
    toxicity: [
      {
        type: 'toxicity',
        category: 'identity_attack' | 'insult' | 'obscene' | 'severe_toxicity' | 'sexual_explicit' | 'threat',
        probability: number,
        description: string
      }
    ],

    // NSFW detection (array of results)
    nsfw: [
      {
        type: 'nsfw',
        filename: string,
        category: 'Porn' | 'Hentai' | 'Sexy' | 'Neutral' | 'Drawing',
        probability: number,
        description: string
      }
    ]
  },

  // All URLs extracted from email
  links: string[],

  // Tokens extracted from email
  tokens: string[],

  // Email metadata
  mail: {
    from: object,
    to: object[],
    subject: string,
    text: string,
    html: string,
    attachments: object[],
    headers: object
  },

  // Performance metrics (if enabled)
  metrics: {
    totalTime: number, // milliseconds
    classificationTime: number,
    phishingTime: number,
    executableTime: number,
    macroTime: number,
    virusTime: number,
    patternTime: number,
    idnTime: number,
    memoryUsage: object
  }
}

Advanced Usage

Custom Classifier

root@kitploit:~
import SpamScanner from 'spamscanner';
import NaiveBayes from '@ladjs/naivebayes';

// Train custom classifier
const classifier = new NaiveBayes();
classifier.learn('buy viagra now', 'spam');
classifier.learn('hello friend', 'ham');

const scanner = new SpamScanner({
  classifier: classifier.toJson()
});

Custom Text Replacements

root@kitploit:~
const scanner = new SpamScanner({
  replacements: new Map([
    ['u', 'you'],
    ['ur', 'your'],
    ['r', 'are'],
    ['b4', 'before']
  ])
});

Language Filtering

root@kitploit:~
// Only accept English, Spanish, and French emails
const scanner = new SpamScanner({
  supportedLanguages: ['en', 'es', 'fr']
});

// Accept all languages
const scanner2 = new SpamScanner({
  supportedLanguages: []
});

Performance Monitoring

root@kitploit:~
const scanner = new SpamScanner({
  enablePerformanceMetrics: true
});

const result = await scanner.scan(email);

console.log('Total scan time:', result.metrics.totalTime, 'ms');
console.log('Classification time:', result.metrics.classificationTime, 'ms');
console.log('Virus scan time:', result.metrics.virusScanTime, 'ms');

Selective Feature Disabling

root@kitploit:~
// Disable macro detection for performance
const scanner = new SpamScanner({
  enableMacroDetection: false
});

// Disable advanced pattern recognition
const scanner2 = new SpamScanner({
  enableAdvancedPatternRecognition: false
});

Custom Timeout

root@kitploit:~
// Set 60-second timeout for slow scans
const scanner = new SpamScanner({
  timeout: 60000
});

Custom Logger

root@kitploit:~
import winston from 'winston';

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ filename: 'spam-scanner.log' })
  ]
});

const scanner = new SpamScanner({
  debug: true,
  logger: logger
});

ARF (Abuse Reporting Format)

SpamScanner includes a native ARF (Abuse Reporting Format) parser for handling email feedback reports from ISPs and email providers.

Parsing ARF Reports

root@kitploit:~
import {ArfParser} from 'spamscanner/arf';
import fs from 'node:fs';

// Read an ARF report email
const arfEmail = fs.readFileSync('feedback_report.eml');

// Parse the ARF report
const report = await ArfParser.parse(arfEmail);

console.log('Feedback Type:', report.feedbackType);
console.log('Source IP:', report.sourceIp);
console.log('Original Sender:', report.originalMailFrom);
console.log('Original Recipients:', report.originalRcptTo);

Safe Parsing

root@kitploit:~
// Use tryParse for safe parsing (returns null if not ARF)
const report = await ArfParser.tryParse(emailContent);

if (report) {
  console.log('ARF report detected:', report.feedbackType);
} else {
  console.log('Not an ARF report');
}

Creating ARF Reports

root@kitploit:~
import {ArfParser} from 'spamscanner/arf';

const arfMessage = ArfParser.create({
  feedbackType: 'abuse',
  userAgent: 'MyMailServer/1.0',
  from: '[email protected]',
  to: '[email protected]',
  originalMessage: originalEmailContent,
  humanReadable: 'This email was reported as spam by our users.',
  sourceIp: '192.168.1.100',
  originalMailFrom: '[email protected]',
  originalRcptTo: ['[email protected]'],
  arrivalDate: new Date(),
  reportingMta: 'mail.yourdomain.com',
});

// Send arfMessage to the abuse address

ARF Result Object

PropertyTypeDescription
isArfbooleanWhether this is a valid ARF message
feedbackTypestringType: abuse, fraud, virus, other, not-spam, auth-failure, dmarc
userAgentstringUser agent that generated the report
versionstringARF version (usually "1")
sourceIpstringSource IP of the original message
originalMailFromstringOriginal MAIL FROM address
originalRcptTostring[]Original RCPT TO addresses
arrivalDateDateWhen the original message arrived
reportingMtaobjectReporting MTA info ({type, name})
incidentsnumberNumber of incidents reported
humanReadablestringHuman-readable description
originalMessagestringThe original reported message
originalHeadersobjectParsed headers from original message

Mail Server Integration

SpamScanner can be integrated with popular mail servers like Postfix and Dovecot as a content filter.

Postfix Integration

Using Pipe Content Filter

This is the recommended method for most Postfix setups.

  1. Create a dedicated user (recommended for security):
root@kitploit:~
sudo useradd -r -s /bin/false spamscanner
  1. Edit /etc/postfix/master.cf:
root@kitploit:~
# SpamScanner content filter
spamscanner unix - n n - - pipe
  flags=Rq user=spamscanner argv=/usr/local/bin/spamscanner scan -
  1. Edit /etc/postfix/main.cf:
root@kitploit:~
content_filter = spamscanner:dummy
  1. Reload Postfix:
root@kitploit:~
sudo postfix reload

Postfix will now pipe all incoming emails to SpamScanner. If SpamScanner exits with code 1 (spam), Postfix will reject the message.

Dovecot Integration

Using Sieve and Pipe

  1. Enable Pigeonhole Sieve (ensure dovecot-pigeonhole is installed)

  2. Create a Sieve script (/var/lib/dovecot/sieve/default.sieve):

root@kitploit:~
require ["vnd.dovecot.pipe"];

# Scan all incoming mail
if header :contains "X-Spam-Flag" "NO" {
  pipe "/usr/local/bin/spamscanner-sieve-helper";
}
  1. Create a helper script (/usr/local/bin/spamscanner-sieve-helper):
root@kitploit:~
#!/bin/bash
EMAIL=$(cat)
RESULT=$(echo "$EMAIL" | /usr/local/bin/spamscanner scan -)
if [[ $? -eq 1 ]]; then
  echo "X-Spam-Flag: YES" | cat - <(echo "$EMAIL")
else
  echo "$EMAIL"
fi

TCP Server Mode

For high-volume environments, run SpamScanner as a persistent TCP server:

root@kitploit:~
# Start the server
spamscanner server --port 7830 --host 127.0.0.1

Systemd Service

Create /etc/systemd/system/spamscanner.service:

root@kitploit:~
[Unit]
Description=SpamScanner TCP Server
After=network.target

[Service]
Type=simple
User=spamscanner
ExecStart=/usr/local/bin/spamscanner server --port 7830
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

Enable and start:

root@kitploit:~
sudo systemctl enable spamscanner
sudo systemctl start spamscanner

Client Example

root@kitploit:~
# Send email to TCP server and get JSON response
cat email.eml | nc localhost 7830

Performance

Benchmarks

Scan TypeFirst ScanSubsequent ScansNotes
Small Email (< 10KB)2-3s200-500msNo attachments
Medium Email (10-100KB)3-5s500ms-1s1-2 attachments
Large Email (100KB-1MB)5-10s1-3sMultiple attachments
With NSFW Detection+30s (first)+100-200msTensorFlow model loading
With Toxicity Detection+30s (first)+100-200msTensorFlow model loading

[!NOTE] First scans with TensorFlow models (NSFW/toxicity) take 30+ seconds due to model loading. Subsequent scans are fast because models are cached in memory.

Optimization Tips

  1. Model Caching: Keep scanner instance alive to cache TensorFlow models
  2. Disable Unused Features: Turn off macro detection or pattern recognition if not needed
  3. Adjust Timeout: Increase timeout for large emails with many attachments
  4. Use clamdscan: Prefer clamdscan over clamscan for faster virus scanning
  5. Limit Languages: Specify supportedLanguages to skip unnecessary language detection

Memory Usage

  • Base: 50-100MB
  • With TensorFlow Models: 500MB-1GB
  • Per Scan: 10-50MB (temporary)

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

root@kitploit:~
# Clone repository
git clone https://github.com/spamscanner/spamscanner.git
cd spamscanner

# Install dependencies
pnpm install

# Run tests
npm test

# Run tests with coverage
npm run test-coverage

# Build
pnpm run build

Running Tests

root@kitploit:~
# All tests
npm test

# Specific test file
node --test test/test.js

# With coverage
npm run test-coverage

License

Business Source License 1.1 © Forward Email

Support

  • Documentation: https://spamscanner.net
  • Issues: GitHub Issues
  • Email: mailto:[email protected]

Acknowledgments

  • Forward Email - Production usage and testing
  • TensorFlow.js - NSFW and toxicity detection
  • ClamAV - Virus scanning
  • Natural - NLP and tokenization
  • tldts - TLD parsing
  • confusables - Unicode confusables detection

Made with ❤️ by the Forward Email team

#

Download Tool
ukUkrainianbeBelarusianltLithuanian
lvLatvianetEstoniancaCatalan
euBasqueglGaliciangaIrish
gdScottish GaeliccyWelshisIcelandic
mtMalteseafAfrikaansswSwahili
amAmharichaHausayoYoruba
igIgbosoSomaliomOromo
tiTigrinyamgMalagasynyChichewa
snShonaxhXhosazuZulu
stSouthern SothotnTswana
Yes (limited)
No
Pattern RecognitionYesYesYesNo
Executable DetectionYes (195+)YesYesYes
Magic Number VerificationYesNoNoYes
PDF JavaScript DetectionYesNoNoPartial
Archive DetectionYesYesYesYes
Performance MetricsYesNoYesNo
TypeScript SupportYesNoNoNo
Active DevelopmentYesYesYesYes
Production ReadyYesYesYesYes
classifier
object
null
Custom Naive Bayes classifier data
replacementsMap|objectnullCustom text replacements for preprocessing