Click here to Skip to main content
Click here to Skip to main content

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.

Introduction

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 br_rules.cf 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:

Classes:

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 br_rules.cf file, that will be used to build the SpamRule object later.
Properties:
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.
Properties:
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.

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

SpamFileReader
Properties:
FileName - Name of the file to read.

Methods
ReadFromFile - reads and parses the .cf file. As written before, it needs to be improved since it's only parsing the br_rules.cf 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 Smile | :)

  • 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.

License

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

Share

About the Author

RafaMiranda
Software Developer (Senior)
Brazil Brazil
No Biography provided

Comments and Discussions

 
QuestionDoes this work with the existing SpamAssassin rules? Pinmembermatply20-Aug-09 21:30 
AnswerRe: Does this work with the existing SpamAssassin rules? PinmemberRafaMiranda30-Mar-10 8:57 
GeneralRe: Does this work with the existing SpamAssassin rules? Pinmembersaadallali16-Aug-12 1:39 
GeneralEnglish PinmemberSixcode10-Aug-06 7:45 
GeneralRe: English PinmemberRafaMiranda10-Aug-06 8:14 
GeneralRe: English PinmemberSixcode17-Aug-06 12:30 
QuestionLinks? Pinmemberfwsouthern2-Aug-06 18:21 
Please fix your source & demo links! And, while you're at it, please write an "article" .....
AnswerRe: Links? PinmemberRafaMiranda3-Aug-06 8:40 

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
Web02 | 2.8.140827.1 | Last Updated 2 Aug 2006
Article Copyright 2006 by RafaMiranda
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid