(This article is followed by my article "Using the ZetaSpamAssassin Wrapper in a real-word application")
SpamAssassin is an open source server application that checks (e-mail) messages for being spam or no spam. In this article I describe a class that enables you to easily communicate with a SpamAssassin server to check whether a given text (
string) is likely to contain spam text.
Why I created the Wrapper
To our customers, we provide some ASP ("application service provider") applications like guestbooks and discussion boards, all hosted centralized on our servers. In the last month, customers increasingly complained about the lot of spam in their guestbooks and discussion boards.
The first solution that came to my mind was to implement a Captcha, which is well documented on CodeProject, too. Just search for it!
I even started implementing Captcha when a colleague of mine interrupted me and pointed to a better solution: Let the messages that are posted to those guestbooks and discussion boards be checked by a background application. He pointed me to the WordPress SpamAssassin Plugin, a PHP script for the popular Weblog application WordPress.
I used this WordPress plugin as a starting point for my own implementation. Basically it connects to a SpamAssassin server in the background, doing some socket communication to send a text to check and receive a response from the SpamAssassin server whether he thinks that the text is likely to be spam or not.
After doing some tests, I discovered the complete protocol specification (or some sort of) for SpamAssassin and wrote a class to encapsulate the protocol.
The SpamAssassin Protocol
SpamAssassin has several so called "Commands" to send from a client (called "SPAMC") to a SpamAssassin server (called "SPAMD" for "Demon"). Those commands are:
Please refer to the protocol specification for details about the single commands. Each command being sent from a SPAMC contains a different payload depending on the command. The result that is returned by SPAMD depends on the used command, too.
The SpamAssassin Protocol Wrapper
SpamAssassinProtocol wraps the SpamAssassin commands in an easy-to-use manner. For each command there are three elements:
- A function to execute a command. E.g.
SpamAssassinProtocol.ExecuteCheck() for executing the CHECK command.
- A class that contains the parameters passed to the command function. E.g.
SpamAssassinCheckArgs for passing the parameters for the CHECK command.
- A class that contains the result returned from the command function. E.g.
SpamAssassinCheckArgs for the result from the CHECK command.
The class currently contains the basic wrappers. Probably I do need to provide more abstract functions and classes to make the single commands being more usable in a real-word scenario.
A test application is included in the download at the top of this article.
In order to use this class in you own website you need the following requirements:
- Microsoft .NET Framework 2.0
- A running SpamAssassin server (Linux)
Please see my article "Using the ZetaSpamAssassin Wrapper in a real-word application" where I introduce a web service to you that could remove the needs for running a webservice by yourself.
In this article I shortly introduced you an easy-to-use class that encapsulates the SpamAssassin protocol for communicating from a SPAMC to a SPAMD.
Please note that I am rather "SpamAssassin-illiterate", knowing only the minimum about SpamAssassin that I needed to know in order to create the class. All the installation and configuration was did by my colleague Rainer. So it is likely that I missed some of the concepts that the SPAMD authors put into their commands.
I am therefore curious on feedback from you about the class and practial applications you created with it and how to improve it. Keep your comments coming! (simply use the comments section below)
First version of the article. The
SpamAssassinProtocol class contains the basic wrappers and was initially tested for working functionality. More testing and adjustment will be required when more feedback from you comes in!
Please also see my article "Using the ZetaSpamAssassin Wrapper in a real-word application"