19 #include "validatoremail_p.h"
20 #include <QRegularExpression>
28 using namespace Cutelyst;
31 ValidatorRule(*new ValidatorEmailPrivate(field, threshold, options, messages, defValKey))
72 ValidatorEmailDiagnoseStruct diag;
74 if (ValidatorEmailPrivate::checkEmail(v, d->options, d->threshold, &diag)) {
75 if (!diag.literal.isEmpty()) {
84 result.
extra = QVariant::fromValue<QList<Diagnose>>(diag.returnStatus);
103 bool ValidatorEmailPrivate::checkEmail(
const QString &address, ValidatorEmail::Options options,
ValidatorEmail::Category threshold, ValidatorEmailDiagnoseStruct *diagnoseStruct)
109 EmailPart context = ComponentLocalpart;
111 EmailPart contextPrior = ComponentLocalpart;
121 int elementCount = 0;
123 bool hypenFlag =
false;
124 bool endOrDie =
false;
128 const QString stringSpecials = QStringLiteral(
"()<>[]:;@\\,.\"");
139 const QString domain = address.
mid(atPos + 1);
140 bool asciiDomain =
true;
141 for (
const QChar &ch : domain) {
142 const ushort &uc = ch.
unicode();
161 const int rawLength = email.
length();
163 for (
int i = 0; i < rawLength; i++) {
170 case ComponentLocalpart:
190 if (elementLen == 0) {
198 contextStack.push_back(context);
199 context = ContextComment;
201 if (elementLen == 0) {
213 parseLocalPart += token;
214 atomListLocalPart[elementCount] =
QString();
216 if (elementLen == 0) {
221 parseLocalPart += token;
222 atomListLocalPart[elementCount] += token;
225 contextStack.push_back(context);
226 context = ContextQuotedString;
230 }
else if ((token ==
QChar(QChar::CarriageReturn)) || (token ==
QChar(QChar::Space)) || (token ==
QChar(QChar::Tabulation))) {
231 if ((token ==
QChar(QChar::CarriageReturn)) && ((++i == rawLength) || (email[i] !=
QChar(QChar::LineFeed)))) {
236 if (elementLen == 0) {
242 contextStack.push_back(context);
243 context = ContextFWS;
247 if (contextStack.size() != 1) {
249 qCCritical(C_VALIDATOR,
"ValidatorEmail: Unexpected item on context stack");
253 if (parseLocalPart.
isEmpty()) {
255 }
else if (elementLen == 0) {
257 }
else if (parseLocalPart.
size() > 64) {
262 }
else if ((contextPrior == ContextComment) || (contextPrior == ContextFWS)) {
276 context = ComponentDomain;
277 contextStack.clear();
278 contextStack.push_back(context);
297 switch (contextPrior) {
302 case ContextQuotedString:
307 qCCritical(C_VALIDATOR,
"ValidatorEmail: More atext found where none is allowed, but unrecognised prior context.");
311 contextPrior = context;
312 const ushort uni = token.
unicode();
314 if (!allowUtf8Local) {
315 if ((uni < 33) || (uni > 126) || stringSpecials.
contains(token)) {
320 if ((uni < 33) || (uni > 126) || stringSpecials.
contains(token)) {
326 parseLocalPart += token;
327 atomListLocalPart[elementCount] += token;
336 case ComponentDomain:
377 if (elementLen == 0) {
387 contextStack.push_back(context);
388 context = ContextComment;
390 if (elementLen == 0) {
393 }
else if (hypenFlag) {
409 if (elementLen > 63) {
417 atomListDomain[elementCount] =
QString();
418 parseDomain += token;
424 contextStack.push_back(context);
425 context = ComponentLiteral;
426 parseDomain += token;
427 atomListDomain[elementCount] += token;
432 }
else if ((token ==
QChar(QChar::CarriageReturn)) || (token ==
QChar(QChar::Space)) || (token ==
QChar(QChar::Tabulation))) {
433 if ((token ==
QChar(QChar::CarriageReturn)) && ((++i == rawLength) || email[i] !=
QChar(QChar::LineFeed))) {
438 if (elementLen == 0) {
445 contextStack.push_back(context);
446 context = ContextFWS;
474 switch (contextPrior) {
479 case ComponentLiteral:
484 qCCritical(C_VALIDATOR,
"ValidatorEmail: More atext found where none is allowed, but unrecognised prior context.");
489 const ushort uni = token.
unicode();
492 if ((uni < 33) || (uni > 126) || stringSpecials.
contains(token)) {
495 if (elementLen == 0) {
500 }
else if (!(((uni > 47) && (uni < 58)) || ((uni > 64) && (uni < 91)) || ((uni > 96) && (uni < 123)))) {
505 parseDomain += token;
506 atomListDomain[elementCount] += token;
514 case ComponentLiteral:
525 if (static_cast<int>(*std::max_element(returnStatus.constBegin(), returnStatus.constEnd())) <
static_cast<int>(
ValidatorEmail::Deprecated)) {
581 QString addressLiteral = parseLiteral;
583 QRegularExpression ipv4Regex(QStringLiteral(
"\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"));
600 int groupCount = matchesIP.
size();
605 if (groupCount != maxGroups) {
612 if ((index == 0) || (index == (ipv6.
length() - 2))) {
616 if (groupCount > maxGroups) {
618 }
else if (groupCount == maxGroups) {
629 int unmatchedChars = 0;
630 for (
const QString &ip : matchesIP) {
635 if (unmatchedChars != 0) {
647 parseDomain += token;
648 atomListDomain[elementCount] += token;
650 contextPrior = context;
651 context = contextStack.takeLast();
654 contextStack.push_back(context);
655 context = ContextQuotedPair;
656 }
else if ((token ==
QChar(QChar::CarriageReturn)) || (token ==
QChar(QChar::Space)) || (token ==
QChar(QChar::Tabulation))) {
657 if ((token ==
QChar(QChar::CarriageReturn)) && ((++i == rawLength) || (email[i] !=
QChar(QChar::LineFeed)))) {
663 contextStack.push_back(context);
664 context = ContextFWS;
680 const ushort uni = token.
unicode();
683 if ((uni > 127) || (uni == 0) || (uni ==
QLatin1Char(
'['))) {
686 }
else if ((uni < 33) || (uni == 127)) {
690 parseLiteral += token;
691 parseDomain += token;
692 atomListDomain[elementCount] += token;
700 case ContextQuotedString:
709 contextStack.push_back(context);
710 context = ContextQuotedPair;
711 }
else if ((token ==
QChar(QChar::CarriageReturn)) || (token ==
QChar(QChar::Tabulation))) {
714 if ((token ==
QChar(QChar::CarriageReturn)) && ((++i == rawLength) || (email[i] !=
QChar(QChar::LineFeed)))) {
728 parseLocalPart +=
QChar(QChar::Space);
729 atomListLocalPart[elementCount] +=
QChar(QChar::Space);
733 contextStack.push_back(context);
734 context = ContextFWS;
737 parseLocalPart += token;
738 atomListLocalPart[elementCount] +=token;
740 contextPrior = context;
741 context = contextStack.takeLast();
756 const ushort uni = token.
unicode();
758 if (!allowUtf8Local) {
759 if ((uni > 127) || (uni == 0) || (uni == 10)) {
761 }
else if ((uni < 32) || (uni == 127)) {
766 if ((uni > 127) || (uni == 0) || (uni == 10)) {
768 }
else if ((uni < 32) || (uni == 127)) {
774 parseLocalPart += token;
775 atomListLocalPart[elementCount] += token;
791 case ContextQuotedPair:
809 const ushort uni = token.
unicode();
813 }
else if (((uni < 31) && (uni != 9)) || (uni == 127)) {
824 contextPrior = context;
825 context = contextStack.takeLast();
830 case ContextQuotedString:
832 parseLocalPart += token;
833 atomListLocalPart[elementCount] +=
QLatin1Char(
'\\');
834 atomListLocalPart[elementCount] += token;
837 case ComponentLiteral:
839 parseDomain += token;
841 atomListDomain[elementCount] += token;
846 qCCritical(C_VALIDATOR,
"ValidatorEmail: Quoted pair logic invoked in an invalid context.");
862 contextStack.push_back(context);
863 context = ContextComment;
865 contextPrior = context;
866 context = contextStack.takeLast();
883 contextStack.push_back(context);
884 context = ContextQuotedPair;
885 }
else if ((token ==
QChar(QChar::CarriageReturn)) || (token ==
QChar(QChar::Space)) || (token ==
QChar(QChar::Tabulation))) {
886 if ((token ==
QChar(QChar::CarriageReturn)) && ((++i == rawLength) || (email[i] !=
QChar(QChar::LineFeed)))) {
892 contextStack.push_back(context);
893 context = ContextFWS;
910 const ushort uni = token.
unicode();
912 if ((uni > 127) || (uni == 0) || (uni == 10)) {
915 }
else if ((uni < 32) || (uni == 127)) {
938 if (tokenPrior ==
QChar(QChar::CarriageReturn)) {
939 if (token ==
QChar(QChar::CarriageReturn)) {
944 if (crlf_count > 0) {
945 if (++crlf_count > 1) {
953 if (token ==
QChar(QChar::CarriageReturn)) {
954 if ((++i == rawLength) || (email[i] !=
QChar(QChar::LineFeed))) {
958 }
else if ((token !=
QChar(QChar::Space)) && (token !=
QChar(QChar::Tabulation))) {
959 if (tokenPrior ==
QChar(QChar::CarriageReturn)) {
964 if (crlf_count > 0) {
968 contextPrior = context;
969 context = contextStack.takeLast();
994 qCCritical(C_VALIDATOR,
"ValidatorEmail: Unknown context");
998 if (static_cast<int>(*std::max_element(returnStatus.constBegin(), returnStatus.constEnd())) >
static_cast<int>(
ValidatorEmail::RFC5322)) {
1004 if (static_cast<int>(*std::max_element(returnStatus.constBegin(), returnStatus.constEnd())) <
static_cast<int>(
ValidatorEmail::RFC5322)) {
1005 if (context == ContextQuotedString) {
1007 }
else if (context == ContextQuotedPair) {
1009 }
else if (context == ContextComment) {
1011 }
else if (context == ComponentLiteral) {
1013 }
else if (token ==
QChar(QChar::CarriageReturn)) {
1015 }
else if (parseDomain.
isEmpty()) {
1017 }
else if (elementLen == 0) {
1019 }
else if (hypenFlag) {
1021 }
else if (parseDomain.
size() > 255) {
1025 }
else if ((parseLocalPart.
size() + 1 + parseDomain.
size()) > 254) {
1045 }
else if (elementLen > 63) {
1051 bool dnsChecked =
false;
1053 if (checkDns && (static_cast<int>(*std::max_element(returnStatus.constBegin(), returnStatus.constEnd())) <
static_cast<int>(threshold))) {
1067 if (elementCount == 0) {
1071 QDnsLookup mxLookup(QDnsLookup::MX, parseDomain);
1078 if ((mxLookup.error() == QDnsLookup::NoError) && !mxLookup.mailExchangeRecords().empty()) {
1082 QDnsLookup aLookup(QDnsLookup::A, parseDomain);
1089 if ((aLookup.error() == QDnsLookup::NoError) && !aLookup.hostAddressRecords().empty()) {
1129 if (!dnsChecked && (static_cast<int>(*std::max_element(returnStatus.constBegin(), returnStatus.constEnd())) <
static_cast<int>(
ValidatorEmail::DNSWarn))) {
1130 if (elementCount == 0) {
1134 if (QStringLiteral(
"0123456789").contains(atomListDomain[elementCount][0])) {
1139 if (returnStatus.size() != 1) {
1141 for (
int j = 0; j < returnStatus.size(); ++j) {
1149 std::sort(returnStatus.begin(), returnStatus.end(), std::greater<ValidatorEmail::Diagnose>());
1154 if (diagnoseStruct) {
1155 diagnoseStruct->finalStatus = finalStatus;
1156 diagnoseStruct->returnStatus = returnStatus;
1157 diagnoseStruct->localpart = parseLocalPart;
1158 diagnoseStruct->domain = parseDomain;
1159 diagnoseStruct->literal = parseLiteral;
1162 ret = (
static_cast<int>(finalStatus) < static_cast<int>(threshold));
1174 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid. Please note that this does not mean that both the address and the domain actually exist. This address could be issued by the domain owner without breaking the rules of any RFCs.");
1177 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Could not find an MX record for this address’ domain but an A record does exist.");
1180 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Could neither find an MX record nor an A record for this address’ domain.");
1183 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but at a Top Level Domain.");
1186 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but the Top Level Domain begins with a number.");
1189 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but contains a quoted string.");
1192 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but uses an IP address instead of a domain name.");
1195 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but uses an IP address that contains a :: only eliding one zero group. All implementations must accept and be able to handle any legitimate RFC 4291 format.");
1198 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains comments.");
1201 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains folding white spaces like line breaks.");
1204 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The local part is in a deprecated form.");
1207 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains an obsolete form of folding white spaces.");
1210 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted string contains a deprecated character.");
1213 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted pair contains a deprecated character.");
1216 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains a comment in a position that is deprecated.");
1219 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A comment contains a deprecated character.");
1222 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains a comment or folding white space around the @ sign.");
1225 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is RFC 5322 compliant but contains domain characters that are not allowed by DNS.");
1228 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is too long.");
1231 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The local part of the address is too long.");
1234 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain part is too long.");
1237 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain part contains an element that is too long.");
1240 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain literal is not a valid RFC 5321 address literal.");
1243 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain literal is not a valid RFC 5321 domain literal and it contains obsolete characters.");
1246 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 literal address contains the wrong number of groups.");
1249 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 literal address contains too many :: sequences.");
1252 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address contains an illegal group of characters.");
1255 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address has too many groups.");
1258 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address starts with a single colon.");
1261 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address ends with a single colon.");
1264 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain literal contains a character that is not allowed.");
1267 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address has no local part.");
1270 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address has no domain part.");
1273 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address must not contain consecutive dots.");
1276 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains text after a comment or folding white space.");
1279 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains text after a quoted string.");
1282 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Extra characters were found after the end of the domain literal.");
1285 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The Address contains a character that is not allowed in a quoted pair.");
1288 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains a character that is not allowed.");
1291 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted string contains a character that is not allowed.");
1294 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A comment contains a character that is not allowed.");
1297 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address can not end with a backslash.");
1300 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Neither part of the address may begin with a dot.");
1303 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Neither part of the address may end with a dot.");
1306 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain or subdomain can not begin with a hyphen.");
1309 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain or subdomain can not end with a hyphen.");
1312 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Unclosed quoted string. (Missing double quotation mark)");
1315 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Unclosed comment. (Missing closing parantheses)");
1318 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Domain literal is missing its closing bracket.");
1321 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Folding white space contains consecutive line break sequences (CRLF).");
1324 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Folding white space ends with a line break sequence (CRLF).");
1327 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains a carriage return (CR) that is not followed by a line feed (LF).");
1330 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A fatal error occured while parsing the address.");
1342 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid. Please note that this does not mean that both the address and the domain actually exist. This address could be issued by the domain owner without breaking the rules of any RFCs.").
arg(label);
1345 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Could not find an MX record for the address’ domain in the “%1” field but an A record does exist.").
arg(label);
1348 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Could neither find an MX record nor an A record for address’ domain in the “%1” field.").
arg(label);
1351 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but at a Top Level Domain.").
arg(label);
1354 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but the Top Level Domain begins with a number.").
arg(label);
1357 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but contains a quoted string.").
arg(label);
1360 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but uses an IP address instead of a domain name.").
arg(label);
1363 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but uses an IP address that contains a :: only eliding one zero group. All implementations must accept and be able to handle any legitimate RFC 4291 format.").
arg(label);
1366 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains comments.").
arg(label);
1369 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains folding white spaces like line breaks.").
arg(label);
1372 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The local part of the address in the “%1” field is in a deprecated form.").
arg(label);
1375 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains an obsolete form of folding white spaces.").
arg(label);
1378 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted string in the address in the “%1” field contains a deprecated character.").
arg(label);
1381 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted pair in the address in the “%1” field contains a deprecate character.").
arg(label);
1384 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains a comment in a position that is deprecated.").
arg(label);
1387 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A comment in the address in the “%1” field contains a deprecated character.").
arg(label);
1390 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains a comment or folding white space around the @ sign.").
arg(label);
1393 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is RFC 5322 compliant but contains domain charachters that are not allowed by DNS.").
arg(label);
1396 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is too long.").
arg(label);
1399 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The local part of the address in the “%1” field is too long.").
arg(label);
1402 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain part of the address in the “%1” field is too long.").
arg(label);
1405 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain part of the address in the “%1” field contains an element that is too long.").
arg(label);
1408 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain literal of the address in the “%1” field is not a valid RFC 5321 address literal.").
arg(label);
1411 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The domain literal of the address in the “%1” field is not a valid RFC 5321 domain literal and it contains obsolete characters.").
arg(label);
1414 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 literal of the address in the “%1” field contains the wrong number of groups.").
arg(label);
1417 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 literal of the address in the “%1” field contains too many :: sequences.").
arg(label);
1420 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address of the email address in the “%1” field contains an illegal group of characters.").
arg(label);
1423 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address of the email address in the “%1” field has too many groups.").
arg(label);
1426 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address of the email address in the “%1” field starts with a single colon.").
arg(label);
1429 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The IPv6 address of the email address in the “%1” field ends with a single colon.").
arg(label);
1432 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain literal of the address in the “%1” field contains a character that is not allowed.").
arg(label);
1435 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field has no local part.").
arg(label);
1438 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field has no domain part.").
arg(label);
1441 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field must not contain consecutive dots.").
arg(label);
1444 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains text after a comment or folding white space.").
arg(label);
1447 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains text after a quoted string.").
arg(label);
1450 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Extra characters were found after the end of the domain literal of the address in the “%1” field.").
arg(label);
1453 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains a character that is not allowed in a quoted pair.").
arg(label);
1456 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains a character that is not allowed.").
arg(label);
1459 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A quoted string in the address in the “%1” field contains a character that is not allowed.").
arg(label);
1462 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A comment in the address in the “%1” field contains a character that is not allowed.").
arg(label);
1465 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field can't end with a backslash.").
arg(label);
1468 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Neither part of the address in the “%1” field may begin with a dot.").
arg(label);
1471 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Neither part of the address in the “%1” field may end with a dot.").
arg(label);
1474 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain or subdomain of the address in the “%1” field can not begin with a hyphen.").
arg(label);
1477 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A domain or subdomain of the address in the “%1” field can not end with a hyphen.").
arg(label);
1480 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Unclosed quoted string in the address in the “%1” field. (Missing double quotation mark)").
arg(label);
1483 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Unclosed comment in the address in the “%1” field. (Missing closing parantheses)").
arg(label);
1486 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Domain literal of the address in the “%1” field is missing its closing bracket.").
arg(label);
1489 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Folding white space in the address in the “%1” field contains consecutive line break sequences (CRLF).").
arg(label);
1492 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Folding white space in the address in the “%1” field ends with a line break sequence (CRLF).").
arg(label);
1495 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains a carriage return (CR) that is not followed by a line feed (LF).").
arg(label);
1498 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"A fatal error occured while parsing the address in the “%1” field.").
arg(label);
1514 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid.");
1517 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid but a DNS check was not successful.");
1520 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid for SMTP but has unusual elements.");
1523 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is valid within the message but can not be used unmodified for the envelope.");
1526 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address contains deprecated elements but my still be valid in restricted contexts.");
1529 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address is only valid according to the broad definition of RFC 5322. It is otherwise invalid.");
1532 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"Address is invalid for any purpose.");
1538 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid.").
arg(label);
1541 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid but a DNS check was not successful.").
arg(label);
1544 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid for SMTP but has unusual elements.").
arg(label);
1547 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is valid within the message but can not be used unmodified for the envelope.").
arg(label);
1550 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field contains deprecated elements but my still be valid in restricted contexts.").
arg(label);
1553 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is only valid according to the broad definition of RFC 5322. It is otherwise invalid.").
arg(label);
1556 ret = c->
translate(
"Cutelyst::ValidatorEmail",
"The address in the “%1” field is invalid for any purpose.").
arg(label);
1567 const quint8 diag =
static_cast<quint8
>(diagnose);
1569 if (diag < static_cast<quint8>(
Valid)) {
1571 }
else if (diag < static_cast<quint8>(
DNSWarn)) {
1573 }
else if (diag < static_cast<quint8>(
RFC5321)) {
1575 }
else if (diag < static_cast<quint8>(
CFWS)) {
1577 }
else if (diag < static_cast<quint8>(
Deprecated)) {
1579 }
else if (diag < static_cast<quint8>(
RFC5322)) {
1598 ValidatorEmailDiagnoseStruct diag;
1599 ret = ValidatorEmailPrivate::checkEmail(email, options, threshold, &diag);
1602 *diagnoses = diag.returnStatus;
1608 #include "moc_validatoremail.cpp"
QString captured(int nth) const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString label(Context *c) const
Returns the human readable field label used for generic error messages.
Stores custom error messages and the input field label.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const T & at(int i) const
static QString categoryString(Context *c, Category category, const QString &label=QString())
Returns a descriptive and translated string for the category.
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
void append(const T &value)
QString value(const ParamsMultiMap ¶ms) const
Returns the value of the field from the input params.
int exec(ProcessEventsFlags flags)
static QString diagnoseString(Context *c, Diagnose diagnose, const QString &label=QString())
Returns a descriptive and translated string for the diagnose.
QByteArray toAce(const QString &domain)
QStringRef leftRef(int n) const
Checks if the value is a valid email address according to specific RFCs.
QString validationError(Context *c, const QVariant &errorData=QVariant()) const
Returns a descriptive error message if validation failed.
QStringRef rightRef(int n) const
static Category category(Diagnose diagnose)
Returns the category the diagnose belongs to.
Base class for all validator rules.
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.
void defaultValue(Context *c, ValidatorReturnType *result, const char *validatorName) const
I a defValKey has been set in the constructor, this will try to get the default value from the stash ...
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void setValue(const T &value)
bool contains(const T &value) const
QStringRef midRef(int position, int n) const
const QChar * unicode() const
QString mid(int position, int n) const
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
Returns a generic error if validation failed.
QString translate(const char *context, const char *sourceText, const char *disambiguation=nullptr, int n=-1) const
QString left(int n) const
QString fromLatin1(const char *str, int size)
Contains the result of a single input parameter validation.
Diagnose
Single diagnose values that show why an address is not valid.
const QChar at(int position) const
~ValidatorEmail() override
Deconstructs the email validator.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int compare(const QString &other, Qt::CaseSensitivity cs) const
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.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const
bool isLetterOrNumber() const