summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <mail@sandroknauss.de>2014-12-10 12:40:02 (GMT)
committerSandro Knauß <mail@sandroknauss.de>2014-12-10 13:18:21 (GMT)
commitf0f953aaa3ede43be087a72e492e5aef3d354499 (patch)
tree783a760718132a02839d804d2422f639c934cb6b
parent23a0111c45e9f441c5e27ef9bf5b83c47fde98f5 (diff)
downloadlibkolab-dev/fix_memberurl.tar.gz
Make memberUrls compatible to documentation.dev/fix_memberurl
We have to work around QUrl, because QUrl has at least lacks about some features of url encoding ("+" - sign) and or de/encoding "@", ","... KOLAB: #4052
-rw-r--r--kolabformat/kolabobject.cpp38
-rw-r--r--tests/kolabobjecttest.cpp28
2 files changed, 51 insertions, 15 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 569a882..e417b65 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -62,6 +62,12 @@ KCalCore::Event::Ptr readV2EventXML(const QByteArray& xmlData, QStringList& atta
return fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
}
+QString ownUrlDecode(QByteArray encodedParam)
+{
+ encodedParam.replace('+', ' ');
+ return QUrl::fromPercentEncoding(encodedParam);
+}
+
RelationMember parseMemberUrl(const QString &string)
{
if (string.startsWith("urn:uuid:")) {
@@ -69,8 +75,11 @@ RelationMember parseMemberUrl(const QString &string)
member.gid = string.mid(9);
return member;
}
- QUrl url(QUrl::fromPercentEncoding(string.toLatin1()));
- QList<QByteArray> path = url.encodedPath().split('/');
+ QUrl url(QUrl::fromEncoded(string.toLatin1()));
+ QList<QByteArray> path;
+ Q_FOREACH(const QByteArray &fragment, url.encodedPath().split('/')) {
+ path.append(ownUrlDecode(fragment).toUtf8());
+ }
// qDebug() << path;
bool isShared = false;
int start = path.indexOf("user");
@@ -93,9 +102,9 @@ RelationMember parseMemberUrl(const QString &string)
}
member.uid = path.takeLast().toLong();
member.mailbox = path;
- member.messageId = url.queryItemValue("message-id");
- member.subject = url.queryItemValue("subject");
- member.date = url.queryItemValue("date");
+ member.messageId = ownUrlDecode(url.encodedQueryItemValue("message-id"));
+ member.subject = ownUrlDecode(url.encodedQueryItemValue("subject"));
+ member.date = ownUrlDecode(url.encodedQueryItemValue("date"));
// qDebug() << member.uid << member.mailbox;
return member;
}
@@ -118,21 +127,24 @@ KOLAB_EXPORT QString generateMemberUrl(const RelationMember &member)
QUrl url;
url.setScheme("imap");
QList<QByteArray> path;
+ path << "/";
if (!member.user.isEmpty()) {
path << "user";
- path << member.user.toLatin1();
+ path << QUrl::toPercentEncoding(member.user.toLatin1());
} else {
path << "shared";
}
- path << member.mailbox;
+ Q_FOREACH(const QByteArray &mb, member.mailbox) {
+ path << QUrl::toPercentEncoding(mb);
+ }
path << QByteArray::number(member.uid);
- url.setPath("/" + join(path, "/"));
+ url.setEncodedPath("/" + join(path, "/"));
- QList<QPair<QString, QString> > queryItems;
- queryItems.append(qMakePair(QString::fromLatin1("message-id"), member.messageId));
- queryItems.append(qMakePair(QString::fromLatin1("subject"), member.subject));
- queryItems.append(qMakePair(QString::fromLatin1("date"), member.date));
- url.setQueryItems(queryItems);
+ QList<QPair<QByteArray, QByteArray> > queryItems;
+ queryItems.append(qMakePair(QString::fromLatin1("message-id").toLatin1(), QUrl::toPercentEncoding(member.messageId)));
+ queryItems.append(qMakePair(QString::fromLatin1("subject").toLatin1(), QUrl::toPercentEncoding(member.subject)));
+ queryItems.append(qMakePair(QString::fromLatin1("date").toLatin1(), QUrl::toPercentEncoding(member.date)));
+ url.setEncodedQueryItems(queryItems);
return QString::fromLatin1(url.toEncoded());
}
diff --git a/tests/kolabobjecttest.cpp b/tests/kolabobjecttest.cpp
index cad5f47..5840760 100644
--- a/tests/kolabobjecttest.cpp
+++ b/tests/kolabobjecttest.cpp
@@ -83,11 +83,13 @@ void KolabObjectTest::dontCrashWithEmptyIncidence()
void KolabObjectTest::parseRelationMembers()
{
{
- QString memberString("imap:///user/jan.aachen%40lhm.klab.cc/INBOX/20?message-id=%3Cf06aa3345a25005380b47547ad161d36%40lhm.klab.cc%3E&date=Tue%2C+12+Aug+2014+20%3A42%3A59+%2B0200&subject=Re%3A+test");
+ QString memberString("imap:///user/jan.aachen%40lhm.klab.cc/INBOX/20?message-id=%3Cf06aa3345a25005380b47547ad161d36%40lhm.klab.cc%3E&subject=Re%3A+test&date=Tue%2C+12+Aug+2014+20%3A42%3A59+%2B0200");
Kolab::RelationMember member = Kolab::parseMemberUrl(memberString);
- const QString result = Kolab::generateMemberUrl(member);
+ QString result = Kolab::generateMemberUrl(member);
qDebug() << result;
+ result.replace(QLatin1String("%20"),QLatin1String("+"));
+ QCOMPARE(result, memberString);
}
//user namespace by uid
@@ -141,6 +143,28 @@ void KolabObjectTest::parseRelationMembers()
Kolab::RelationMember result = Kolab::parseMemberUrl(url);
QCOMPARE(result.gid, member.gid);
}
+
+ // chars to en/decode
+ {
+
+ Kolab::RelationMember member;
+ member.uid = 20;
+ member.mailbox = QList<QByteArray>() << "spaces in folders" << "+^,:@";
+ member.user = "john.doe:^@example.org";
+ member.messageId = "messageid+^,:@";
+ member.date = "date+^,:@";
+ member.subject = "subject+^,:@";
+
+ QString url = Kolab::generateMemberUrl(member);
+ qDebug() << url;
+ Kolab::RelationMember result = Kolab::parseMemberUrl(url);
+ QCOMPARE(result.uid, member.uid);
+ QCOMPARE(result.mailbox, member.mailbox);
+ QCOMPARE(result.user, member.user);
+ QCOMPARE(result.messageId, member.messageId);
+ QCOMPARE(result.date, member.date);
+ QCOMPARE(result.subject, member.subject);
+ }
}