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 <paudley@blackcat.ca>
6 SPDX-FileCopyrightText: 2004 Ingo Kloecker <kloecker@kde.org>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "antispamconfig.h"
12
13#include <KConfig>
14#include <KConfigGroup>
15
16using namespace MessageViewer;
17
18AntiSpamConfig *AntiSpamConfig::instance()
19{
20 static AntiSpamConfig s_self;
21 return &s_self;
22}
23
25{
26 return mAgents;
27}
28
29AntiSpamConfig::AntiSpamConfig()
30{
31 readConfig();
32}
33
34AntiSpamConfig::~AntiSpamConfig() = default;
35
36void AntiSpamConfig::readConfig()
37{
38 mAgents.clear();
39 KConfig config(QStringLiteral("kmail.antispamrc"));
40 KConfigGroup general(&config, QStringLiteral("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}
Singleton to manage loading the kmail.antispamrc file.
const SpamAgents agents() const
Returns a list of all agents found on the system.
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
void append(QList< T > &&value)
iterator begin()
void clear()
iterator end()
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.