cutelyst 5.0.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-2025 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 Diagnose : int {
54 // Address is valid
56 0,
59 // Address is valid but there are warnings about the DNS
61 4,
66 // Address is valid but a DNS check was not successful
70 6,
73 8,
74 // Address is valid for SMTP but has unusual Elements
77 10,
81 13,
84 // Address is valid within the message but cannot be used unmodified for the envelope
86 CFWSFWS = 18,
87 // Address contains deprecated elements but may still be valid in restricted contexts
95 49,
96 // The address in only valid according to the broad definition of RFC 5322. It is otherwise
97 // invalid
99 65,
106 70,
112 72,
118 // Address is invalid for any purpose
120 129,
125 133,
128 135,
130 136,
145 150,
147 };
148 Q_ENUM(Diagnose)
149
150
174 Q_ENUM(Category)
175
185 Q_DECLARE_FLAGS(Options, Option)
186
187
196 explicit ValidatorEmail(const QString &field,
197 Category threshold = RFC5321,
198 Options options = NoOption,
199 const ValidatorMessages &messages = {},
200 const QString &defValKey = {});
201
205 ~ValidatorEmail() override;
206
214 static QString diagnoseString(const Context *c, Diagnose diagnose, const QString &label = {});
215
223 static QString categoryString(const Context *c, Category category, const QString &label = {});
224
230 static Category category(Diagnose diagnose);
231
240 static QString categoryString(const Context *c, Diagnose diagnose, const QString &label = {});
241
257 static bool validate(const QString &email,
258 Category threshold = RFC5321,
259 Options options = NoOption,
260 QList<Diagnose> *diagnoses = nullptr);
261
276 static void validateCb(
277 const QString &email,
278 Category threshold,
279 Options options,
280 std::function<
281 void(bool isValid, const QString &cleanedEmail, const QList<Diagnose> &diagnoses)> cb);
282
283protected:
295 ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
296
308 void validateCb(Context *c, const ParamsMultiMap &params, ValidatorRtFn cb) const override;
309
314 const QVariant &errorData = QVariant()) const override;
315
316private:
317 Q_DECLARE_PRIVATE(ValidatorEmail) // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
318 Q_DISABLE_COPY(ValidatorEmail)
319};
320
321} // namespace Cutelyst
322
323Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorEmail::Options)
324
325#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.
ValidatorEmail(const QString &field, Category threshold=RFC5321, Options options=NoOption, const ValidatorMessages &messages={}, const QString &defValKey={})
Diagnose
Single diagnose values that show why an address is not valid.
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
static QString diagnoseString(const Context *c, Diagnose diagnose, const QString &label={})
QString label(const Context *c) const
ValidatorRule(const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
std::function< void(ValidatorReturnType &&result)> ValidatorRtFn
Void callback function for validator rules that processes the ValidatorReturnType.
QMultiMap< QString, QString > ParamsMultiMap
static void validateCb(const QString &email, Category threshold, Options options, std::function< void(bool isValid, const QString &cleanedEmail, const QList< Diagnose > &diagnoses)> cb)
Checks if the email is a valid address according to the Category given in the threshold.
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.