Messagelib

spamheaderanalyzer.h
1 /*
2  spamheaderanalyzer.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 <KMime/Message>
14 
15 #include <QString>
16 #include <QVector>
17 
18 namespace MessageViewer
19 {
20 enum SpamError {
21  noError,
22  uninitializedStructUsed,
23  errorExtractingAgentString,
24  couldNotConverScoreToFloat,
25  couldNotConvertThresholdToFloatOrThresholdIsNegative,
26  couldNotFindTheScoreField,
27  couldNotFindTheThresholdField,
28  couldNotConvertConfidenceToFloat
29 };
30 
31 /**
32  @short A simple tuple of error, agent, score, confidence and header.
33 
34  The score returned is positive if no error has occurred.
35  error values indicate the following errors:
36  noError Spam Headers successfully parsed
37  uninitializedStructUsed Uninitialized struct used
38  errorExtractingAgentString Error extracting agent string
39  couldNotConverScoreToFloat Couldn't convert score to float
40  couldNotConvertThresholdToFloatOrThresholdIsNegative Couldn't convert threshold to float or threshold is negative
41  couldNotFindTheScoreField Couldn't find the score field
42  couldNotFindTheThresholdField Couldn't find the threshold field
43  couldNotConvertConfidenceToFloat Couldn't convert confidence to float
44 */
45 class SpamScore
46 {
47 public:
48  SpamScore()
49  : mError(noError)
50  , mScore(-2.0)
51  , mConfidence(-2.0)
52  {
53  }
54 
55  SpamScore(const QString &agent, SpamError error, float score, float confidence, const QString &header, const QString &cheader)
56  : mAgent(agent)
57  , mError(error)
58  , mScore(score)
59  , mConfidence(confidence)
60  , mHeader(header)
61  , mConfidenceHeader(cheader)
62  {
63  }
64 
65  Q_REQUIRED_RESULT QString agent() const
66  {
67  return mAgent;
68  }
69 
70  Q_REQUIRED_RESULT float score() const
71  {
72  return mScore;
73  }
74 
75  Q_REQUIRED_RESULT float confidence() const
76  {
77  return mConfidence;
78  }
79 
80  Q_REQUIRED_RESULT SpamError error() const
81  {
82  return mError;
83  }
84 
85  Q_REQUIRED_RESULT QString spamHeader() const
86  {
87  return mHeader;
88  }
89 
90  Q_REQUIRED_RESULT QString confidenceHeader() const
91  {
92  return mConfidenceHeader;
93  }
94 
95 private:
96  QString mAgent;
97  SpamError mError;
98  float mScore;
99  float mConfidence;
100  QString mHeader;
101  QString mConfidenceHeader;
102 };
104 
105 /**
106  @short Flyweight for analysing spam headers.
107  @author Patrick Audley <[email protected]>
108  */
110 {
111 public:
112  /**
113  @short Extract scores from known anti-spam headers
114  @param message A KMime::Message to examine
115  @return A list of detected scores. See SpamScore
116  */
117  static SpamScores getSpamScores(KMime::Message *message);
118 };
119 }
120 
Flyweight for analysing spam headers.
A simple tuple of error, agent, score, confidence and header.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.