====== SpamAssassin Bayes Trainer ======
This module trains the [[howto:spamd|SpamAssassin]] Bayesian classifier from
e-mail: hand it a message and it tells the SpamAssassin server (''spamd'') to
learn that message as //spam// or //ham// (legitimate mail).

The ''spamd'' server must be started with the ''%%--allow-tell%%'' option, which
enables its learn command.

===== Source =====
Current version of ''spamlearn.js'' is available in the Synchronet [[dev:Git]] Repository.

''spamlearn.js'' is dependent on ''[[https://gitlab.synchro.net/main/sbbs/-/blob/master/exec/load/salib.js|salib.js]]''.

===== Training by e-mail =====

Configure one or two //learn// addresses as [[config:mailproc.ini|external mail
processors]], each gated to the sysop (user #1) so that no one else can feed --
and poison -- your Bayes database:

<file mailproc.ini>
[spamlearn.js spam]
to = spamlearn
passthru = false
AccessRequirements = user equal 1

[spamlearn.js ham]
to = hamlearn
passthru = false
AccessRequirements = user equal 1
</file>

When you receive spam that was not caught, **redirect** it to your ''spamlearn''
address; when good mail is wrongly tagged as spam, redirect it to ''hamlearn''.

**Redirect (resend), do not forward.** A redirect delivers the original message
unchanged, which is what the classifier needs to learn from. A normal //forward//
rewrites the headers and re-encodes the body, so the classifier would learn your
forwarding wrapper instead of the original message. (Most mail clients have a
Redirect or Resend command, sometimes only via an add-on.)

''passthru = false'' causes the message to be consumed once it has been learned:
it is not delivered or bounced.

===== Honeypot / spam-trap auto-training =====

Mail sent to a //spam-trap// (honeypot) address is spam by definition, so it can
train Bayes automatically, with no redirecting on your part. Add the ''block''
option -- which also adds the sender to the IP filter after learning -- and list
your trap addresses:

<file mailproc.ini>
[spamlearn.js spam block]
to = trap1, trap2
passthru = false
ProcessDNSBL = true
ProcessSpam = true
</file>

List a trap section **before** your ''[SPAMC]'' scanning section so trap mail is
learned and blocked rather than scanned and rejected first. There are no
''AccessRequirements'' here on purpose -- mail from outsiders is exactly what a
trap is meant to catch.

Use this in place of a [[config:spambait.cfg|spambait.cfg]] entry when you want
trap hits to //train// Bayes as well as block the sender: a spambait.cfg address
only blocks, because it is handled before any external mail processor runs.

===== Options =====

  spam | ham        message class to learn (default: spam)
  block [seconds]   after learning, add the sender's IP to the filter
                    (default: 180 days)
  dest <ip_address> (also -d)
  port <tcp_port> (also -p)
  username <user> (also -u)
  max-size <bytes> (also -s)
  debug

===== See Also =====
  * [[:howto:spamd|How To Use SpamAssassin with the Synchronet Mail Server]]
  * [[:module:spamc|SpamAssassin Client]]
  * [[:config:mailproc.ini]]
  * [[:server:mail|Mail Server]]
  * [[:module:|Modules]]

{{tag>spam email antispam bayes}}
