Messagelib

antispamconfig.h
1/*
2 antispamconfig.h
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#pragma once
12
13#include <QList>
14#include <QRegularExpression>
15
16class QString;
17
18namespace MessageViewer
19{
20/// Valid types of SpamAgent
21enum SpamAgentTypes {
22 SpamAgentNone, //!< Invalid SpamAgent, skip this agent
23 SpamAgentBool, //!< Simple Yes or No (Razor)
24 SpamAgentFloat, //!< For straight percentages between 0.0 and 1.0 (BogoFilter)
25 SpamAgentFloatLarge, //!< For straight percentages between 0.0 and 100.0
26 SpamAgentAdjustedFloat, //!< Use this when we need to compare against a threshold (SpamAssasssin)
27};
28
29class SpamAgent
30{
31public:
32 SpamAgent()
33 : mType(SpamAgentNone)
34 {
35 }
36
37 SpamAgent(const QString &name,
38 SpamAgentTypes type,
39 const QByteArray &field,
40 const QByteArray &cfield,
41 const QRegularExpression &score,
42 const QRegularExpression &threshold,
43 const QRegularExpression &confidence)
44 : mName(name)
45 , mType(type)
46 , mField(field)
47 , mConfidenceField(cfield)
48 , mScore(score)
49 , mThreshold(threshold)
50 , mConfidence(confidence)
51 {
52 }
53
54 [[nodiscard]] QString name() const
55 {
56 return mName;
57 }
58
59 [[nodiscard]] SpamAgentTypes scoreType() const
60 {
61 return mType;
62 }
63
64 [[nodiscard]] QByteArray header() const
65 {
66 return mField;
67 }
68
69 [[nodiscard]] QByteArray confidenceHeader() const
70 {
71 return mConfidenceField;
72 }
73
74 [[nodiscard]] QRegularExpression scorePattern() const
75 {
76 return mScore;
77 }
78
79 [[nodiscard]] QRegularExpression thresholdPattern() const
80 {
81 return mThreshold;
82 }
83
84 [[nodiscard]] QRegularExpression confidencePattern() const
85 {
86 return mConfidence;
87 }
88
89private:
90 QString mName;
91 SpamAgentTypes mType;
92 QByteArray mField;
93 QByteArray mConfidenceField;
94 QRegularExpression mScore;
95 QRegularExpression mThreshold;
96 QRegularExpression mConfidence;
97};
98using SpamAgents = QList<SpamAgent>;
99
100class AntiSpamConfigSingletonProvider;
101
102/**
103 @short Singleton to manage loading the kmail.antispamrc file.
104 @author Patrick Audley <paudley@blackcat.ca>
105
106 Use of this config-manager class is straight forward. Since it
107 is a singleton object, all you have to do is obtain an instance
108 by calling @p SpamConfig::instance() and use any of the
109 public member functions.
110 */
112{
113 friend class AntiSpamConfigSingletonProvider;
114
115private:
117
118public:
120
121 static AntiSpamConfig *instance();
122
123 /**
124 * Returns a list of all agents found on the system. This
125 * might list SA twice, if both the C and the Perl version are present.
126 */
127 const SpamAgents agents() const;
128
129 /**
130 * Returns a list of unique agents, found on the system. SpamAssassin will
131 * only be listed once, even if both the C and the Perl version are
132 * installed.
133 */
134 const SpamAgents uniqueAgents() const;
135
136private:
137 SpamAgents mAgents;
138
139 void readConfig();
140};
141}
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.
QString name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.