File indexing completed on 2025-03-09 04:54:26
0001 /* 0002 antispamconfig.cpp 0003 0004 This file is part of KMail, the KDE mail client. 0005 SPDX-FileCopyrightText: 2004 Patrick Audley <paudley@blackcat.ca> 0006 SPDX-FileCopyrightText: 2004 Ingo Kloecker <kloecker@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "antispamconfig.h" 0012 0013 #include <KConfig> 0014 #include <KConfigGroup> 0015 0016 using namespace MessageViewer; 0017 0018 AntiSpamConfig *AntiSpamConfig::instance() 0019 { 0020 static AntiSpamConfig s_self; 0021 return &s_self; 0022 } 0023 0024 const SpamAgents AntiSpamConfig::agents() const 0025 { 0026 return mAgents; 0027 } 0028 0029 AntiSpamConfig::AntiSpamConfig() 0030 { 0031 readConfig(); 0032 } 0033 0034 AntiSpamConfig::~AntiSpamConfig() = default; 0035 0036 void AntiSpamConfig::readConfig() 0037 { 0038 mAgents.clear(); 0039 KConfig config(QStringLiteral("kmail.antispamrc")); 0040 KConfigGroup general(&config, QStringLiteral("General")); 0041 int totalTools = general.readEntry("tools", 0); 0042 for (int i = 1; i <= totalTools; ++i) { 0043 KConfigGroup tool(&config, QStringLiteral("Spamtool #%1").arg(i)); 0044 if (tool.hasKey("ScoreHeader")) { 0045 const QString name = tool.readEntry("ScoreName"); 0046 const QByteArray header = tool.readEntry("ScoreHeader").toLatin1(); 0047 const QByteArray cheader = tool.readEntry("ConfidenceHeader").toLatin1(); 0048 const QByteArray type = tool.readEntry("ScoreType").toLatin1(); 0049 const QString score = tool.readEntryUntranslated("ScoreValueRegexp"); 0050 const QString threshold = tool.readEntryUntranslated("ScoreThresholdRegexp"); 0051 const QString confidence = tool.readEntryUntranslated("ScoreConfidenceRegexp"); 0052 SpamAgentTypes typeE = SpamAgentNone; 0053 if (qstricmp(type.data(), "bool") == 0) { 0054 typeE = SpamAgentBool; 0055 } else if (qstricmp(type.data(), "decimal") == 0) { 0056 typeE = SpamAgentFloat; 0057 } else if (qstricmp(type.data(), "percentage") == 0) { 0058 typeE = SpamAgentFloatLarge; 0059 } else if (qstricmp(type.data(), "adjusted") == 0) { 0060 typeE = SpamAgentAdjustedFloat; 0061 } 0062 mAgents.append(SpamAgent(name, typeE, header, cheader, QRegularExpression(score), QRegularExpression(threshold), QRegularExpression(confidence))); 0063 } 0064 } 0065 } 0066 0067 const SpamAgents AntiSpamConfig::uniqueAgents() const 0068 { 0069 QStringList seenAgents; 0070 SpamAgents agents; 0071 SpamAgents::ConstIterator it(mAgents.begin()); 0072 SpamAgents::ConstIterator end(mAgents.end()); 0073 for (; it != end; ++it) { 0074 const QString agent((*it).name()); 0075 if (!seenAgents.contains(agent)) { 0076 agents.append(*it); 0077 seenAgents.append(agent); 0078 } 0079 } 0080 return agents; 0081 }