Messagelib

antispamconfig.cpp
1 /*
2  antispamconfig.cpp
3 
4  This file is part of KMail, the KDE mail client.
5  SPDX-FileCopyrightText: 2004 Patrick Audley <[email protected]>
6  SPDX-FileCopyrightText: 2004 Ingo Kloecker <[email protected]>
7 
8  SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 
11 #include "antispamconfig.h"
12 
13 #include <KConfig>
14 #include <KConfigGroup>
15 
16 using namespace MessageViewer;
17 
18 AntiSpamConfig *AntiSpamConfig::instance()
19 {
20  static AntiSpamConfig s_self;
21  return &s_self;
22 }
23 
25 {
26  return mAgents;
27 }
28 
29 AntiSpamConfig::AntiSpamConfig()
30 {
31  readConfig();
32 }
33 
34 AntiSpamConfig::~AntiSpamConfig() = default;
35 
36 void AntiSpamConfig::readConfig()
37 {
38  mAgents.clear();
39  KConfig config(QStringLiteral("kmail.antispamrc"));
40  KConfigGroup general(&config, "General");
41  int totalTools = general.readEntry("tools", 0);
42  for (int i = 1; i <= totalTools; ++i) {
43  KConfigGroup tool(&config, QStringLiteral("Spamtool #%1").arg(i));
44  if (tool.hasKey("ScoreHeader")) {
45  const QString name = tool.readEntry("ScoreName");
46  const QByteArray header = tool.readEntry("ScoreHeader").toLatin1();
47  const QByteArray cheader = tool.readEntry("ConfidenceHeader").toLatin1();
48  const QByteArray type = tool.readEntry("ScoreType").toLatin1();
49  const QString score = tool.readEntryUntranslated("ScoreValueRegexp");
50  const QString threshold = tool.readEntryUntranslated("ScoreThresholdRegexp");
51  const QString confidence = tool.readEntryUntranslated("ScoreConfidenceRegexp");
52  SpamAgentTypes typeE = SpamAgentNone;
53  if (qstricmp(type.data(), "bool") == 0) {
54  typeE = SpamAgentBool;
55  } else if (qstricmp(type.data(), "decimal") == 0) {
56  typeE = SpamAgentFloat;
57  } else if (qstricmp(type.data(), "percentage") == 0) {
58  typeE = SpamAgentFloatLarge;
59  } else if (qstricmp(type.data(), "adjusted") == 0) {
60  typeE = SpamAgentAdjustedFloat;
61  }
62  mAgents.append(SpamAgent(name, typeE, header, cheader, QRegExp(score), QRegExp(threshold), QRegExp(confidence)));
63  }
64  }
65 }
66 
68 {
69  QStringList seenAgents;
71  SpamAgents::ConstIterator it(mAgents.begin());
72  SpamAgents::ConstIterator end(mAgents.end());
73  for (; it != end; ++it) {
74  const QString agent((*it).name());
75  if (!seenAgents.contains(agent)) {
76  agents.append(*it);
77  seenAgents.append(agent);
78  }
79  }
80  return agents;
81 }
void append(const T &value)
QVector::iterator begin()
Singleton to manage loading the kmail.antispamrc file.
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
typedef ConstIterator
const QLatin1String name
void clear()
void append(const T &value)
PartitionTable::TableType type
QString readEntryUntranslated(const QString &pKey, const QString &aDefault=QString()) const
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
bool hasKey(const QString &key) const
char * data()
const SpamAgents agents() const
Returns a list of all agents found on the system.
QVector::iterator end()
T readEntry(const QString &key, const T &aDefault) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.