cutelyst  4.3.0
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-2023 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 
48 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorEmail : public ValidatorRule
49 {
50  Q_GADGET
51 public:
55  enum Category : int {
56  Valid = 1,
57  DNSWarn = 7,
59  RFC5321 = 15,
62  CFWS = 31,
64  Deprecated = 63,
66  RFC5322 = 127,
69  Error = 255
70  };
71  Q_ENUM(Category)
72 
73 
76  enum Diagnose : int {
77  // Address is valid
78  ValidAddress =
79  0,
82  // Address is valid but a DNS check was not successful
83  DnsWarnNoMxRecord =
84  5,
85  DnsWarnNoRecord = 6,
86  // Address is valid for SMTP but has unusual Elements
87  RFC5321TLD = 9,
88  RFC5321TLDNumeric =
89  10,
90  RFC5321QuotedString = 11,
91  RFC5321AddressLiteral = 12,
92  RFC5321IPv6Deprecated =
93  13,
96  // Address is valid within the message but cannot be used unmodified for the envelope
97  CFWSComment = 17,
98  CFWSFWS = 18,
99  // Address contains deprecated elements but may still be valid in restricted contexts
100  DeprecatedLocalpart = 33,
101  DeprecatedFWS = 34,
102  DeprecatedQText = 35,
103  DeprecatedQP = 36,
104  DeprecatedComment = 37,
105  DeprecatedCText = 38,
106  DeprecatedCFWSNearAt =
107  49,
108  // The address in only valid according to the broad definition of RFC 5322. It is otherwise
109  // invalid
110  RFC5322Domain =
111  65,
113  RFC5322TooLong = 66,
114  RFC5322LocalTooLong = 67,
115  RFC5322DomainTooLong = 68,
116  RFC5322LabelTooLong = 69,
117  RFC5322DomainLiteral =
118  70,
120  RFC5322DomLitOBSDText = 71,
123  RFC5322IPv6GroupCount =
124  72,
125  RFC5322IPv62x2xColon = 73,
126  RFC5322IPv6BadChar = 74,
127  RFC5322IPv6MaxGroups = 75,
128  RFC5322IPv6ColonStart = 76,
129  RFC5322IPv6ColonEnd = 77,
130  // Address is invalid for any purpose
131  ErrorExpectingDText =
132  129,
133  ErrorNoLocalPart = 130,
134  ErrorNoDomain = 131,
135  ErrorConsecutiveDots = 132,
136  ErrorATextAfterCFWS =
137  133,
138  ErrorATextAfterQS = 134,
139  ErrorATextAfterDomLit =
140  135,
141  ErrorExpectingQpair =
142  136,
143  ErrorExpectingAText = 137,
144  ErrorExpectingQText = 138,
145  ErrorExpectingCText = 139,
146  ErrorBackslashEnd = 140,
147  ErrorDotStart = 141,
148  ErrorDotEnd = 142,
149  ErrorDomainHyphenStart = 143,
150  ErrorDomainHyphenEnd = 144,
151  ErrorUnclosedQuotedStr = 145,
152  ErrorUnclosedComment = 146,
153  ErrorUnclosedDomLiteral = 147,
154  ErrorFWSCRLFx2 = 148,
155  ErrorFWSCRLFEnd = 149,
156  ErrorCRnoLF =
157  150,
158  ErrorFatal = 254
159  };
160  Q_ENUM(Diagnose)
161 
162  enum Option : quint8 {
163  NoOption = 0,
164  CheckDNS =
165  1,
166  UTF8Local = 2,
167  AllowIDN = 4,
168  AllowUTF8 = UTF8Local | AllowIDN
170  };
171  Q_DECLARE_FLAGS(Options, Option)
172 
173 
182  ValidatorEmail(const QString &field,
183  Category threshold = RFC5321,
184  Options options = NoOption,
185  const ValidatorMessages &messages = ValidatorMessages(),
186  const QString &defValKey = QString());
187 
191  ~ValidatorEmail() override;
192 
200  static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label = {});
201 
209  static QString categoryString(Context *c, Category category, const QString &label = {});
210 
216  static Category category(Diagnose diagnose);
217 
226  static QString categoryString(Context *c, Diagnose diagnose, const QString &label = {});
227 
241  static bool validate(const QString &email,
242  Category threshold = RFC5321,
243  Options options = NoOption,
244  QList<Diagnose> *diagnoses = nullptr);
245 
246 protected:
255  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
256 
260  QString genericValidationError(Context *c,
261  const QVariant &errorData = QVariant()) const override;
262 
263 private:
264  Q_DECLARE_PRIVATE(ValidatorEmail) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
265  Q_DISABLE_COPY(ValidatorEmail)
266 };
267 
268 } // namespace Cutelyst
269 
270 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorEmail::Options)
271 
272 #endif // CUTELYSTVALIDATOREMAIL_H
Stores custom error messages and the input field label.
The Cutelyst Context.
Definition: context.h:42
Checks if the value is a valid email address according to specific RFCs.
The Cutelyst namespace holds all public Cutelyst API.
Base class for all validator rules.
QMultiMap< QString, QString > ParamsMultiMap
Category
Validation category, used as threshold to define valid addresses.
Diagnose
Single diagnose values that show why an address is not valid.