[erlang-questions] Communicating with SpamAssassin from Erlang

Alain O'Dea alain.odea@REDACTED
Tue Mar 8 03:11:35 CET 2011


On 2011-03-07, at 7:57, Atilla Erdődi <atilla.erdodi@REDACTED> wrote:

> Hi everyone,
> 
> I'm trying to use SpamAssassin to check the spam score of a mail from
> Erlang using a port.  I've experimented with several options for
> open_port, different message formats, but haven't managed to get any
> reply from spamc, so it times out. Apparently it doesn't notice the
> end of the transmission. Hopefully the solution is something trivial,
> I've missed so far.
> 
> (The obvious solution would be to reimplement the tcp protocol of
> SpamAssassin in Erlang, but I would like simpler solution for now, at
> least for the prototype.)
> 
> The simplified code is below:
> 
> SpamDServer = "127.0.0.1",
> Exec = os:find_executable("spamc"),
> Port = open_port({spawn, Exec ++ " -c -d " ++ SpamDServer}, [use_stdio]),
> port_command(Port, "dummy text \r\n"),
> port_command(Port, <<4>>), %EOT
> receive
>    {Port, {data, Res}} ->
>        io:format("Spamscore: ~p~n", [Res]);
>    Other ->
>        io:format("Unknown message: ~p\n", [Other])
> after 10000 ->
>        io:format("timeout\n")
> end,
> erlang:port_close(Port).
> 
> 
> Regards,
> Atilla

Hi Atilla:

This is probably a non-answer, but Akismet provides a REST API for spam checks and is far more accurate than SpamAssassin.  Akismet is non-free, but inexpensive.

Cheers,
Alain


More information about the erlang-questions mailing list