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 :-)
- 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 member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.