npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

spamd-client

v1.0.1

Published

NodeJS client for connecting to spamd/spamc server

Downloads

179

Readme

SpamD Network Client

This library is NodeJS driver for Spamassassin spamd protocol built over TCP. Allow check emails via Spamassassin from NodeJS.

Implemented protocol methods

  • [X] CHECK
  • [X] HEADERS
  • [X] PROCESS
  • [X] REPORT
  • [X] REPORT_IFSPAM
  • [X] SYMBOLS
  • [ ] TELL
  • [ ] PING

API Documentation

Api built for convenient usage in point-free style. Using native Promises.

TOC

Connection

Actions

Connection

Connection.of

Function Connection.of(options: SpamdClientOptions): () => Promise<Connection>

Factory for creating connection by given schema.

Parameters:

| Name | Type | | ------ | ------ | | options | SpamdClientOptions |

SpamdClientOptions

{
    host: string
    port: number
}

Returns: () => Promise<Connection>

Example:

import { Connection, Action } from 'spamd-client'

const connect = Connection.of({ host: 'example.com', port: 2233 })

connect()
  .then(Action.check('<your_email_body>'))
  .then(console.log) // EX: { isSpam: true, score: -0.8, threshold: 5 }
  .catch(console.error) // EX: Error: Cannot connect

Actions

Action.check

Function Action.check(email: string): (connection: Connection) => Promise<CheckResult>

Instruct SpamAssassin to process the included message.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<CheckResult>

CheckResult

{
  isSpam: boolean
  score: number
  threshold: number
}

Action.headers

Function Action.headers(email: string): (connection: Connection) => Promise<HeadersResult>

Instruct SpamAssassin to process the included message.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<HeadersResult>

HeadersResult

{
  spamReport: {
    isSpam: boolean
    score: number
    threshold: number
  },
  body: string
}

Example

{
  spamReport: {
    isSpam: true,
    score: -0.9,
    threshold: 5,
  },
  body: `
    Received: from localhost by debian
        with SpamAssassin (version 3.4.0);
        Tue, 10 Jan 2017 11:09:26 -0500
    From: Sender <[email protected]>
    To: Recipient <[email protected]>
    Subject: Test spam mail (GTUBE)
    Date: Wed, 23 Jul 2003 23:30:00 +0200
    Message-Id: <[email protected]>
    X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on debian
    X-Spam-Flag: YES
    X-Spam-Level: **************************************************
    X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,NO_RECEIVED,
        NO_RELAYS autolearn=no autolearn_force=no version=3.4.0
    MIME-Version: 1.0Content-Type: multipart/mixed; boundary="----------=_58750736.8D9F70BC"
  `
}

Action.process

Function Action.process(email: string): (connection: Connection) => Promise<ProcessResult>

Instruct SpamAssassin to process the message and return the modified message.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<ProcessReport>

ProcessResult

{
  spamReport: {
    isSpam: boolean
    score: number
    threshold: number
  },
  body: string
}

Example

{
  spamReport: {
    isSpam: true,
    score: -0.9,
    threshold: 5,
  },
  body: `
    Received: from localhost by debian
    with SpamAssassin (version 3.4.0);
    Tue, 10 Jan 2017 10:57:02 -0500
    From: Sender <[email protected]>
    To: Recipient <[email protected]>
    Subject: Test spam mail (GTUBE)
    Date: Wed, 23 Jul 2003 23:30:00 +0200
    Message-Id: <[email protected]>
    X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on debian
    X-Spam-Flag: YES
    X-Spam-Level: **************************************************
    X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,NO_RECEIVED,
        NO_RELAYS autolearn=no autolearn_force=no version=3.4.0
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary="----------=_5875044E.D4EFFFD7"

    This is a multi-part message in MIME format.

    ------------=_5875044E.D4EFFFD7
    Content-Type: text/plain; charset=iso-8859-1
    Content-Disposition: inline
    Content-Transfer-Encoding: 8bit

    Spam detection software, running on the system "debian",
    has identified this incoming email as possible spam.  The original
    message has been attached to this so you can view it or label
    similar future email.  If you have any questions, see
    @@CONTACT_ADDRESS@@ for details.

    Content preview:  This is the GTUBE, the Generic Test for Unsolicited Bulk Email
    If your spam filter supports it, the GTUBE provides a test by which you can
    verify that the filter is installed correctly and is detecting incoming spam.
    You can send yourself a test mail containing the following string of characters
    (in upper case and with no white spaces and line breaks): [...]

    Content analysis details:   (1000.0 points, 5.0 required)

    pts rule name              description
    ---- ---------------------- --------------------------------------------------
    1000 GTUBE                  BODY: Generic Test for Unsolicited Bulk Email
    -0.0 NO_RELAYS              Informational: message was not relayed via SMTP
    -0.0 NO_RECEIVED            Informational: message has no Received headers



    ------------=_5875044E.D4EFFFD7
    Content-Type: message/rfc822; x-spam-type=original
    Content-Description: original message before SpamAssassin
    Content-Disposition: inline
    Content-Transfer-Encoding: 8bit

    Subject: Test spam mail (GTUBE)
    Message-ID: <[email protected]>
    Date: Wed, 23 Jul 2003 23:30:00 +0200
    From: Sender <[email protected]>
    To: Recipient <[email protected]>
    Precedence: junk
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit

    This is the GTUBE, the
        Generic
        Test for
        Unsolicited
        Bulk
        Email

    If your spam filter supports it, the GTUBE provides a test by which you
    can verify that the filter is installed correctly and is detecting incoming
    spam. You can send yourself a test mail containing the following string of
    characters (in upper case and with no white spaces and line breaks):

    XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

    You should send this test mail from an account outside of your network.


    ------------=_5875044E.D4EFFFD7--
  `
}

Action.report

Function Action.report(email: string): (connection: Connection) => Promise<ReportResult>

Send a request to process a message and return a report.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<ReportResult>

ReportResult

{
  spamReport: {
    isSpam: boolean
    score: number
    threshold: number
  },
  body: string
}

Example

{
  spamReport: {
    isSpam: true,
    score: -0.9,
    threshold: 5,
  },
  body: `
    Spam detection software, running on the system "debian",
    has identified this incoming email as possible spam.  The original
    message has been attached to this so you can view it or label
    similar future email.  If you have any questions, see
    @@CONTACT_ADDRESS@@ for details.

    Content preview:  This is the GTUBE, the Generic Test for Unsolicited Bulk Email
      If your spam filter supports it, the GTUBE provides a test by which you can
      verify that the filter is installed correctly and is detecting incoming spam.
      You can send yourself a test mail containing the following string of characters
      (in upper case and with no white spaces and line breaks): [...]

    Content analysis details:   (1000.0 points, 5.0 required)

    pts rule name              description
    ---- ---------------------- --------------------------------------------------
    1000 GTUBE                  BODY: Generic Test for Unsolicited Bulk Email
    -0.0 NO_RELAYS              Informational: message was not relayed via SMTP
    -0.0 NO_RECEIVED            Informational: message has no Received headers
  `
}

Action.reportIfSpam

Function Action.reportIfSpam(email: string): (connection: Connection) => Promise<ReportIfSpamResult>

Send a request to process a message and return a report only if spam detected.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<ReportIfSpamResult>

ReportIfSpamResult

{
  spamReport: {
    isSpam: boolean
    score: number
    threshold: number
  },
  body: string
}

Example

Produce the same that report action described above.


Action.symbols

Function Action.symbols(email: string): (connection: Connection) => Promise<SymbolsResult>

Send a request to process a message and return a report.

Parameters:

| Name | Type | Description | | ------ | ------ | ------ | | email | string | An email based on the RFC 5322 standard. |

Returns: (connection: Connection) => Promise<SymbolsResult>

SymbolsResult

{
  spamReport: {
    isSpam: boolean
    score: number
    threshold: number
  },
  body: string
}

Example

{
  spamReport: {
    isSpam: true,
    score: -0.9,
    threshold: 5,
  },
  body: [
    'GTUBE',
    'NO_RECEIVED',
    'NO_RELAYS'
  ]
}

License

The MIT License (MIT)

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.