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,
64 RFC5322 = 127,
67 Error = 255
68 };
69 Q_ENUM(Category)
70
71
74 enum Diagnose : int {
75 // Address is valid
77 0,
80 // Address is valid but a DNS check was not successful
82 5,
84 // Address is valid for SMTP but has unusual Elements
87 10,
91 13,
94 // Address is valid within the message but cannot be used unmodified for the envelope
96 CFWSFWS = 18,
97 // Address contains deprecated elements but may still be valid in restricted contexts
105 49,
106 // The address in only valid according to the broad definition of RFC 5322. It is otherwise
107 // invalid
109 65,
116 70,
122 72,
128 // Address is invalid for any purpose
130 129,
135 133,
138 135,
140 136,
155 150,
157 };
158 Q_ENUM(Diagnose)
159
160 enum Option : quint8 {
163 1,
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.
static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label={})
ValidatorEmail(const QString &field, Category threshold=RFC5321, Options options=NoOption, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
QString label(Context *c) const
ValidatorRule(const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
The Cutelyst namespace holds all public Cutelyst API.
Stores custom error messages and the input field label.