• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • antispam
antispamconfig.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
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 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
31  your version.
32 */
33 
34 
35 
36 #include "antispamconfig.h"
37 
38 #include <kascii.h>
39 #include <kconfig.h>
40 #include <kconfiggroup.h>
41 #include <kglobal.h>
42 
43 #include <QCoreApplication>
44 
45 namespace MessageViewer {
46 
47 class AntiSpamConfigSingletonProvider
48 {
49 public:
50  AntiSpamConfig instance;
51 };
52 
53 K_GLOBAL_STATIC( AntiSpamConfigSingletonProvider, theAntiSpamConfigSingletonProvider )
54 
55 AntiSpamConfig * AntiSpamConfig::instance()
56 {
57  // better safe than sorry; check whether the global static has already been destroyed
58  if ( theAntiSpamConfigSingletonProvider.isDestroyed() )
59  {
60  return 0;
61  }
62  return &theAntiSpamConfigSingletonProvider->instance;
63 }
64 
65 AntiSpamConfig::AntiSpamConfig()
66 {
67  // A post routine can be used to delete the object when QCoreApplication destructs,
68  // not adding such a post routine will delete the object normally at program unload
69  qAddPostRoutine(theAntiSpamConfigSingletonProvider.destroy);
70  readConfig();
71 }
72 
73 AntiSpamConfig::~AntiSpamConfig()
74 {
75  // When you install a post routine you have to remove the post routine from the destructor of
76  // the class used as global static!
77  qRemovePostRoutine(theAntiSpamConfigSingletonProvider.destroy);
78 }
79 
80 
81 void AntiSpamConfig::readConfig()
82 {
83  mAgents.clear();
84  KConfig config( QLatin1String("kmail.antispamrc") );
85  config.setReadDefaults( true );
86  KConfigGroup general( &config, "General" );
87  unsigned int totalTools = general.readEntry( "tools", 0 );
88  for ( unsigned int i = 1; i <= totalTools; ++i ) {
89  KConfigGroup tool( &config, QString::fromLatin1("Spamtool #%1").arg( i ) );
90  if ( tool.hasKey( "ScoreHeader" ) ) {
91  const QString name = tool.readEntry( "ScoreName" );
92  const QByteArray header = tool.readEntry( "ScoreHeader" ).toLatin1();
93  const QByteArray cheader = tool.readEntry( "ConfidenceHeader" ).toLatin1();
94  const QByteArray type = tool.readEntry( "ScoreType" ).toLatin1();
95  const QString score = tool.readEntryUntranslated( "ScoreValueRegexp" );
96  const QString threshold = tool.readEntryUntranslated( "ScoreThresholdRegexp" );
97  const QString confidence = tool.readEntryUntranslated( "ScoreConfidenceRegexp" );
98  SpamAgentTypes typeE = SpamAgentNone;
99  if ( kasciistricmp( type.data(), "bool" ) == 0 )
100  typeE = SpamAgentBool;
101  else if ( kasciistricmp( type.data(), "decimal" ) == 0 )
102  typeE = SpamAgentFloat;
103  else if ( kasciistricmp( type.data(), "percentage" ) == 0 )
104  typeE = SpamAgentFloatLarge;
105  else if ( kasciistricmp( type.data(), "adjusted" ) == 0 )
106  typeE = SpamAgentAdjustedFloat;
107  mAgents.append( SpamAgent( name, typeE, header, cheader, QRegExp( score ),
108  QRegExp( threshold ), QRegExp( confidence ) ) );
109  }
110  }
111 }
112 
113 const SpamAgents AntiSpamConfig::uniqueAgents() const
114 {
115  QStringList seenAgents;
116  SpamAgents agents;
117  SpamAgents::ConstIterator it( mAgents.begin() );
118  SpamAgents::ConstIterator end( mAgents.end() );
119  for ( ; it != end ; ++it ) {
120  const QString agent( ( *it ).name() );
121  if ( !seenAgents.contains( agent ) ) {
122  agents.append( *it );
123  seenAgents.append( agent );
124  }
125  }
126  return agents;
127 }
128 }
MessageViewer::SpamAgentFloatLarge
For straight percentages between 0.0 and 100.0.
Definition: antispamconfig.h:50
MessageViewer::AntiSpamConfig::~AntiSpamConfig
~AntiSpamConfig()
Definition: antispamconfig.cpp:73
MessageViewer::SpamAgentFloat
For straight percentages between 0.0 and 1.0 (BogoFilter)
Definition: antispamconfig.h:49
MessageViewer::AntiSpamConfig
Singleton to manage loading the kmail.antispamrc file.
Definition: antispamconfig.h:93
MessageViewer::AntiSpamConfig::instance
static AntiSpamConfig * instance()
Definition: antispamconfig.cpp:55
MessageViewer::SpamAgentAdjustedFloat
Use this when we need to compare against a threshold (SpamAssasssin)
Definition: antispamconfig.h:51
MessageViewer::SpamAgentBool
Simple Yes or No (Razor)
Definition: antispamconfig.h:48
MessageViewer::AntiSpamConfig::agents
const SpamAgents agents() const
Returns a list of all agents found on the system.
Definition: antispamconfig.h:107
MessageViewer::SpamAgentTypes
SpamAgentTypes
Valid types of SpamAgent.
Definition: antispamconfig.h:46
MessageViewer::AntiSpamConfig::uniqueAgents
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
Definition: antispamconfig.cpp:113
MessageViewer::SpamAgentNone
Invalid SpamAgent, skip this agent.
Definition: antispamconfig.h:47
MessageViewer::SpamAgents
QVector< SpamAgent > SpamAgents
Definition: antispamconfig.h:80
type
const char * type
Definition: bodypartformatter.cpp:192
MessageViewer::SpamAgent
Definition: antispamconfig.h:54
antispamconfig.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal