Click here to Skip to main content
13,257,667 members (74,026 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 2 Aug 2006

SpamAssassin Rule Analyzer

, 2 Aug 2006
Rate this:
Please Sign up or sign in to vote.
Imports SpamAssassin rule files to xml format and simulates the rules.


I work for a company that among other things, have a solicited email sender product. We send emails for the biggest e-commerce, internet portals and banks companies in Brazil. We started to have a lot of problems with our clients emails campaigns, because of their limited or non sense technique on making those campaigns as they were beeing marked as spams.

So, this project started up as a tool for this product on behalf to help and/or educate our clients to create better campaigns.

The original idea was to integrate SpamAssassin service (spamd) with our product to make this analysis, but after all the implementation dificulties to integrate it to our system and the fact that we were only going to use few of those rules, We decided to create our own analyzer using SpamAssassin rules.

Using the code

First of all, I would like to make an observation conserning the parser. The parser is based on the file which is in the package and I know it sucks so far. By next week I will make a more generic one, or if anyone could help improving it, I'll appreciated. The important thing is that the application and library are based on the xml format (and file), not actually the parser.

OK... This project contains two VS projects:

1) UnearSpamParser library.

2) Windows application to test the library.

About the UnearSpamParser library:


BaseCollection.cs - Base class for the SpamRuleList and SpamMetaLineList.

SpamRuleMetaLineList - List of Spam Rule Meta Line Objects.

SpamRuleList - List of Spam Rule Objects.

SpamMetaLine - class used when parsing the file. Each object represents a line in the file, that will be used to build the SpamRule object later.
Type - Area that the rule is applied or property definition of the rule (i.e. rawbody, uri, score, describe, etc...)
RuleName - Name of the rule.
MetaText - Is the value of the property of the rule. (i.e. at the "describe" definition, the meta text would be the description string. At the rawbody definition would be the regular expression.)

SpamRule - Represents the SpamAssassin Rule object.
Type - Area that the rule is applied or property definition of the rule (i.e. rawbody, uri, score, describe, etc...)
Name - Name of the rule.
Description - description of the rule.
RegExExpression - Regular expression of the rule.
Score - the score of the rule.
Result - Returns the 0 or the score after the execution of the rule.
Locale - Locale that the rules applies to (Not beeing used so far).
Source - Origin of the rule (SpamAssassin, etc...). Also, it's not being used so far.
IsMeta< - Returns whether  the rule is a Meta rule.
IsSubRule - Returns whether  the rule is a subrule of a meta rule.
IsRegExValid - Returns whether the Regular Expression is valid.
Scored - Returns whether the rule scored.

ExecuteRule - overloaded method that executes the rule and sets the Result property if the rule scored.

FileName - Name of the file to read.

ReadFromFile - reads and parses the .cf file. As written before, it needs to be improved since it's only parsing the file.

ReadFromXml - reads the xml file

SaveSpamRuleToXML - Saves Spam Rules to a XML file.

SaveSpamRuleMetaLineXML - Saves Spam Meta Line list to a XML file.

GetLine - Gets the rule line from the .cf file.

GetType - Gets the rule type from the .cf file.

GetRuleName - Gets the rule name.

GetRuleMetaText - Gets the rule meta text from the .cf file.

About the windows application:

First of all, I'm sorry to tell you all, but the interface comunication is in Portuguese language but I'll write down the translation. Portuguese is not that hard though :-)

  • Geral (tab) - General
  • Simular Regras - Simulate Rules
  • Importação das Regras - Rule Import
  • Importar... - Import...
  • Salvar XML - Save XML
  • Testar Mensagens - Test Messages
  • Executar Regras - Execute Rules
  • Resultados - Results
  • Regra - Rule
  • Nome - Name
  • Descrição - Description
  • Simular - Simulate

The first step is to import a file (there's a sample of the XML and the .cf files within the zip)files)

After the file has been imported, just paste the email message and execute it. It will appear a list of the rules scored for message if it applies to any.

To test a specific rule, you need to go to the second tab ("Simular Regras").

After the file has been imported, the list of rules should be displayed at the list box on the right.

When you select a rule, it will display all the properties as seen bellow

Just put some test to simulate the rule and try to adjust it with the RegEx textbox.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
Brazil Brazil
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionDoes this work with the existing SpamAssassin rules? Pin
matply20-Aug-09 22:30
membermatply20-Aug-09 22:30 
AnswerRe: Does this work with the existing SpamAssassin rules? Pin
RafaMiranda30-Mar-10 9:57
memberRafaMiranda30-Mar-10 9:57 
GeneralRe: Does this work with the existing SpamAssassin rules? Pin
saadallali16-Aug-12 2:39
membersaadallali16-Aug-12 2:39 
GeneralEnglish Pin
Sixcode10-Aug-06 8:45
memberSixcode10-Aug-06 8:45 
GeneralRe: English Pin
RafaMiranda10-Aug-06 9:14
memberRafaMiranda10-Aug-06 9:14 
GeneralRe: English Pin
Sixcode17-Aug-06 13:30
memberSixcode17-Aug-06 13:30 
QuestionLinks? Pin
fwsouthern2-Aug-06 19:21
memberfwsouthern2-Aug-06 19:21 
AnswerRe: Links? Pin
RafaMiranda3-Aug-06 9:40
memberRafaMiranda3-Aug-06 9:40 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 2 Aug 2006
Article Copyright 2006 by RafaMiranda
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid