The SpamAssassin Network Protocol
=================================

(This document is still a draft)

Synopsis
--------

The protocol for communication between spamc/spamd is somewhat HTTP like.  The
conversation looks like:

               spamc --> PROCESS SPAMC/1.2
               spamc --> Content-length: <size>
  (optional)   spamc --> User: <username>
               spamc --> \r\n [blank line]
               spamc --> --message sent here--

               spamd --> SPAMD/1.1 0 EX_OK
               spamd --> Content-length: <size>
               spamd --> \r\n [blank line]
               spamd --> --processed message sent here--

After each side is done writing, it shuts down its side of the connection.

The first line from spamc is the command for spamd to execute (PROCESS a
message is the command in protocol<=1.2) followed by the protocol version.

The first line of the response from spamd is the protocol version (note this is
SPAMD here, where it was SPAMC on the other side) followed by a response code
from sysexits.h followed by a response message string which describes the error
if there was one.  If the response code is not 0, then the processed message
will not be sent, and the socket will be closed after the first line is sent.


Commands
--------

The following commands are defined as of protocol 1.2:

CHECK         --  Just check if the passed message is spam or not and reply as
                  described below

SYMBOLS       --  Check if message is spam or not, and return score plus list
                  of symbols hit

REPORT        --  Check if message is spam or not, and return score plus report

REPORT_IFSPAM --  Check if message is spam or not, and return score plus report
                  if the message is spam

SKIP          --  Ignore this message -- client opened connection then changed
                  its mind

PING          --  Return a confirmation that spamd is alive.

PROCESS       --  Process this message as described above and return modified
                  message


CHECK command returns just a header (terminated by "\r\n\r\n") with the first
line as for PROCESS (ie a response code and message), and then a header called
"Spam:" with value of either "True" or "False", then a semi-colon, and then the
score for this message, " / " then the threshold.  So the entire response looks
like either:

	SPAMD/1.1 0 EX_OK
	Spam: True ; 15 / 5

or

	SPAMD/1.1 0 EX_OK
	Spam: False ; 2 / 5


SYMBOLS command returns the same as CHECK, followed by a line listing all the
rule names, separated by commas.  Note that some versions of the protocol
terminate this line with "\r\n", and some do not, due to an oversight; so
clients should be flexible on whether or not a CR-LF pair follows
the symbol text, and how many CR-LFs there are.


REPORT command returns the same as CHECK, followed immediately by the report
generated by spamd:

	SPAMD/1.1 0 EX_OK
	Spam: False ; 2 / 5

	This mail is probably spam.  The original message has been attached
	along with this report, so you can recognize or block similar unwanted
	mail in future.  See http://spamassassin.apache.org/tag/ for more details.
	[...]

Note that the superfluous-score/threshold-line bug that appeared in
SpamAssassin 2.5x is fixed.

Clients should be flexible on whether or not a CR-LF pair follows
the report text, and how many CR-LFs there are.


REPORT_IFSPAM returns the same as REPORT if the message is spam, or nothing at
all if the message is non-spam.


The PING command does not actually trigger any spam checking, and (as with
SKIP) no additional input is expected. It returns a simple confirmation
response, like this:

	SPAMD/1.2 0 PONG

This facility may be useful for monitoring programs which wish to check that
the daemon is alive and providing at least a basic response within a reasonable
time frame.
