kmail

antispamconfig.cpp
1 /*
2  antispamconfig.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  Copyright (c) 2004 Patrick Audley <paudley@blackcat.ca>
6  Copyright (c) 2004 Ingo Kloecker <kloecker@kde.org>
7 
8  KMail is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  KMail is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22  In addition, as a special exception, the copyright holders give
23  permission to link the code of this program with any edition of
24  the TQt library by Trolltech AS, Norway (or with modified versions
25  of TQt that use the same license as TQt), and distribute linked
26  combinations including the two. You must obey the GNU General
27  Public License in all respects for all of the code used other than
28  TQt. If you modify this file, you may extend this exception to
29  your version of the file, but you are not obligated to do so. If
30  you do not wish to do so, delete this exception statement from
31  your version.
32 */
33 
34 #include "antispamconfig.h"
35 
36 #include <kstaticdeleter.h>
37 #include <tdeconfig.h>
38 
39 using namespace KMail;
40 
41 AntiSpamConfig * AntiSpamConfig::sSelf = 0;
42 static KStaticDeleter<AntiSpamConfig> antispamconfig_sd;
43 
44 AntiSpamConfig * AntiSpamConfig::instance() {
45  if ( !sSelf ) {
46  antispamconfig_sd.setObject( sSelf, new AntiSpamConfig() );
47  sSelf->readConfig();
48  }
49  return sSelf;
50 }
51 
52 void AntiSpamConfig::readConfig()
53 {
54  mAgents.clear();
55  TDEConfig config( "kmail.antispamrc", true );
56  config.setReadDefaults( true );
57  TDEConfigGroup general( &config, "General" );
58  unsigned int totalTools = general.readUnsignedNumEntry( "tools", 0 );
59  for ( unsigned int i = 1; i <= totalTools; ++i ) {
60  TDEConfigGroup tool( &config, TQString("Spamtool #%1").arg( i ) );
61  if ( tool.hasKey( "ScoreHeader" ) ) {
62  TQString name = tool.readEntry( "ScoreName" );
63  TQCString header = tool.readEntry( "ScoreHeader" ).latin1();
64  TQCString type = tool.readEntry( "ScoreType" ).latin1();
65  TQString score = tool.readEntryUntranslated( "ScoreValueRegexp" );
66  TQString threshold = tool.readEntryUntranslated( "ScoreThresholdRegexp" );
68  if ( kasciistricmp( type.data(), "bool" ) == 0 )
69  typeE = SpamAgentBool;
70  else if ( kasciistricmp( type.data(), "decimal" ) == 0 )
71  typeE = SpamAgentFloat;
72  else if ( kasciistricmp( type.data(), "percentage" ) == 0 )
73  typeE = SpamAgentFloatLarge;
74  else if ( kasciistricmp( type.data(), "adjusted" ) == 0 )
75  typeE = SpamAgentAdjustedFloat;
76  mAgents.append( SpamAgent( name, typeE, header, TQRegExp( score ),
77  TQRegExp( threshold ) ) );
78  }
79  }
80 }
81 
82 const SpamAgents AntiSpamConfig::uniqueAgents() const
83 {
84  TQStringList seenAgents;
85  SpamAgents agents;
86  SpamAgents::ConstIterator it( mAgents.begin() );
87  SpamAgents::ConstIterator end( mAgents.end() );
88  for ( ; it != end ; ++it ) {
89  const TQString agent( ( *it ).name() );
90  if ( seenAgents.find( agent ) == seenAgents.end() ) {
91  agents.append( *it );
92  seenAgents.append( agent );
93  }
94  }
95  return agents;
96 }
Singleton to manage loading the kmail.antispamrc file.
const SpamAgents agents() const
Returns a list of all agents found on the system.
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
folderdiaquotatab.h
Definition: aboutdata.cpp:40
SpamAgentTypes
Valid types of SpamAgent.
@ 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)