summaryrefslogtreecommitdiff
path: root/kolabformat/kolabobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kolabformat/kolabobject.cpp')
-rw-r--r--kolabformat/kolabobject.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index b894818..90b4e78 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -51,6 +51,7 @@ static inline QString noteKolabType() { return QString::fromLatin1(KOLAB_TYPE_NO
static inline QString configurationKolabType() { return QString::fromLatin1(KOLAB_TYPE_CONFIGURATION); }
static inline QString dictKolabType() { return QString::fromLatin1(KOLAB_TYPE_DICT); }
static inline QString freebusyKolabType() { return QString::fromLatin1(KOLAB_TYPE_FREEBUSY); }
+static inline QString relationKolabType() { return QString::fromLatin1(KOLAB_TYPE_RELATION); }
static inline QString xCalMimeType() { return QString::fromLatin1(MIME_TYPE_XCAL); };
static inline QString xCardMimeType() { return QString::fromLatin1(MIME_TYPE_XCARD); };
@@ -61,6 +62,62 @@ KCalCore::Event::Ptr readV2EventXML(const QByteArray& xmlData, QStringList& atta
return fromXML<KCalCore::Event::Ptr, KolabV2::Event>(xmlData, attachments);
}
+RelationMember parseMemberUrl(const QString &string)
+{
+ RelationMember member;
+ QUrl url(QUrl::fromPercentEncoding(string.toLatin1()));
+ QList<QByteArray> path = url.encodedPath().split('/');
+ // qDebug() << path;
+ int start = path.indexOf("user");
+ if (start < 0) {
+ kWarning() << "Couldn't find \"user\" in path: " << path;
+ return RelationMember();
+ }
+ path = path.mid(start + 1);
+ if (path.size() < 2) {
+ kWarning() << "Incomplete path: " << path;
+ return RelationMember();
+ }
+ // user-name
+ path.removeFirst();
+ member.uid = path.takeLast().toLong();
+ member.mailbox = path;
+ member.messageId = url.queryItemValue("message-id");
+ member.subject = url.queryItemValue("subject");
+ member.date = url.queryItemValue("date");
+ // qDebug() << member.uid << member.mailbox;
+ return member;
+}
+
+static QByteArray join(const QList<QByteArray> &list, const QByteArray &c)
+{
+ QByteArray result;
+ Q_FOREACH (const QByteArray &a, list) {
+ result += a + c;
+ }
+ result.chop(c.size());
+ return result;
+}
+
+KOLAB_EXPORT QString generateMemberUrl(const RelationMember &member)
+{
+ QUrl url;
+ url.setScheme("imap");
+ QList<QByteArray> path;
+ path << "user";
+ path << "localuser@localhost";
+ path << member.mailbox;
+ path << QByteArray::number(member.uid);
+ url.setPath("/" + 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);
+
+ return QString::fromLatin1(url.toEncoded());
+}
//@cond PRIVATE
class KolabObjectReader::Private
@@ -87,6 +144,8 @@ public:
ObjectType mObjectType;
Version mVersion;
Kolab::Freebusy mFreebusy;
+ Akonadi::Tag mTag;
+ QStringList mTagMembers;
ObjectType mOverrideObjectType;
Version mOverrideVersion;
bool mDoOverrideVersion;
@@ -138,6 +197,8 @@ Kolab::ObjectType getObjectType(const QString &type)
return FreebusyObject;
} else if (type.contains(dictKolabType())) { //Previous versions appended the language to the type
return DictionaryConfigurationObject;
+ } else if (type == relationKolabType()) {
+ return RelationConfigurationObject;
}
Warning() << "Unknown object type: " << type;
return Kolab::InvalidObject;
@@ -162,6 +223,8 @@ QByteArray getTypeString(Kolab::ObjectType type)
return KOLAB_TYPE_NOTE;
case DictionaryConfigurationObject:
return KOLAB_TYPE_CONFIGURATION;
+ case RelationConfigurationObject:
+ return KOLAB_TYPE_RELATION;
default:
Critical() << "unknown type "<< type;
}
@@ -181,6 +244,7 @@ QByteArray getMimeType(Kolab::ObjectType type)
return MIME_TYPE_XCARD;
case NoteObject:
case DictionaryConfigurationObject:
+ case RelationConfigurationObject:
return MIME_TYPE_KOLAB;
default:
Critical() << "unknown type "<< type;
@@ -326,6 +390,22 @@ ObjectType KolabObjectReader::Private::readKolabV3(const KMime::Message::Ptr &ms
mFreebusy = fb;
}
break;
+ case RelationConfigurationObject: {
+ const Kolab::Configuration &configuration = Kolab::readConfiguration(xml, false);
+ const Kolab::Relation &relation = configuration.relation();
+
+ mTag = Akonadi::Tag();
+ mTag.setName(Conversion::fromStdString(relation.name()));
+ mTag.setGid(Conversion::fromStdString(configuration.uid()).toLatin1());
+ mTag.setType(Akonadi::Tag::PLAIN);
+
+ mTagMembers.reserve(relation.members().size());
+ foreach (const std::string &member, relation.members()) {
+ mTagMembers << Conversion::fromStdString(member);
+ }
+
+ }
+ break;
default:
Critical() << "no kolab object found ";
printMessageDebugInfo(msg);
@@ -452,6 +532,16 @@ Freebusy KolabObjectReader::getFreebusy() const
return d->mFreebusy;
}
+Akonadi::Tag KolabObjectReader::getTag() const
+{
+ return d->mTag;
+}
+
+QStringList KolabObjectReader::getTagMembers() const
+{
+ return d->mTagMembers;
+}
+
//Normalize incidences before serializing them
KCalCore::Incidence::Ptr normalizeIncidence(KCalCore::Incidence::Ptr original)
@@ -630,6 +720,28 @@ KMime::Message::Ptr KolabObjectWriter::writeFreebusy(const Freebusy &freebusy, V
return Mime::createMessage(Conversion::fromStdString(freebusy.uid()), xCalMimeType(), freebusyKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId));
}
+KMime::Message::Ptr KolabObjectWriter::writeTag(const Akonadi::Tag &tag, const QStringList &members, Version v, const QString &productId)
+{
+ ErrorHandler::clearErrors();
+ if (v != KolabV3) {
+ Critical() << "only v3 implementation available";
+ }
+
+ Kolab::Relation relation(Conversion::toStdString(tag.name()), "tag");
+ std::vector<std::string> m;
+ m.reserve(members.count());
+ foreach (const QString &member, members) {
+ m.push_back(Conversion::toStdString(member));
+ }
+ relation.setMembers(m);
+
+ Kolab::Configuration configuration(relation); //TODO preserve creation/lastModified date
+ configuration.setUid(tag.gid().constData());
+ const std::string &v3String = Kolab::writeConfiguration(configuration, Conversion::toStdString(getProductId(productId)));
+ ErrorHandler::handleLibkolabxmlErrors();
+ return Mime::createMessage(Conversion::fromStdString(configuration.uid()), kolabMimeType(), relationKolabType(), Conversion::fromStdString(v3String).toUtf8(), true, getProductId(productId));
+}
+