1
/* -*- mode: C++; c-file-style: "gnu" -*-
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>
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.
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.
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
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 Qt library by Trolltech AS, Norway (or with modified versions
25
of Qt that use the same license as Qt), 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
Qt. 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
34
#include "antispamconfig.h"
38
#include <kconfiggroup.h>
41
#include <QStringList>
43
using namespace KMail;
47
class AntiSpamConfigSingletonProvider
50
AntiSpamConfig instance;
54
K_GLOBAL_STATIC( AntiSpamConfigSingletonProvider, theAntiSpamConfigSingletonProvider )
56
AntiSpamConfig * AntiSpamConfig::instance()
58
// better safe than sorry; check whether the global static has already been destroyed
59
if ( theAntiSpamConfigSingletonProvider.isDestroyed() )
63
return &theAntiSpamConfigSingletonProvider->instance;
66
AntiSpamConfig::AntiSpamConfig()
71
void AntiSpamConfig::readConfig()
74
KConfig config( "kmail.antispamrc" );
75
config.setReadDefaults( true );
76
KConfigGroup general( &config, "General" );
77
unsigned int totalTools = general.readEntry( "tools", 0 );
78
for ( unsigned int i = 1; i <= totalTools; ++i ) {
79
KConfigGroup tool( &config, QString("Spamtool #%1").arg( i ) );
80
if ( tool.hasKey( "ScoreHeader" ) ) {
81
QString name = tool.readEntry( "ScoreName" );
82
QByteArray header = tool.readEntry( "ScoreHeader" ).toLatin1();
83
QByteArray cheader = tool.readEntry( "ConfidenceHeader" ).toLatin1();
84
QByteArray type = tool.readEntry( "ScoreType" ).toLatin1();
85
QString score = tool.readEntryUntranslated( "ScoreValueRegexp" );
86
QString threshold = tool.readEntryUntranslated( "ScoreThresholdRegexp" );
87
QString confidence = tool.readEntryUntranslated( "ScoreConfidenceRegexp" );
88
SpamAgentTypes typeE = SpamAgentNone;
89
if ( kasciistricmp( type.data(), "bool" ) == 0 )
90
typeE = SpamAgentBool;
91
else if ( kasciistricmp( type.data(), "decimal" ) == 0 )
92
typeE = SpamAgentFloat;
93
else if ( kasciistricmp( type.data(), "percentage" ) == 0 )
94
typeE = SpamAgentFloatLarge;
95
else if ( kasciistricmp( type.data(), "adjusted" ) == 0 )
96
typeE = SpamAgentAdjustedFloat;
97
mAgents.append( SpamAgent( name, typeE, header, cheader, QRegExp( score ),
98
QRegExp( threshold ), QRegExp( confidence ) ) );
103
const SpamAgents AntiSpamConfig::uniqueAgents() const
105
QStringList seenAgents;
107
SpamAgents::ConstIterator it( mAgents.begin() );
108
SpamAgents::ConstIterator end( mAgents.end() );
109
for ( ; it != end ; ++it ) {
110
const QString agent( ( *it ).name() );
111
if ( !seenAgents.contains( agent ) ) {
112
agents.append( *it );
113
seenAgents.append( agent );