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
12namespace Cutelyst {
13
14class ValidatorEmailPrivate;
15
42class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorEmail : public ValidatorRule
43{
44 Q_GADGET
45public:
49 enum Category : quint8 {
50 Valid = 1,
51 DNSWarn = 7,
53 RFC5321 = 15,
56 CFWS = 31,
60 RFC5322 = 127,
63 Error = 255
64 };
65 Q_ENUM(Category)
66
67
70 enum Diagnose : quint8 {
71 // Address is valid
73 0,
76 // Address is valid but a DNS check was not successful
78 5,
80 // Address is valid for SMTP but has unusual Elements
83 10,
87 13,
90 // Address is valid within the message but cannot be used unmodified for the envelope
92 CFWSFWS = 18,
93 // Address contains deprecated elements but may still be valid in restricted contexts
101 49,
102 // The address in only valid according to the broad definition of RFC 5322. It is otherwise
103 // invalid
105 65,
112 70,
118 72,
124 // Address is invalid for any purpose
126 129,
131 133,
134 135,
136 136,
151 150,
153 };
154 Q_ENUM(Diagnose)
155
156 enum Option : quint8 {
159 1,
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
235protected:
244 ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
245
249 QString genericValidationError(Context *c,
250 const QVariant &errorData = QVariant()) const override;
251
252private:
253 Q_DECLARE_PRIVATE(ValidatorEmail)
254 Q_DISABLE_COPY(ValidatorEmail)
255};
256
257} // namespace Cutelyst
258
259Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorEmail::Options)
260
261#endif // CUTELYSTVALIDATOREMAIL_H
The Cutelyst Context.
Definition context.h:39
Checks if the value is a valid email address according to specific RFCs.
Diagnose
Single diagnose values that show why an address is not valid.
ValidatorEmail(const QString &field, Category threshold=RFC5321, Options options=NoOption, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new email validator.
Category
Validation category, used as threshold to define valid addresses.
ValidatorRule(const QString &field, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Constructs a new ValidatorRule with the given parameters.
The Cutelyst namespace holds all public Cutelyst API.
Definition Mainpage.dox:8
QMultiMap< QString, QString > ParamsMultiMap
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.