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].ca>
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, QRegularExpression(score), QRegularExpression(threshold), QRegularExpression(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()
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
void append(const T &value)
const SpamAgents agents() const
Returns a list of all agents found on the system.
Singleton to manage loading the kmail.antispamrc file.
void clear()
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
QVector::iterator end()
typedef ConstIterator
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:01:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.