Commit 51828453 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Simplify code

parent 9bbbec3b
......@@ -414,6 +414,20 @@ void StringUtilTest::test_parseMailToWithUtf8Encoded()
}
void StringUtilTest::test_parseMailToWithUtf8QuotedEncoded()
{
const QByteArray ba("mailto:=?utf-8?q?foo_Cen_=3Cbla=2Ecete=40kde=2Ecom=3E=2C_Kile_Debut_=3Ckile=2Edebut=40foo=2Ecom?=");
QUrl url = QUrl(QUrl::fromPercentEncoding(ba));
QVector<QPair<QString, QString> > data = StringUtil::parseMailtoUrl(url);
QCOMPARE(data.size(), 1);
for (int i = 0; i < 1; ++i) {
if (data.at(i).first == QLatin1String("to")) {
QCOMPARE(data.at(i).second, QString::fromUtf8("foo Cen <bla.cete@kde.com>, Kile Debut <kile.debut@foo.com"));
}
}
}
void StringUtilTest::test_parseMailToBug366981()
{
const QString ba(QStringLiteral("mailto:test@test.com?subject=test&body=line1%0D%0Aline2"));
......
......@@ -43,6 +43,7 @@ private Q_SLOTS:
void test_parseMAilToBug402378();
void test_parseMailToBug406208();
void test_parseMailToWithUtf8Encoded();
void test_parseMailToWithUtf8QuotedEncoded();
};
#endif
......@@ -40,7 +40,7 @@
#include <QStringList>
#include <QUrlQuery>
#include <kpimtextedit/textutils.h>
#include <KCodecs>
using namespace KMime;
using namespace KMime::Types;
using namespace KMime::HeaderParsing;
......@@ -182,27 +182,10 @@ QVector<QPair<QString, QString> > parseMailtoUrl(const QUrl &url)
QString toStr;
int i = 0;
//Convert =?utf-8?B...?=
const QString utf8CharsetPrefix = QStringLiteral("=?utf-8?B?");
int indexUtf8 = str.indexOf(utf8CharsetPrefix);
bool utf8EncodingStrFound = false;
while (indexUtf8 != 1) {
const int indexEndEncoding = str.indexOf(QStringLiteral("?="));
if (indexEndEncoding == -1) {
break;
}
const QString encodedStr = str.mid(indexUtf8 + utf8CharsetPrefix.size(), indexEndEncoding - indexUtf8 - utf8CharsetPrefix.size());
const QByteArray ba = QByteArray::fromBase64(encodedStr.toLatin1(), QByteArray::Base64UrlEncoding);
const QString decodedStr = QString::fromUtf8(ba);
// +2 as "?="
str.replace(indexUtf8, indexEndEncoding + 2 -indexUtf8, decodedStr);
indexUtf8 = str.indexOf(utf8CharsetPrefix);
utf8EncodingStrFound = true;
}
QUrl newUrl = url;
if (utf8EncodingStrFound) {
newUrl = QUrl::fromUserInput(str);
}
//String can be encoded.
str = KCodecs::decodeRFC2047String(str);
const QUrl newUrl = QUrl::fromUserInput(str);
int indexTo = -1;
//Workaround line with # see bug 406208
......
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