summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2014-10-29 21:22:24 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2014-10-29 21:22:24 (GMT)
commit7746f2d0e206074964660143626d92c438525461 (patch)
tree4a1b5c17da03d084c8336779d6ee049cff04534f
parent8b06c46eaaf70fc70af3abff8f7fbfa7f3116a19 (diff)
downloadlibkolab-7746f2d0e206074964660143626d92c438525461.tar.gz
Tag: support for gid members and shared folder members.
-rw-r--r--kolabformat/kolabobject.cpp30
-rw-r--r--kolabformat/kolabobject.h1
-rw-r--r--tests/kolabobjecttest.cpp38
3 files changed, 61 insertions, 8 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index 3cf3f86..cc50d9e 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -64,13 +64,22 @@ KCalCore::Event::Ptr readV2EventXML(const QByteArray& xmlData, QStringList& atta
RelationMember parseMemberUrl(const QString &string)
{
- RelationMember member;
+ if (string.startsWith("urn:uuid:")) {
+ RelationMember member;
+ member.gid = string.mid(9);
+ return member;
+ }
QUrl url(QUrl::fromPercentEncoding(string.toLatin1()));
QList<QByteArray> path = url.encodedPath().split('/');
// qDebug() << path;
+ bool isShared = false;
int start = path.indexOf("user");
if (start < 0) {
- Warning() << "Couldn't find \"user\" in path: " << path;
+ start = path.indexOf("shared");
+ isShared = true;
+ }
+ if (start < 0) {
+ Warning() << "Couldn't find \"user\" or \"shared\" in path: " << path;
return RelationMember();
}
path = path.mid(start + 1);
@@ -78,8 +87,10 @@ RelationMember parseMemberUrl(const QString &string)
Warning() << "Incomplete path: " << path;
return RelationMember();
}
- // user-name
- path.removeFirst();
+ RelationMember member;
+ if (!isShared) {
+ member.user = path.takeFirst();
+ }
member.uid = path.takeLast().toLong();
member.mailbox = path;
member.messageId = url.queryItemValue("message-id");
@@ -101,11 +112,18 @@ static QByteArray join(const QList<QByteArray> &list, const QByteArray &c)
KOLAB_EXPORT QString generateMemberUrl(const RelationMember &member)
{
+ if (!member.gid.isEmpty()) {
+ return QString("urn:uuid:%1").arg(member.gid);
+ }
QUrl url;
url.setScheme("imap");
QList<QByteArray> path;
- path << "user";
- path << "localuser@localhost";
+ if (!member.user.isEmpty()) {
+ path << "user";
+ path << member.user.toLatin1();
+ } else {
+ path << "shared";
+ }
path << member.mailbox;
path << QByteArray::number(member.uid);
url.setPath("/" + join(path, "/"));
diff --git a/kolabformat/kolabobject.h b/kolabformat/kolabobject.h
index 0b56fe8..dff7a6b 100644
--- a/kolabformat/kolabobject.h
+++ b/kolabformat/kolabobject.h
@@ -51,6 +51,7 @@ struct KOLAB_EXPORT RelationMember {
QList<QByteArray> mailbox;
QString user;
qint64 uid;
+ QString gid;
};
KOLAB_EXPORT RelationMember parseMemberUrl(const QString &url);
KOLAB_EXPORT QString generateMemberUrl(const RelationMember &url);
diff --git a/tests/kolabobjecttest.cpp b/tests/kolabobjecttest.cpp
index f57ce1d..cad5f47 100644
--- a/tests/kolabobjecttest.cpp
+++ b/tests/kolabobjecttest.cpp
@@ -83,15 +83,14 @@ 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&date=Tue%2C+12+Aug+2014+20%3A42%3A59+%2B0200&subject=Re%3A+test");
Kolab::RelationMember member = Kolab::parseMemberUrl(memberString);
-
const QString result = Kolab::generateMemberUrl(member);
qDebug() << result;
}
+ //user namespace by uid
{
Kolab::RelationMember member;
@@ -106,6 +105,41 @@ void KolabObjectTest::parseRelationMembers()
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);
+ }
+
+ //shared namespace by uid
+ {
+
+ Kolab::RelationMember member;
+ member.uid = 20;
+ member.mailbox = QList<QByteArray>() << "foo" << "bar";
+ 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);
+ QVERIFY(result.user.isEmpty());
+ QCOMPARE(result.messageId, member.messageId);
+ QCOMPARE(result.date, member.date);
+ QCOMPARE(result.subject, member.subject);
+ }
+
+ //by uuid/gid
+ {
+
+ Kolab::RelationMember member;
+ member.gid = "fooobar";
+ QString url = Kolab::generateMemberUrl(member);
+ qDebug() << url;
+ Kolab::RelationMember result = Kolab::parseMemberUrl(url);
+ QCOMPARE(result.gid, member.gid);
}
}