Ruby client for Rspamd’s HTTP API

Usage

Initialize a client with the host and port of an Rspamd controller process:

client = Rspamd::Client.new(host: "localhost", port: 11334)

Check a message:

result = client.check(<<~MIME)
  Date: Tue, 21 Jan 2020 21:04:42 +0000
  From: Alice <[email protected]>
  To: Bob <[email protected]>
  Message-ID: <[email protected]>
  Subject: Hello
  Mime-Version: 1.0
  Content-Type: text/plain; charset=UTF-8
  Content-Transfer-Encoding: quoted-printable
  Delivered-To: [email protected]

  Hi Bob!

  -Alice
MIME

result.spam? # => false
result.ham? # => true

result.score # => 1.2
result.required_score # => 15
result.action # => "no action"

Report a message as spam:

client.spam!(<<~MIME)
  Date: Tue, 21 Jan 2020 21:04:42 +0000
  From: Spammer <[email protected]>
  To: Bob <[email protected]>
  Message-ID: <[email protected]>
  Subject: Hello
  Mime-Version: 1.0
  Content-Type: text/plain; charset=UTF-8
  Content-Transfer-Encoding: quoted-printable
  Delivered-To: [email protected]

  Buy some stuff?
MIME

Report a message as ham:

client.ham!(<<~MIME)
  Date: Tue, 21 Jan 2020 21:04:42 +0000
  From: Alice <[email protected]>
  To: Bob <[email protected]>
  Message-ID: <[email protected]>
  Subject: Hello
  Mime-Version: 1.0
  Content-Type: text/plain; charset=UTF-8
  Content-Transfer-Encoding: quoted-printable
  Delivered-To: [email protected]

  Hi Bob!

  -Alice
MIME