Click here to Skip to main content
Click here to Skip to main content
Go to top

A C# Wrapper for the SpamAssassin Protocol

, 18 Feb 2006
Rate this:
Please Sign up or sign in to vote.
Introducing a class that simplifies the communication with a SpamAssassin server
<!------------------------------- STEP 2 ---------------------------><!-- Include download and sample image information. -->

SpamAssassin logo

<!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (

,

etc) -->

Introduction

(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:

  • CHECK
  • SYMBOLS
  • REPORT
  • REPORT_IFSPAM
  • SKIP
  • PING
  • PROCESS
  • TELL

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

The class 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.

Installation

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.

Conclusion

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)

History

  • 2006-02-18:
    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!
     
  • 2006-02-18:
    Please also see my article "Using the ZetaSpamAssassin Wrapper in a real-word application"

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Offline-Homepage-Baukasten

Comments and Discussions

 
Question[Message Deleted] PinmemberMember 472935824-Jun-09 23:28 
AnswerRe: CODE IMPROVMENT IDEA. TCPCLIENT PinsitebuilderUwe Keim24-Jun-09 23:36 
AnswerRe: CODE IMPROVMENT IDEA. TCPCLIENT [modified] PinmemberMember 472935824-Jun-09 23:56 
Generalyou are the man. PinmemberMember 47293588-May-09 4:52 
GeneralAn existing connection was forcibily closed by the remote host PinmemberMember 234143013-Oct-08 5:01 
QuestionWebservice down PinmemberRafaMiranda20-Jul-06 10:00 
AnswerRe: Webservice down PinsitebuilderUwe Keim20-Jul-06 18:11 
GeneralRe: Webservice down [modified] PinmemberRafaMiranda21-Jul-06 4:23 
GeneralRe: Webservice down PinsitebuilderUwe Keim21-Jul-06 4:37 
QuestionRe: Webservice down PinmemberRafaMiranda25-Jul-06 10:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 18 Feb 2006
Article Copyright 2006 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid