cutelyst  3.7.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-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 <Cutelyst/cutelyst_global.h>
9 #include "validatorrule.h"
10 
11 namespace Cutelyst {
12 
13 class ValidatorEmailPrivate;
14 
36 class CUTELYST_PLUGIN_UTILS_VALIDATOR_EXPORT ValidatorEmail : public ValidatorRule
37 {
38  Q_GADGET
39 public:
43  enum Category : quint8 {
44  Valid = 1,
45  DNSWarn = 7,
46  RFC5321 = 15,
47  CFWS = 31,
48  Deprecated = 63,
49  RFC5322 = 127,
50  Error = 255
51  };
52  Q_ENUM(Category)
53 
54 
57  enum Diagnose : quint8 {
58  // Address is valid
59  ValidAddress = 0,
60  // Address is valid but a DNS check was not successful
61  DnsWarnNoMxRecord = 5,
62  DnsWarnNoRecord = 6,
63  // Address is valid for SMTP but has unusual Elements
64  RFC5321TLD = 9,
65  RFC5321TLDNumberic = 10,
66  RFC5321QuotedString = 11,
67  RFC5321AddressLiteral = 12,
68  RFC5321IPv6Deprecated = 13,
69  // Address is valid within the message but cannot be used unmodified for the envelope
70  CFWSComment = 17,
71  CFWSFWS = 18,
72  // Address contains deprecated elements but may still be valid in restricted contexts
73  DeprecatedLocalpart = 33,
74  DeprecatedFWS = 34,
75  DeprecatedQText = 35,
76  DeprecatedQP = 36,
77  DeprecatedComment = 37,
78  DeprecatedCText = 38,
79  DeprecatedCFWSNearAt = 49,
80  // The address in only valid according to the broad definition of RFC 5322. It is otherwise invalid
81  RFC5322Domain = 65,
82  RFC5322TooLong = 66,
83  RFC5322LocalTooLong = 67,
84  RFC5322DomainTooLong = 68,
85  RFC5322LabelTooLong = 69,
86  RFC5322DomainLiteral = 70,
87  RFC5322DomLitOBSDText = 71,
88  RFC5322IPv6GroupCount = 72,
89  RFC5322IPv62x2xColon = 73,
90  RFC5322IPv6BadChar = 74,
91  RFC5322IPv6MaxGroups = 75,
92  RFC5322IPv6ColonStart = 76,
93  RFC5322IPv6ColonEnd = 77,
94  // Address is invalid for any purpose
95  ErrorExpectingDText = 129,
96  ErrorNoLocalPart = 130,
97  ErrorNoDomain = 131,
98  ErrorConsecutiveDots = 132,
99  ErrorATextAfterCFWS = 133,
100  ErrorATextAfterQS = 134,
101  ErrorATextAfterDomLit = 135,
102  ErrorExpectingQpair = 136,
103  ErrorExpectingAText = 137,
104  ErrorExpectingQText = 138,
105  ErrorExpectingCText = 139,
106  ErrorBackslashEnd = 140,
107  ErrorDotStart = 141,
108  ErrorDotEnd = 142,
109  ErrorDomainHyphenStart = 143,
110  ErrorDomainHyphenEnd = 144,
111  ErrorUnclosedQuotedStr = 145,
112  ErrorUnclosedComment = 146,
113  ErrorUnclosedDomLiteral = 147,
114  ErrorFWSCRLFx2 = 148,
115  ErrorFWSCRLFEnd = 149,
116  ErrorCRnoLF = 150,
117  ErrorFatal = 254
118  };
119  Q_ENUM(Diagnose)
120 
121  enum Option : quint8 {
122  NoOption = 0,
123  CheckDNS = 1,
124  UTF8Local = 2,
125  AllowIDN = 4,
126  AllowUTF8 = UTF8Local|AllowIDN
127  };
128  Q_DECLARE_FLAGS(Options, Option)
129 
130 
137  ValidatorEmail(const QString &field, Category threshold = RFC5321, Options options = NoOption, const ValidatorMessages &messages = ValidatorMessages(), const QString &defValKey = QString());
138 
142  ~ValidatorEmail() override;
143 
151  static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label = QString());
152 
160  static QString categoryString(Context *c, Category category, const QString &label = QString());
161 
167  static Category category(Diagnose diagnose);
168 
176  static QString categoryString(Context *c, Diagnose diagnose, const QString &label = QString());
177 
187  static bool validate(const QString &email, Category threshold = RFC5321, Options options = NoOption, QList<Diagnose> *diagnoses = nullptr);
188 
189 protected:
197  ValidatorReturnType validate(Context *c, const ParamsMultiMap &params) const override;
198 
202  QString genericValidationError(Context *c, const QVariant &errorData = QVariant()) const override;
203 
204 private:
205  Q_DECLARE_PRIVATE(ValidatorEmail)
206  Q_DISABLE_COPY(ValidatorEmail)
207 };
208 
209 }
210 
211 Q_DECLARE_OPERATORS_FOR_FLAGS(Cutelyst::ValidatorEmail::Options)
212 
213 #endif //CUTELYSTVALIDATOREMAIL_H
214 
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.
Category
Validation category, used as threshold to define valid addresses.
Base class for all validator rules.
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.
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.
Definition: validatorrule.h:49