项目作者: sjinnovation

项目描述 :
NodeJS client for connecting to spamd/spamc server
高级语言: TypeScript
项目地址: git://github.com/sjinnovation/spamd-client.git
创建时间: 2018-12-14T09:42:51Z
项目社区:https://github.com/sjinnovation/spamd-client

开源协议:MIT License

下载


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

Connection

Connection.of

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

Factory for creating connection by given schema.

Parameters:

Name Type
options SpamdClientOptions

SpamdClientOptions

  1. {
  2. host: string
  3. port: number
  4. }

Returns: () => Promise<Connection>

Example:

  1. import { Connection, Action } from 'spamd-client'
  2. const connect = Connection.of({ host: 'example.com', port: 2233 })
  3. connect()
  4. .then(Action.check('<your_email_body>'))
  5. .then(console.log) // EX: { isSpam: true, score: -0.8, threshold: 5 }
  6. .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

  1. {
  2. isSpam: boolean
  3. score: number
  4. threshold: number
  5. }

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

  1. {
  2. spamReport: {
  3. isSpam: boolean
  4. score: number
  5. threshold: number
  6. },
  7. body: string
  8. }

Example

  1. {
  2. spamReport: {
  3. isSpam: true,
  4. score: -0.9,
  5. threshold: 5,
  6. },
  7. body: `
  8. Received: from localhost by debian
  9. with SpamAssassin (version 3.4.0);
  10. Tue, 10 Jan 2017 11:09:26 -0500
  11. From: Sender <sender@example.net>
  12. To: Recipient <recipient@example.net>
  13. Subject: Test spam mail (GTUBE)
  14. Date: Wed, 23 Jul 2003 23:30:00 +0200
  15. Message-Id: <GTUBE1.1010101@example.net>
  16. X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on debian
  17. X-Spam-Flag: YES
  18. X-Spam-Level: **************************************************
  19. X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,NO_RECEIVED,
  20. NO_RELAYS autolearn=no autolearn_force=no version=3.4.0
  21. MIME-Version: 1.0Content-Type: multipart/mixed; boundary="----------=_58750736.8D9F70BC"
  22. `
  23. }

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

  1. {
  2. spamReport: {
  3. isSpam: boolean
  4. score: number
  5. threshold: number
  6. },
  7. body: string
  8. }

Example

  1. {
  2. spamReport: {
  3. isSpam: true,
  4. score: -0.9,
  5. threshold: 5,
  6. },
  7. body: `
  8. Received: from localhost by debian
  9. with SpamAssassin (version 3.4.0);
  10. Tue, 10 Jan 2017 10:57:02 -0500
  11. From: Sender <sender@example.net>
  12. To: Recipient <recipient@example.net>
  13. Subject: Test spam mail (GTUBE)
  14. Date: Wed, 23 Jul 2003 23:30:00 +0200
  15. Message-Id: <GTUBE1.1010101@example.net>
  16. X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on debian
  17. X-Spam-Flag: YES
  18. X-Spam-Level: **************************************************
  19. X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,NO_RECEIVED,
  20. NO_RELAYS autolearn=no autolearn_force=no version=3.4.0
  21. MIME-Version: 1.0
  22. Content-Type: multipart/mixed; boundary="----------=_5875044E.D4EFFFD7"
  23. This is a multi-part message in MIME format.
  24. ------------=_5875044E.D4EFFFD7
  25. Content-Type: text/plain; charset=iso-8859-1
  26. Content-Disposition: inline
  27. Content-Transfer-Encoding: 8bit
  28. Spam detection software, running on the system "debian",
  29. has identified this incoming email as possible spam. The original
  30. message has been attached to this so you can view it or label
  31. similar future email. If you have any questions, see
  32. @@CONTACT_ADDRESS@@ for details.
  33. Content preview: This is the GTUBE, the Generic Test for Unsolicited Bulk Email
  34. If your spam filter supports it, the GTUBE provides a test by which you can
  35. verify that the filter is installed correctly and is detecting incoming spam.
  36. You can send yourself a test mail containing the following string of characters
  37. (in upper case and with no white spaces and line breaks): [...]
  38. Content analysis details: (1000.0 points, 5.0 required)
  39. pts rule name description
  40. ---- ---------------------- --------------------------------------------------
  41. 1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email
  42. -0.0 NO_RELAYS Informational: message was not relayed via SMTP
  43. -0.0 NO_RECEIVED Informational: message has no Received headers
  44. ------------=_5875044E.D4EFFFD7
  45. Content-Type: message/rfc822; x-spam-type=original
  46. Content-Description: original message before SpamAssassin
  47. Content-Disposition: inline
  48. Content-Transfer-Encoding: 8bit
  49. Subject: Test spam mail (GTUBE)
  50. Message-ID: <GTUBE1.1010101@example.net>
  51. Date: Wed, 23 Jul 2003 23:30:00 +0200
  52. From: Sender <sender@example.net>
  53. To: Recipient <recipient@example.net>
  54. Precedence: junk
  55. MIME-Version: 1.0
  56. Content-Type: text/plain; charset=us-ascii
  57. Content-Transfer-Encoding: 7bit
  58. This is the GTUBE, the
  59. Generic
  60. Test for
  61. Unsolicited
  62. Bulk
  63. Email
  64. If your spam filter supports it, the GTUBE provides a test by which you
  65. can verify that the filter is installed correctly and is detecting incoming
  66. spam. You can send yourself a test mail containing the following string of
  67. characters (in upper case and with no white spaces and line breaks):
  68. XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
  69. You should send this test mail from an account outside of your network.
  70. ------------=_5875044E.D4EFFFD7--
  71. `
  72. }

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

  1. {
  2. spamReport: {
  3. isSpam: boolean
  4. score: number
  5. threshold: number
  6. },
  7. body: string
  8. }

Example

  1. {
  2. spamReport: {
  3. isSpam: true,
  4. score: -0.9,
  5. threshold: 5,
  6. },
  7. body: `
  8. Spam detection software, running on the system "debian",
  9. has identified this incoming email as possible spam. The original
  10. message has been attached to this so you can view it or label
  11. similar future email. If you have any questions, see
  12. @@CONTACT_ADDRESS@@ for details.
  13. Content preview: This is the GTUBE, the Generic Test for Unsolicited Bulk Email
  14. If your spam filter supports it, the GTUBE provides a test by which you can
  15. verify that the filter is installed correctly and is detecting incoming spam.
  16. You can send yourself a test mail containing the following string of characters
  17. (in upper case and with no white spaces and line breaks): [...]
  18. Content analysis details: (1000.0 points, 5.0 required)
  19. pts rule name description
  20. ---- ---------------------- --------------------------------------------------
  21. 1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email
  22. -0.0 NO_RELAYS Informational: message was not relayed via SMTP
  23. -0.0 NO_RECEIVED Informational: message has no Received headers
  24. `
  25. }

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

  1. {
  2. spamReport: {
  3. isSpam: boolean
  4. score: number
  5. threshold: number
  6. },
  7. body: string
  8. }

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

  1. {
  2. spamReport: {
  3. isSpam: boolean
  4. score: number
  5. threshold: number
  6. },
  7. body: string
  8. }

Example

  1. {
  2. spamReport: {
  3. isSpam: true,
  4. score: -0.9,
  5. threshold: 5,
  6. },
  7. body: [
  8. 'GTUBE',
  9. 'NO_RECEIVED',
  10. 'NO_RELAYS'
  11. ]
  12. }

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.