Skip to content
GitLab
Menu
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
9e7fa689
Commit
9e7fa689
authored
Jan 02, 2020
by
Laurent Montel
😁
Browse files
Prepare porting to QRegularExpression
parent
7e06f49c
Changes
4
Hide whitespace changes
Inline
Side-by-side
mimetreeparser/autotests/nodehelpertest.cpp
View file @
9e7fa689
...
...
@@ -270,4 +270,19 @@ void NodeHelperTest::testFromAsString()
QCOMPARE
(
helper
.
fromAsString
(
encSubExtra
),
encSender
);
}
void
NodeHelperTest
::
shouldTestExtractAttachmentIndex_data
()
{
QTest
::
addColumn
<
QString
>
(
"path"
);
QTest
::
addColumn
<
QString
>
(
"extractedPath"
);
QTest
::
newRow
(
"empty"
)
<<
QString
()
<<
QString
();
}
void
NodeHelperTest
::
shouldTestExtractAttachmentIndex
()
{
QFETCH
(
QString
,
path
);
QFETCH
(
QString
,
extractedPath
);
NodeHelper
helper
;
QCOMPARE
(
extractedPath
,
helper
.
extractAttachmentIndex
(
path
));
}
QTEST_GUILESS_MAIN
(
NodeHelperTest
)
mimetreeparser/autotests/nodehelpertest.h
View file @
9e7fa689
...
...
@@ -37,6 +37,8 @@ private Q_SLOTS:
void
testHREF
();
void
testCreateTempDir
();
void
testFromAsString
();
void
shouldTestExtractAttachmentIndex_data
();
void
shouldTestExtractAttachmentIndex
();
};
}
#endif
mimetreeparser/src/nodehelper.cpp
View file @
9e7fa689
...
...
@@ -767,20 +767,29 @@ KMime::Content *NodeHelper::fromHREF(const KMime::Message::Ptr &mMessage, const
return
contentFromIndex
(
mMessage
.
data
(),
url
.
adjusted
(
QUrl
::
StripTrailingSlash
).
path
());
}
else
{
const
QString
path
=
url
.
toLocalFile
();
// extract from /<path>/qttestn28554.index.2.3:0:2/unnamed -> "2.3:0:2"
// start of the index is something that is not a number followed by a dot: \D.
// index is only made of numbers,"." and ":": ([0-9.:]+)
// index is the last part of the folder name: /
const
QRegExp
rIndex
(
QStringLiteral
(
"
\\
D
\\
.([e0-9.:]+)/"
));
//search the occurrence at most at the end
if
(
rIndex
.
lastIndexIn
(
path
)
!=
-
1
)
{
return
contentFromIndex
(
mMessage
.
data
(),
rIndex
.
cap
(
1
));
const
QString
extractedPath
=
extractAttachmentIndex
(
path
);
if
(
!
extractedPath
.
isEmpty
())
{
return
contentFromIndex
(
mMessage
.
data
(),
extractedPath
);
}
return
mMessage
.
data
();
}
}
QString
NodeHelper
::
extractAttachmentIndex
(
const
QString
&
path
)
const
{
// extract from /<path>/qttestn28554.index.2.3:0:2/unnamed -> "2.3:0:2"
// start of the index is something that is not a number followed by a dot: \D.
// index is only made of numbers,"." and ":": ([0-9.:]+)
// index is the last part of the folder name: /
const
QRegExp
rIndex
(
QStringLiteral
(
"
\\
D
\\
.([e0-9.:]+)/"
));
//search the occurrence at most at the end
if
(
rIndex
.
lastIndexIn
(
path
)
!=
-
1
)
{
return
rIndex
.
cap
(
1
);
}
return
QString
();
}
QString
NodeHelper
::
fixEncoding
(
const
QString
&
encoding
)
{
QString
returnEncoding
=
encoding
;
...
...
mimetreeparser/src/nodehelper.h
View file @
9e7fa689
...
...
@@ -229,6 +229,7 @@ public:
*/
QVector
<
KMime
::
Content
*>
attachmentsOfExtraContents
()
const
;
Q_REQUIRED_RESULT
QString
extractAttachmentIndex
(
const
QString
&
path
)
const
;
Q_SIGNALS:
void
update
(
MimeTreeParser
::
UpdateMode
);
...
...
Write
Preview
Supports
Markdown
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