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
OK... This project contains two VS projects:
1) UnearSpamParser library.
2) Windows application to test the library.
About the UnearSpamParser
- Base class
for the SpamRuleList and
- List of Spam Rule
Meta Line Objects.
- List of Spam Rule Objects.
- 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,
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
- Represents the SpamAssassin Rule
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
Result - Returns the 0 or the score after the execution of the
Locale - Locale that the rules applies to (Not beeing used so
Source - Origin of the rule (SpamAssassin, etc...). Also, it's not
being used so far.
IsMeta< - Returns whether the rule is a
IsSubRule - Returns whether the rule is a subrule of a
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.
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 br_rules.cf
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
- 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
To test a specific rule, you need to go to the second tab ("Simular
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