34 #include "spamheaderanalyzer.h"
36 #include "antispamconfig.h"
37 #include "kmmessage.h"
41 using namespace KMail;
45 kdDebug(5006) << k_funcinfo << endl;
47 SpamAgents agents = AntiSpamConfig::instance()->uniqueAgents();
49 for ( SpamAgentsIterator it = agents.begin(); it != agents.end(); ++it ) {
57 TQString mField = message->
headerField( (*it).header() );
58 if ( mField.isEmpty() )
62 bool scoreValid =
false;
66 TQRegExp scorePattern = (*it).scorePattern();
67 if ( scorePattern.search( mField ) != -1 ) {
68 scoreString = scorePattern.cap( 1 );
76 kdDebug(5006) <<
"Score could not be extracted from header '"
77 << mField <<
"'" << endl;
79 bool floatValid =
false;
80 switch ( (*it).scoreType() ) {
86 if( (*it).scorePattern().search( mField ) == -1 )
93 score = scoreString.toFloat( &floatValid );
96 kdDebug(5006) <<
"Score (" << scoreString <<
") is no number"
104 score = scoreString.toFloat( &floatValid );
107 kdDebug(5006) <<
"Score (" << scoreString <<
") is no number"
113 score = scoreString.toFloat( &floatValid );
116 kdDebug(5006) <<
"Score (" << scoreString <<
") is no number"
122 TQString thresholdString;
123 TQRegExp thresholdPattern = (*it).thresholdPattern();
124 if ( thresholdPattern.search( mField ) != -1 ) {
125 thresholdString = thresholdPattern.cap( 1 );
129 kdDebug(5006) <<
"Threshold could not be extracted from header '"
130 << mField <<
"'" << endl;
133 float threshold = thresholdString.toFloat( &floatValid );
134 if ( !floatValid || ( threshold <= 0.0 ) ) {
136 kdDebug(5006) <<
"Threshold (" << thresholdString <<
") is no "
137 <<
"number or is negative" << endl;
146 else if ( score > threshold )
149 score = score / threshold * 100.0;
153 scores.append(
SpamScore( (*it).name(), score, mField ) );
TQString headerField(const TQCString &name) const
Returns the value of a header field with the given name.
A simple tupel of agent, score and header.
@ SpamAgentFloatLarge
For straight percentages between 0.0 and 100.0.
@ SpamAgentBool
Simple Yes or No (Razor)
@ SpamAgentFloat
For straight percentages between 0.0 and 1.0 (BogoFilter)
@ SpamAgentNone
Invalid SpamAgent, skip this agent.
@ SpamAgentAdjustedFloat
Use this when we need to compare against a threshold (SpamAssasssin)