Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PIM
PIM MailCommon
Commits
ec6e61ab
Commit
ec6e61ab
authored
Aug 02, 2020
by
Ahmad Samir
Committed by
Volker Krause
Aug 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port QRegExp to QRegularExpression
parent
761bf1df
Pipeline
#30997
passed with stage
in 59 minutes and 11 seconds
Changes
6
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
33 deletions
+33
-33
src/filter/filteractions/filteractionrewriteheader.cpp
src/filter/filteractions/filteractionrewriteheader.cpp
+7
-7
src/filter/filteractions/filteractionrewriteheader.h
src/filter/filteractions/filteractionrewriteheader.h
+2
-2
src/filter/filteractions/filteractionwithcommand.cpp
src/filter/filteractions/filteractionwithcommand.cpp
+15
-12
src/search/searchrule/searchrulenumerical.cpp
src/search/searchrule/searchrulenumerical.cpp
+3
-5
src/search/searchrule/searchrulestring.cpp
src/search/searchrule/searchrulestring.cpp
+3
-5
src/snippets/snippetsmanager.cpp
src/snippets/snippetsmanager.cpp
+3
-2
No files found.
src/filter/filteractions/filteractionrewriteheader.cpp
View file @
ec6e61ab
...
...
@@ -37,7 +37,7 @@ FilterActionRewriteHeader::FilterActionRewriteHeader(QObject *parent)
bool
FilterActionRewriteHeader
::
isEmpty
()
const
{
return
mParameter
.
isEmpty
()
||
mReg
Exp
.
isEmpty
();
return
mParameter
.
isEmpty
()
||
mReg
ex
.
pattern
()
.
isEmpty
();
}
QString
FilterActionRewriteHeader
::
informationAboutNotValidAction
()
const
...
...
@@ -46,7 +46,7 @@ QString FilterActionRewriteHeader::informationAboutNotValidAction() const
if
(
mParameter
.
isEmpty
())
{
info
=
i18n
(
"Header not defined"
);
}
if
(
mReg
Exp
.
isEmpty
())
{
if
(
mReg
ex
.
pattern
()
.
isEmpty
())
{
if
(
!
info
.
isEmpty
())
{
info
+=
QLatin1Char
(
'\n'
);
}
...
...
@@ -71,7 +71,7 @@ FilterAction::ReturnCode FilterActionRewriteHeader::process(ItemContext &context
QString
value
=
header
->
asUnicodeString
();
const
QString
oldValue
=
value
;
const
QString
newValue
=
value
.
replace
(
mReg
Exp
,
mReplacementString
);
const
QString
newValue
=
value
.
replace
(
mReg
ex
,
mReplacementString
);
if
(
newValue
!=
oldValue
)
{
msg
->
removeHeader
(
param
.
constData
());
...
...
@@ -161,7 +161,7 @@ void FilterActionRewriteHeader::setParamWidgetValue(QWidget *paramWidget) const
KLineEdit
*
regExpLineEdit
=
paramWidget
->
findChild
<
KLineEdit
*>
(
QStringLiteral
(
"search"
));
Q_ASSERT
(
regExpLineEdit
);
regExpLineEdit
->
setText
(
mReg
Exp
.
pattern
());
regExpLineEdit
->
setText
(
mReg
ex
.
pattern
());
KLineEdit
*
lineEdit
=
paramWidget
->
findChild
<
KLineEdit
*>
(
QStringLiteral
(
"replace"
));
Q_ASSERT
(
lineEdit
);
...
...
@@ -176,7 +176,7 @@ void FilterActionRewriteHeader::applyParamWidgetValue(QWidget *paramWidget)
const
KLineEdit
*
regExpLineEdit
=
paramWidget
->
findChild
<
KLineEdit
*>
(
QStringLiteral
(
"search"
));
Q_ASSERT
(
regExpLineEdit
);
mReg
Exp
.
setPattern
(
regExpLineEdit
->
text
());
mReg
ex
.
setPattern
(
regExpLineEdit
->
text
());
const
KLineEdit
*
lineEdit
=
paramWidget
->
findChild
<
KLineEdit
*>
(
QStringLiteral
(
"replace"
));
Q_ASSERT
(
lineEdit
);
...
...
@@ -202,7 +202,7 @@ QString FilterActionRewriteHeader::argsAsString() const
{
QString
result
=
mParameter
;
result
+=
QLatin1Char
(
'\t'
);
result
+=
mReg
Exp
.
pattern
();
result
+=
mReg
ex
.
pattern
();
result
+=
QLatin1Char
(
'\t'
);
result
+=
mReplacementString
;
...
...
@@ -223,7 +223,7 @@ void FilterActionRewriteHeader::argsFromString(const QString &argsStr)
QString
result
;
result
=
list
[
0
];
mReg
Exp
.
setPattern
(
list
[
1
]);
mReg
ex
.
setPattern
(
list
[
1
]);
mReplacementString
=
list
[
2
];
int
index
=
mParameterList
.
indexOf
(
result
);
...
...
src/filter/filteractions/filteractionrewriteheader.h
View file @
ec6e61ab
...
...
@@ -10,7 +10,7 @@
#include "filteractionwithstringlist.h"
#include <QReg
Exp
>
#include <QReg
ularExpression
>
namespace
MailCommon
{
//=============================================================================
...
...
@@ -40,7 +40,7 @@ public:
Q_REQUIRED_RESULT
QString
informationAboutNotValidAction
()
const
override
;
private:
QReg
Exp
mReg
Exp
;
QReg
ularExpression
mReg
ex
;
QString
mReplacementString
;
};
}
...
...
src/filter/filteractions/filteractionwithcommand.cpp
View file @
ec6e61ab
...
...
@@ -9,6 +9,8 @@
#include "mailcommon_debug.h"
#include <KProcess>
#include <KShell>
#include <QRegularExpression>
#include <QTemporaryFile>
using
namespace
MailCommon
;
...
...
@@ -59,16 +61,14 @@ QString FilterActionWithCommand::substituteCommandLineArgsFor(const KMime::Messa
{
QString
result
=
mParameter
;
QList
<
int
>
argList
;
QRegExp
r
(
QStringLiteral
(
"%[0-9-]+"
));
const
QRegularExpression
r
e
(
QStringLiteral
(
"%
(
[0-9-]+
)
"
));
// search for '%n'
int
start
=
-
1
;
while
((
start
=
r
.
indexIn
(
result
,
start
+
1
))
>
0
)
{
const
int
len
=
r
.
matchedLength
();
QRegularExpressionMatchIterator
iter
=
re
.
globalMatch
(
result
);
while
(
iter
.
hasNext
())
{
// and save the encountered 'n' in a list.
bool
ok
=
false
;
const
int
n
=
result
.
midRef
(
start
+
1
,
len
-
1
).
toInt
(
&
ok
);
const
int
n
=
iter
.
next
().
captured
(
1
).
toInt
(
&
ok
);
if
(
ok
)
{
argList
.
append
(
n
);
}
...
...
@@ -139,16 +139,19 @@ void substituteMessageHeaders(const KMime::Message::Ptr &aMsg, QString &result)
{
// Replace the %{foo} with the content of the foo header field.
// If the header doesn't exist, remove the placeholder.
QRegExp
header_rx
(
QStringLiteral
(
"%
\\
{([a-z0-9-]+)
\\
}"
),
Qt
::
CaseInsensitive
);
int
idx
=
0
;
while
((
idx
=
header_rx
.
indexIn
(
result
,
idx
))
!=
-
1
)
{
const
KMime
::
Headers
::
Base
*
header
=
aMsg
->
headerByType
(
header_rx
.
cap
(
1
).
toLatin1
().
constData
());
const
QRegularExpression
header_rx
(
QStringLiteral
(
"%
\\
{([a-z0-9-]+)
\\
}"
),
QRegularExpression
::
CaseInsensitiveOption
);
int
offset
=
0
;
QRegularExpressionMatch
rmatch
;
while
(
result
.
indexOf
(
header_rx
,
offset
,
&
rmatch
)
!=
-
1
)
{
const
KMime
::
Headers
::
Base
*
header
=
aMsg
->
headerByType
(
rmatch
.
captured
(
1
).
toLatin1
().
constData
());
QString
replacement
;
if
(
header
)
{
replacement
=
KShell
::
quoteArg
(
QString
::
fromLatin1
(
header
->
as7BitString
()));
}
result
.
replace
(
idx
,
header_rx
.
matchedLength
(),
replacement
);
idx
+=
replacement
.
length
();
const
int
start
=
rmatch
.
capturedStart
(
0
);
result
.
replace
(
start
,
rmatch
.
capturedLength
(
0
),
replacement
);
offset
=
start
+
replacement
.
size
();
}
}
...
...
src/search/searchrule/searchrulenumerical.cpp
View file @
ec6e61ab
...
...
@@ -12,7 +12,7 @@ using MailCommon::FilterLog;
#include <QDateTime>
#include <KMime/KMimeMessage>
#include <QReg
Exp
>
#include <QReg
ularExpression
>
#include <algorithm>
...
...
@@ -88,14 +88,12 @@ bool SearchRuleNumerical::matchesInternal(long numericalValue, long numericalMsg
case
SearchRule
::
FuncRegExp
:
{
QRegExp
regexp
(
contents
(),
Qt
::
CaseInsensitive
);
return
regexp
.
indexIn
(
msgContents
)
>=
0
;
return
msgContents
.
contains
(
QRegularExpression
(
contents
(),
QRegularExpression
::
CaseInsensitiveOption
));
}
case
SearchRule
::
FuncNotRegExp
:
{
QRegExp
regexp
(
contents
(),
Qt
::
CaseInsensitive
);
return
regexp
.
indexIn
(
msgContents
)
<
0
;
return
!
msgContents
.
contains
(
QRegularExpression
(
contents
(),
QRegularExpression
::
CaseInsensitiveOption
));
}
case
FuncIsGreater
:
...
...
src/search/searchrule/searchrulestring.cpp
View file @
ec6e61ab
...
...
@@ -18,7 +18,7 @@ using MailCommon::FilterLog;
#include <KLocalizedString>
#include <QReg
Exp
>
#include <QReg
ularExpression
>
#include <algorithm>
#include <boost/bind.hpp>
...
...
@@ -259,14 +259,12 @@ bool SearchRuleString::matchesInternal(const QString &msgContents) const
case
SearchRule
::
FuncRegExp
:
{
QRegExp
regexp
(
contents
(),
Qt
::
CaseInsensitive
);
return
regexp
.
indexIn
(
msgContents
)
>=
0
;
return
msgContents
.
contains
(
QRegularExpression
(
contents
(),
QRegularExpression
::
CaseInsensitiveOption
));
}
case
SearchRule
::
FuncNotRegExp
:
{
QRegExp
regexp
(
contents
(),
Qt
::
CaseInsensitive
);
return
regexp
.
indexIn
(
msgContents
)
<
0
;
return
!
msgContents
.
contains
(
QRegularExpression
(
contents
(),
QRegularExpression
::
CaseInsensitiveOption
));
}
case
SearchRule
::
FuncStartWith
:
...
...
src/snippets/snippetsmanager.cpp
View file @
ec6e61ab
...
...
@@ -24,6 +24,7 @@
#include <QAction>
#include <QPointer>
#include <QItemSelectionModel>
#include <QRegularExpression>
using
namespace
MailCommon
;
...
...
@@ -435,8 +436,8 @@ QString SnippetsManager::Private::replaceVariables(const QString &text)
int
iEnd
=
-
1
;
QMap
<
QString
,
QString
>
tempLocalVariables
(
localVariables
);
do
{
//find the next variable by this
QRegExp
iFound
=
text
.
indexOf
(
QReg
Exp
(
QLatin1String
(
"
\\
$[A-Za-z-_0-9
\\
s]*
\\
$"
)),
iEnd
+
1
);
//find the next variable by this
regex
iFound
=
text
.
indexOf
(
QReg
ularExpression
(
QStringLiteral
(
"
\\
$[A-Za-z
\\
-_0-9
\\
s]*
\\
$"
)),
iEnd
+
1
);
if
(
iFound
>=
0
)
{
iEnd
=
text
.
indexOf
(
QLatin1Char
(
'$'
),
iFound
+
1
)
+
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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