Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Messagelib
Commits
db6faabd
Commit
db6faabd
authored
Oct 10, 2022
by
Laurent Montel
Browse files
Port some code to QRegularExpression
parent
d9bd248d
Pipeline
#245098
passed with stage
in 32 minutes
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
messagecomposer/src/composer-ng/richtextcomposersignatures.cpp
View file @
db6faabd
...
...
@@ -8,7 +8,7 @@
#include
"richtextcomposerng.h"
#include
<KIdentityManagement/Signature>
#include
<QRegExp>
#include
<QTextBlock>
using
namespace
MessageComposer
;
...
...
messageviewer/src/antispam/antispamconfig.cpp
View file @
db6faabd
...
...
@@ -59,7 +59,7 @@ void AntiSpamConfig::readConfig()
}
else
if
(
qstricmp
(
type
.
data
(),
"adjusted"
)
==
0
)
{
typeE
=
SpamAgentAdjustedFloat
;
}
mAgents
.
append
(
SpamAgent
(
name
,
typeE
,
header
,
cheader
,
QReg
Exp
(
score
),
QRegExp
(
threshold
),
QReg
Exp
(
confidence
)));
mAgents
.
append
(
SpamAgent
(
name
,
typeE
,
header
,
cheader
,
QReg
ularExpression
(
score
),
QRegularExpression
(
threshold
),
QReg
ularExpression
(
confidence
)));
}
}
}
...
...
messageviewer/src/antispam/antispamconfig.h
View file @
db6faabd
...
...
@@ -10,8 +10,7 @@
#pragma once
#include
"messageviewer_export.h"
#include
<QRegExp>
#include
<QRegularExpression>
#include
<QVector>
class
QString
;
...
...
@@ -39,9 +38,9 @@ public:
SpamAgentTypes
type
,
const
QByteArray
&
field
,
const
QByteArray
&
cfield
,
const
QReg
Exp
&
score
,
const
QReg
Exp
&
threshold
,
const
QReg
Exp
&
confidence
)
const
QReg
ularExpression
&
score
,
const
QReg
ularExpression
&
threshold
,
const
QReg
ularExpression
&
confidence
)
:
mName
(
name
)
,
mType
(
type
)
,
mField
(
field
)
...
...
@@ -72,17 +71,17 @@ public:
return
mConfidenceField
;
}
Q_REQUIRED_RESULT
QReg
Exp
scorePattern
()
const
Q_REQUIRED_RESULT
QReg
ularExpression
scorePattern
()
const
{
return
mScore
;
}
Q_REQUIRED_RESULT
QReg
Exp
thresholdPattern
()
const
Q_REQUIRED_RESULT
QReg
ularExpression
thresholdPattern
()
const
{
return
mThreshold
;
}
Q_REQUIRED_RESULT
QReg
Exp
confidencePattern
()
const
Q_REQUIRED_RESULT
QReg
ularExpression
confidencePattern
()
const
{
return
mConfidence
;
}
...
...
@@ -92,9 +91,9 @@ private:
SpamAgentTypes
mType
;
QByteArray
mField
;
QByteArray
mConfidenceField
;
QReg
Exp
mScore
;
QReg
Exp
mThreshold
;
QReg
Exp
mConfidence
;
QReg
ularExpression
mScore
;
QReg
ularExpression
mThreshold
;
QReg
ularExpression
mConfidence
;
};
using
SpamAgents
=
QVector
<
SpamAgent
>
;
...
...
messageviewer/src/antispam/spamheaderanalyzer.cpp
View file @
db6faabd
...
...
@@ -15,6 +15,8 @@
#include
<KMime/Headers>
#include
<KMime/KMimeMessage>
#include
<QRegularExpression>
using
namespace
MessageViewer
;
// static
...
...
@@ -50,9 +52,9 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
if
((
*
it
).
scoreType
()
!=
SpamAgentBool
)
{
// Can we extract the score?
QReg
Exp
scorePattern
=
(
*
it
).
scorePattern
();
if
(
scorePattern
.
indexIn
(
mField
)
!=
-
1
)
{
scoreString
=
scorePattern
.
cap
(
1
);
QReg
ularExpression
scorePattern
=
(
*
it
).
scorePattern
();
if
(
scorePattern
.
match
(
mField
)
.
hasMatch
()
)
{
scoreString
=
scorePattern
.
match
(
mField
).
captured
(
1
);
scoreValid
=
true
;
}
}
else
{
...
...
@@ -70,7 +72,7 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
break
;
case
SpamAgentBool
:
if
((
*
it
).
scorePattern
().
indexIn
(
mField
)
==
-
1
)
{
if
((
*
it
).
scorePattern
().
match
(
mField
)
.
hasMatch
()
)
{
score
=
0.0
;
}
else
{
score
=
100.0
;
...
...
@@ -105,9 +107,9 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
// Find the threshold value.
QString
thresholdString
;
const
QReg
Exp
thresholdPattern
=
(
*
it
).
thresholdPattern
();
if
(
thresholdPattern
.
indexIn
(
mField
)
!=
-
1
)
{
thresholdString
=
thresholdPattern
.
cap
(
1
);
const
QReg
ularExpression
thresholdPattern
=
(
*
it
).
thresholdPattern
();
if
(
thresholdPattern
.
match
(
mField
)
.
hasMatch
()
)
{
thresholdString
=
thresholdPattern
.
match
(
mField
).
captured
(
1
);
}
else
{
spamError
=
couldNotFindTheThresholdField
;
qCDebug
(
MESSAGEVIEWER_LOG
)
<<
"Threshold could not be extracted from header '"
<<
mField
<<
"'"
;
...
...
@@ -147,9 +149,9 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
mCField
=
cHeader
->
asUnicodeString
();
if
(
!
mCField
.
isEmpty
())
{
// Can we extract the confidence?
QReg
Exp
cScorePattern
=
(
*
it
).
confidencePattern
();
if
(
cScorePattern
.
indexIn
(
mCField
)
!=
-
1
)
{
confidenceString
=
cScorePattern
.
cap
(
1
);
QReg
ularExpression
cScorePattern
=
(
*
it
).
confidencePattern
();
if
(
cScorePattern
.
match
(
mCField
)
.
hasMatch
()
)
{
confidenceString
=
cScorePattern
.
match
(
mCField
).
captured
(
1
);
}
confidence
=
confidenceString
.
toFloat
(
&
confidenceValid
);
if
(
!
confidenceValid
)
{
...
...
messageviewer/src/messagepartthemes/default/autotests/util.cpp
View file @
db6faabd
...
...
@@ -4,9 +4,9 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include
"util.h"
#include
<QFile>
#include
<QProcess>
#include
<QRegularExpression>
#include
<QTest>
using
namespace
MessageViewer
;
KMime
::
Message
::
Ptr
Test
::
readAndParseMail
(
const
QString
&
mailFile
)
...
...
@@ -33,11 +33,11 @@ void Test::compareFile(const QString &outFile, const QString &referenceFile)
QVERIFY
(
f
.
open
(
QIODevice
::
ReadOnly
));
QString
content
=
QString
::
fromUtf8
(
f
.
readAll
());
f
.
close
();
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"[
\t
]+"
)),
QStringLiteral
(
" "
));
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"[
\t
]*
\n
+[
\t
]*"
)),
QStringLiteral
(
"
\n
"
));
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"([
\n\t
])
\\
1+"
)),
QStringLiteral
(
"
\\
1"
));
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
">
\n
+[
\t
]*"
)),
QStringLiteral
(
">"
));
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"[
\t
]*
\n
+[
\t
]*<"
)),
QStringLiteral
(
"<"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"[
\t
]+"
)),
QStringLiteral
(
" "
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"[
\t
]*
\n
+[
\t
]*"
)),
QStringLiteral
(
"
\n
"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"([
\n\t
])
\\
1+"
)),
QStringLiteral
(
"
\\
1"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
">
\n
+[
\t
]*"
)),
QStringLiteral
(
">"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"[
\t
]*
\n
+[
\t
]*<"
)),
QStringLiteral
(
"<"
));
content
.
replace
(
QLatin1String
(
" "
),
QLatin1String
(
"NBSP_ENTITY_PLACEHOLDER"
));
// xmlling chokes on
QVERIFY
(
f
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Truncate
));
f
.
write
(
content
.
toUtf8
());
...
...
@@ -56,8 +56,8 @@ void Test::compareFile(const QString &outFile, const QString &referenceFile)
QVERIFY
(
f
.
open
(
QIODevice
::
ReadOnly
));
QString
content
=
QString
::
fromUtf8
(
f
.
readAll
());
f
.
close
();
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"
\"
file:[^
\"
]*[/(?:%2F)]([^
\"
/(?:%2F)]*)
\"
"
)),
QStringLiteral
(
"
\"
file:
\\
1
\"
"
));
content
.
replace
(
QReg
Exp
(
QStringLiteral
(
"(file:///tmp/messageviewer)(_[^
\"
]+)(
\\
.index
\\
.[^
\"
]*)"
)),
QStringLiteral
(
"
\\
1
\\
3"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"
\"
file:[^
\"
]*[/(?:%2F)]([^
\"
/(?:%2F)]*)
\"
"
)),
QStringLiteral
(
"
\"
file:
\\
1
\"
"
));
content
.
replace
(
QReg
ularExpression
(
QStringLiteral
(
"(file:///tmp/messageviewer)(_[^
\"
]+)(
\\
.index
\\
.[^
\"
]*)"
)),
QStringLiteral
(
"
\\
1
\\
3"
));
content
.
replace
(
QLatin1String
(
"NBSP_ENTITY_PLACEHOLDER"
),
QLatin1String
(
" "
));
// undo above transformation for xmllint
QVERIFY
(
f
.
open
(
QIODevice
::
WriteOnly
|
QIODevice
::
Truncate
));
f
.
write
(
content
.
toUtf8
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment