Commit 9e7fa689 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Prepare porting to QRegularExpression

parent 7e06f49c
......@@ -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)
......@@ -37,6 +37,8 @@ private Q_SLOTS:
void testHREF();
void testCreateTempDir();
void testFromAsString();
void shouldTestExtractAttachmentIndex_data();
void shouldTestExtractAttachmentIndex();
};
}
#endif
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment