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 <[email protected]>
6  SPDX-FileCopyrightText: 2004 Ingo Kloecker <[email protected]>
7 
8  SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 
11 #pragma once
12 
13 #include <QRegularExpression>
14 #include <QVector>
15 
16 class QString;
17 
18 namespace MessageViewer
19 {
20 /// Valid types of SpamAgent
21 enum 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 
29 class SpamAgent
30 {
31 public:
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  Q_REQUIRED_RESULT QString name() const
55  {
56  return mName;
57  }
58 
59  Q_REQUIRED_RESULT SpamAgentTypes scoreType() const
60  {
61  return mType;
62  }
63 
64  Q_REQUIRED_RESULT QByteArray header() const
65  {
66  return mField;
67  }
68 
69  Q_REQUIRED_RESULT QByteArray confidenceHeader() const
70  {
71  return mConfidenceField;
72  }
73 
74  Q_REQUIRED_RESULT QRegularExpression scorePattern() const
75  {
76  return mScore;
77  }
78 
79  Q_REQUIRED_RESULT QRegularExpression thresholdPattern() const
80  {
81  return mThreshold;
82  }
83 
84  Q_REQUIRED_RESULT QRegularExpression confidencePattern() const
85  {
86  return mConfidence;
87  }
88 
89 private:
90  QString mName;
91  SpamAgentTypes mType;
92  QByteArray mField;
93  QByteArray mConfidenceField;
94  QRegularExpression mScore;
95  QRegularExpression mThreshold;
96  QRegularExpression mConfidence;
97 };
98 using SpamAgents = QVector<SpamAgent>;
99 
100 class AntiSpamConfigSingletonProvider;
101 
102 /**
103  @short Singleton to manage loading the kmail.antispamrc file.
104  @author Patrick Audley <[email protected]>
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 
115 private:
116  AntiSpamConfig();
117 
118 public:
119  ~AntiSpamConfig();
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 
136 private:
137  SpamAgents mAgents;
138 
139  void readConfig();
140 };
141 }
const SpamAgents agents() const
Returns a list of all agents found on the system.
Singleton to manage loading the kmail.antispamrc file.
const SpamAgents uniqueAgents() const
Returns a list of unique agents, found on the system.
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:30 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.