cutelyst  3.9.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
validatoremail.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2017-2022 Matthias Fehring <mf@huessenbergnetz.de>
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 #ifndef CUTELYSTVALIDATOREMAIL_H
6 #define CUTELYSTVALIDATOREMAIL_H
7 
8 #include "validatorrule.h"
9 
10 #include <Cutelyst/cutelyst_global.h>
11 
12 namespace Cutelyst {
13 
14 class ValidatorEmailPrivate;
15 
42 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorEmail : public ValidatorRule
43 {
44  Q_GADGET
45 public:
49  enum Category : quint8 {
50  Valid = 1,
51  DNSWarn = 7,
53  RFC5321 = 15,
56  CFWS = 31,
58  Deprecated = 63,
60  RFC5322 = 127,
63  Error = 255
64  };
65  Q_ENUM(Category)
66 
67 
70  enum Diagnose : quint8 {
71  // Address is valid
72  ValidAddress =
73  0,
76  // Address is valid but a DNS check was not successful
77  DnsWarnNoMxRecord =
78  5,
79  DnsWarnNoRecord = 6,
80  // Address is valid for SMTP but has unusual Elements
81  RFC5321TLD = 9,
82  RFC5321TLDNumberic =
83  10,
84  RFC5321QuotedString = 11,
85  RFC5321AddressLiteral = 12,
86  RFC5321IPv6Deprecated =
87  13,
90  // Address is valid within the message but cannot be used unmodified for the envelope
91  CFWSComment = 17,
92  CFWSFWS = 18,
93  // Address contains deprecated elements but may still be valid in restricted contexts
94  DeprecatedLocalpart = 33,
95  DeprecatedFWS = 34,
96  DeprecatedQText = 35,
97  DeprecatedQP = 36,
98  DeprecatedComment = 37,
99  DeprecatedCText = 38,
100  DeprecatedCFWSNearAt =
101  49,
102  // The address in only valid according to the broad definition of RFC 5322. It is otherwise
103  // invalid
104  RFC5322Domain =
105  65,
107  RFC5322TooLong = 66,
108  RFC5322LocalTooLong = 67,
109  RFC5322DomainTooLong = 68,
110  RFC5322LabelTooLong = 69,
111  RFC5322DomainLiteral =
112  70,
114  RFC5322DomLitOBSDText = 71,
117  RFC5322IPv6GroupCount =
118  72,
119  RFC5322IPv62x2xColon = 73,
120  RFC5322IPv6BadChar = 74,
121  RFC5322IPv6MaxGroups = 75,
122  RFC5322IPv6ColonStart = 76,
123  RFC5322IPv6ColonEnd = 77,
124  // Address is invalid for any purpose
125  ErrorExpectingDText =
126  129,
127  ErrorNoLocalPart = 130,
128  ErrorNoDomain = 131,
129  ErrorConsecutiveDots = 132,
130  ErrorATextAfterCFWS =
131  133,
132  ErrorATextAfterQS = 134,
133  ErrorATextAfterDomLit =
134  135,
135  ErrorExpectingQpair =
136  136,
137  ErrorExpectingAText = 137,
138  ErrorExpectingQText = 138,
139  ErrorExpectingCText = 139,
140  ErrorBackslashEnd = 140,
141  ErrorDotStart = 141,
142  ErrorDotEnd = 142,
143  ErrorDomainHyphenStart = 143,
144  ErrorDomainHyphenEnd = 144,
145  ErrorUnclosedQuotedStr = 145,
146  ErrorUnclosedComment = 146,
147  ErrorUnclosedDomLiteral = 147,
148  ErrorFWSCRLFx2 = 148,
149  ErrorFWSCRLFEnd = 149,
150  ErrorCRnoLF =
151  150,
152  ErrorFatal = 254
153  };
154  Q_ENUM(Diagnose)
155 
156  enum Option : quint8 {
157  NoOption = 0,
158  CheckDNS =
159  1,
160  UTF8Local = 2,
161  AllowIDN = 4,
162  AllowUTF8 = UTF8Local | AllowIDN
164  };
165  Q_DECLARE_FLAGS(Options, Option)
166 
167 
175  ValidatorEmail(const QString &field,
176  Category threshold = RFC5321,
177  Options options = NoOption,
178  const ValidatorMessages &messages = ValidatorMessages(),
179  const QString &defValKey = QString());
180 
184  ~ValidatorEmail() override;
185 
193  static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label = QString());
194 
202  static QString categoryString(Context *c, Category category, const QString &label = QString());
203 
209  static Category category(Diagnose diagnose);
210 
218  static QString categoryString(Context *c, Diagnose diagnose, const QString &label = QString());
219 
230  static bool validate(const QString &email,
231  Category threshold = RFC5321,
232  Options options = NoOption,
233  QList<Diagnose> *diagnoses = nullptr);
234 
235 protected:
244  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
245 
249  QString genericValidationError(Context *c,
250  const QVariant &errorData = QVariant()) const override;
251 
252 private:
253  Q_DECLARE_PRIVATE(ValidatorEmail)
254  Q_DISABLE_COPY(ValidatorEmail)
255 };
256 
257 } // namespace Cutelyst
258 
259 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorEmail::Options)
260 
261 #endif // CUTELYSTVALIDATOREMAIL_H
Stores custom error messages and the input field label.
The Cutelyst Context.
Definition: context.h:38
Checks if the value is a valid email address according to specific RFCs.
The Cutelyst namespace holds all public Cutelyst API.
Definition: Mainpage.dox:7
Base class for all validator rules.
Category
Validation category, used as threshold to define valid addresses.
Contains the result of a single input parameter validation.
Definition: validatorrule.h:49
Diagnose
Single diagnose values that show why an address is not valid.