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