Messagelib

dkimauthenticationstatusinfoutil.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
3 
4  Code based on ARHParser.jsm from dkim_verifier (Copyright (c) Philippe Lieser)
5  (This software is licensed under the terms of the MIT License.)
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "dkimauthenticationstatusinfoutil.h"
11 
12 /*
13 // domain-name as specified in Section 3.5 of RFC 6376 [DKIM].
14 let domain_name_p = "(?:" + sub_domain_p + "(?:\\." + sub_domain_p + ")+)";
15 */
16 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::wsp_p()
17 {
18  // WSP as specified in Appendix B.1 of RFC 5234
19  return QStringLiteral("[ \t]");
20 }
21 
22 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::vchar_p()
23 {
24  // VCHAR as specified in Appendix B.1 of RFC 5234
25  return QStringLiteral("[!-~]");
26 }
27 
28 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::letDig_p()
29 {
30  // Let-dig as specified in Section 4.1.2 of RFC 5321 [SMTP].
31  return QStringLiteral("[A-Za-z0-9]");
32 }
33 
34 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::ldhStr_p()
35 {
36  // Ldh-str as specified in Section 4.1.2 of RFC 5321 [SMTP].
37  return QStringLiteral("(?:[A-Za-z0-9-]*%1)").arg(DKIMAuthenticationStatusInfoUtil::letDig_p());
38 }
39 
40 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::keyword_p()
41 {
42  // "Keyword" as specified in Section 4.1.2 of RFC 5321 [SMTP].
43  return DKIMAuthenticationStatusInfoUtil::ldhStr_p();
44 }
45 
46 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::subDomain_p()
47 {
48  // sub-domain as specified in Section 4.1.2 of RFC 5321 [SMTP].
49  return QStringLiteral("(?:%1%2?)").arg(DKIMAuthenticationStatusInfoUtil::letDig_p(), DKIMAuthenticationStatusInfoUtil::ldhStr_p());
50 }
51 
52 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::obsFws_p()
53 {
54  // obs-FWS as specified in Section 4.2 of RFC 5322
55  return QStringLiteral("(?:%1+(?:\r\n%1+)*)").arg(DKIMAuthenticationStatusInfoUtil::wsp_p());
56 }
57 
58 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::quotedPair_p()
59 {
60  // quoted-pair as specified in Section 3.2.1 of RFC 5322
61  // Note: obs-qp is not included, so this pattern matches less then specified!
62  return QStringLiteral("(?:\\\\(?:%1|%2))").arg(vchar_p(), wsp_p());
63 }
64 
65 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::fws_p()
66 {
67  // FWS as specified in Section 3.2.2 of RFC 5322
68  return QStringLiteral("(?:(?:(?:%1*\r\n)?%1+)|%2)").arg(wsp_p(), obsFws_p());
69 }
70 
71 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::fws_op()
72 {
73  return QStringLiteral("%1?").arg(fws_p());
74 }
75 
76 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::ctext_p()
77 {
78  // ctext as specified in Section 3.2.2 of RFC 5322
79  return QStringLiteral("[!-'*-[\\]-~]");
80 }
81 
82 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::ccontent_p()
83 {
84  // ccontent as specified in Section 3.2.2 of RFC 5322
85  // Note: comment is not included, so this pattern matches less then specified!
86  return QStringLiteral("(?:%1|%2)").arg(ctext_p(), quotedPair_p());
87 }
88 
89 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::comment_p()
90 {
91  // comment as specified in Section 3.2.2 of RFC 5322
92  return QStringLiteral("\\((?:%1%2)*%1\\)").arg(fws_op(), ccontent_p());
93 }
94 
95 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::cfws_p()
96 {
97  // CFWS as specified in Section 3.2.2 of RFC 5322 [MAIL]
98  return QStringLiteral("(?:(?:(?:%1%2)+%1)|%3)").arg(fws_op(), comment_p(), fws_p());
99 }
100 
101 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::cfws_op()
102 {
103  return QStringLiteral("%1?").arg(cfws_p());
104 }
105 
106 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::atext()
107 {
108  // atext as specified in Section 3.2.3 of RFC 5322
109  return QStringLiteral("[!#-'*-+/-9=?A-Z^-~-]");
110 }
111 
112 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::dotAtomText_p()
113 {
114  // dot-atom-text as specified in Section 3.2.3 of RFC 5322
115  return QStringLiteral("(?:%1+(?:\\.%1+)*)").arg(atext());
116 }
117 
118 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::dotAtom_p()
119 {
120  // dot-atom as specified in Section 3.2.3 of RFC 5322
121  // dot-atom = [CFWS] dot-atom-text [CFWS]
122  return QStringLiteral("(?:%1%2%1)").arg(cfws_op(), dotAtomText_p());
123 }
124 
125 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::qtext_p()
126 {
127  // qtext as specified in Section 3.2.4 of RFC 5322
128  // Note: obs-qtext is not included, so this pattern matches less then specified!
129  return QStringLiteral("[!#-[\\]-~]");
130 }
131 
132 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::qcontent_p()
133 {
134  // qcontent as specified in Section 3.2.4 of RFC 5322
135  return QStringLiteral("(?:%1|%2)").arg(qtext_p(), quotedPair_p());
136 }
137 
138 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::quotedString_p()
139 {
140  // quoted-string as specified in Section 3.2.4 of RFC 5322
141  return QStringLiteral("(?:%1\"(?:%2%3)*%2\"%1)").arg(cfws_op(), fws_op(), qcontent_p());
142 }
143 
144 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::quotedString_cp()
145 {
146  return QStringLiteral("(?:%1\"((?:%2%3)*)%2\"%1)").arg(cfws_op(), fws_op(), qcontent_p());
147 }
148 
149 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::localPart_p()
150 {
151  // local-part as specified in Section 3.4.1 of RFC 5322
152  // Note: obs-local-part is not included, so this pattern matches less then specified!
153  return QStringLiteral("(?:%1|%2))").arg(dotAtom_p(), quotedString_p());
154 }
155 
156 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::token_p()
157 {
158  // token as specified in Section 5.1 of RFC 2045.
159  return QStringLiteral("[^ \\x00-\\x1F\\x7F()<>@,;:\\\\\"/[\\]?=]+");
160 }
161 
162 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::value_p()
163 {
164  // "value" as specified in Section 5.1 of RFC 2045.
165  return QStringLiteral("(?:%1|%2)").arg(token_p(), quotedString_p());
166 }
167 
168 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::value_cp()
169 {
170  return QStringLiteral("(?:(%1)|%2)").arg(token_p(), quotedString_cp());
171 }
172 
173 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::domainName_p()
174 {
175  // domain-name as specified in Section 3.5 of RFC 6376 [DKIM].
176  return QStringLiteral("(?:%1(?:\\.%1)+)").arg(subDomain_p());
177 }
178 
179 // Tries to matches a pattern to the beginning of str.
180 // Adds CFWS_op to the beginning of pattern.
181 // pattern must be followed by string end, ";" or CFWS_p.
182 // If match is found, removes it from str.
183 QString MessageViewer::DKIMAuthenticationStatusInfoUtil::regexMatchO(const QString &regularExpressionStr)
184 {
185  const QString regexp = (QLatin1Char('^') + DKIMAuthenticationStatusInfoUtil::cfws_op() + QStringLiteral("(?:") + regularExpressionStr + QLatin1Char(')')
186  + QStringLiteral("(?:(?:") + DKIMAuthenticationStatusInfoUtil::cfws_op() + QStringLiteral("\r\n$)|(?=;)|(?=")
187  + DKIMAuthenticationStatusInfoUtil::cfws_p() + QStringLiteral("))"));
188  return regexp;
189 }
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 23:05:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.