~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/antispamconfig.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#include "antispamconfig.h"
35
 
 
36
 
#include <kascii.h>
37
 
#include <kconfig.h>
38
 
#include <kconfiggroup.h>
39
 
#include <kglobal.h>
40
 
 
41
 
#include <QStringList>
42
 
 
43
 
using namespace KMail;
44
 
 
45
 
 
46
 
namespace KMail {
47
 
  class AntiSpamConfigSingletonProvider
48
 
  {
49
 
    public:
50
 
      AntiSpamConfig instance;
51
 
  };
52
 
}
53
 
 
54
 
K_GLOBAL_STATIC( AntiSpamConfigSingletonProvider, theAntiSpamConfigSingletonProvider )
55
 
 
56
 
AntiSpamConfig * AntiSpamConfig::instance()
57
 
{
58
 
  // better safe than sorry; check whether the global static has already been destroyed
59
 
  if ( theAntiSpamConfigSingletonProvider.isDestroyed() )
60
 
  {
61
 
    return 0;
62
 
  }
63
 
  return &theAntiSpamConfigSingletonProvider->instance;
64
 
}
65
 
 
66
 
AntiSpamConfig::AntiSpamConfig()
67
 
{
68
 
  readConfig();
69
 
}
70
 
 
71
 
void AntiSpamConfig::readConfig()
72
 
{
73
 
  mAgents.clear();
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 ) ) );
99
 
    }
100
 
  }
101
 
}
102
 
 
103
 
const SpamAgents AntiSpamConfig::uniqueAgents() const
104
 
{
105
 
    QStringList seenAgents;
106
 
    SpamAgents agents;
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 );
114
 
        }
115
 
    }
116
 
    return agents;
117
 
}