Click here to Skip to main content
15,879,239 members
Articles / Programming Languages / C#
Article

A C# Wrapper for the SpamAssassin Protocol

Rate me:
Please Sign up or sign in to vote.
4.69/5 (15 votes)
18 Feb 2006CPOL3 min read 79.6K   1.1K   22   18
Introducing a class that simplifies the communication with a SpamAssassin server

SpamAssassin logo

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)


Written By
Chief Technology Officer Zeta Software GmbH
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.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions

 
Question[Message Deleted] Pin
Z Kavtaskin24-Jun-09 23:28
Z Kavtaskin24-Jun-09 23:28 
AnswerRe: CODE IMPROVMENT IDEA. TCPCLIENT Pin
Uwe Keim24-Jun-09 23:36
sitebuilderUwe Keim24-Jun-09 23:36 
GeneralMessage Removed Pin
8-May-09 4:52
Z Kavtaskin8-May-09 4:52 
GeneralAn existing connection was forcibily closed by the remote host Pin
Member 234143013-Oct-08 5:01
Member 234143013-Oct-08 5:01 
QuestionWebservice down Pin
RafaMiranda20-Jul-06 10:00
RafaMiranda20-Jul-06 10:00 
AnswerRe: Webservice down Pin
Uwe Keim20-Jul-06 18:11
sitebuilderUwe Keim20-Jul-06 18:11 
GeneralRe: Webservice down [modified] Pin
RafaMiranda21-Jul-06 4:23
RafaMiranda21-Jul-06 4:23 
GeneralRe: Webservice down Pin
Uwe Keim21-Jul-06 4:37
sitebuilderUwe Keim21-Jul-06 4:37 
QuestionRe: Webservice down Pin
RafaMiranda25-Jul-06 10:45
RafaMiranda25-Jul-06 10:45 
AnswerRe: Webservice down Pin
Uwe Keim25-Jul-06 17:41
sitebuilderUwe Keim25-Jul-06 17:41 
QuestionNo Spam? Pin
VicSmurf18-Apr-06 10:44
VicSmurf18-Apr-06 10:44 
AnswerRe: No Spam? Pin
Uwe Keim19-Apr-06 7:13
sitebuilderUwe Keim19-Apr-06 7:13 
QuestionFormat Exception error Pin
206mph23-Mar-06 7:00
206mph23-Mar-06 7:00 
AnswerRe: Format Exception error Pin
Uwe Keim23-Mar-06 11:32
sitebuilderUwe Keim23-Mar-06 11:32 
QuestionWhy is it better? Pin
Super Lloyd18-Feb-06 17:06
Super Lloyd18-Feb-06 17:06 
AnswerRe: Why is it better? Pin
Uwe Keim18-Feb-06 17:27
sitebuilderUwe Keim18-Feb-06 17:27 
GeneralRe: Why is it better? Pin
Super Lloyd18-Feb-06 17:36
Super Lloyd18-Feb-06 17:36 
GeneralRe: Why is it better? Pin
Super Lloyd18-Feb-06 17:37
Super Lloyd18-Feb-06 17:37 
GeneralRe: Why is it better? Pin
Uwe Keim18-Feb-06 17:56
sitebuilderUwe Keim18-Feb-06 17:56 

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

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