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

KDE's Doxygen guidelines are available online.