File indexing completed on 2024-11-24 04:44:13
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kolab_export.h" 0010 0011 #include <Akonadi/Item> 0012 #include <Akonadi/Relation> 0013 #include <Akonadi/Tag> 0014 #include <KCalendarCore/Event> 0015 #include <KCalendarCore/Incidence> 0016 #include <KCalendarCore/Journal> 0017 #include <KCalendarCore/Todo> 0018 #include <KContacts/Addressee> 0019 #include <KContacts/ContactGroup> 0020 #include <KMime/Message> 0021 0022 #include "kolabdefinitions.h" 0023 0024 #include <memory> 0025 0026 namespace Kolab 0027 { 0028 class Freebusy; 0029 0030 KOLAB_EXPORT KCalendarCore::Event::Ptr readV2EventXML(const QByteArray &xmlData, QStringList &attachments); 0031 0032 struct KOLAB_EXPORT RelationMember { 0033 QString messageId; 0034 QString subject; 0035 QString date; 0036 QList<QByteArray> mailbox; 0037 QString user; 0038 qint64 uid; 0039 QString gid; 0040 }; 0041 KOLAB_EXPORT RelationMember parseMemberUrl(const QString &url); 0042 KOLAB_EXPORT QString generateMemberUrl(const RelationMember &url); 0043 0044 class KolabObjectReaderPrivate; 0045 0046 /** 0047 * Class to read Kolab Mime files 0048 * 0049 * It implements the Kolab specifics of Mime message handling. 0050 * This class is not reusable and only meant to read a single object. 0051 * Parse the mime message and then call the correct getter, based on the type 0052 * 0053 */ 0054 class KOLAB_EXPORT KolabObjectReader 0055 { 0056 public: 0057 KolabObjectReader(); 0058 explicit KolabObjectReader(const KMime::Message::Ptr &msg); 0059 ~KolabObjectReader(); 0060 0061 ObjectType parseMimeMessage(const KMime::Message::Ptr &msg); 0062 0063 /** 0064 * Set to override the autodetected object type, before parsing the message. 0065 */ 0066 void setObjectType(ObjectType); 0067 0068 /** 0069 * Set to override the autodetected version, before parsing the message. 0070 */ 0071 void setVersion(Version); 0072 0073 /** 0074 * Returns the Object type of the parsed kolab object. 0075 */ 0076 ObjectType getType() const; 0077 /** 0078 * Returns the kolab-format version of the parsed kolab object. 0079 */ 0080 Version getVersion() const; 0081 0082 /** 0083 * Getter to get the retrieved object. 0084 * Only the correct one will return a valid object. 0085 * 0086 * Use getType() to determine the correct one to call. 0087 */ 0088 KCalendarCore::Event::Ptr getEvent() const; 0089 KCalendarCore::Todo::Ptr getTodo() const; 0090 KCalendarCore::Journal::Ptr getJournal() const; 0091 KCalendarCore::Incidence::Ptr getIncidence() const; 0092 KContacts::Addressee getContact() const; 0093 KContacts::ContactGroup getDistlist() const; 0094 KMime::Message::Ptr getNote() const; 0095 QStringList getDictionary(QString &lang) const; 0096 Freebusy getFreebusy() const; 0097 bool isTag() const; 0098 Akonadi::Tag getTag() const; 0099 QStringList getTagMembers() const; 0100 bool isRelation() const; 0101 Akonadi::Relation getRelation() const; 0102 0103 private: 0104 //@cond PRIVATE 0105 KolabObjectReader(const KolabObjectReader &other) = delete; 0106 KolabObjectReader &operator=(const KolabObjectReader &rhs) = delete; 0107 0108 private: 0109 std::unique_ptr<KolabObjectReaderPrivate> const d; 0110 //@endcond 0111 }; 0112 0113 /** 0114 * Class to write Kolab Mime files 0115 * 0116 */ 0117 class KOLAB_EXPORT KolabObjectWriter 0118 { 0119 public: 0120 static KMime::Message::Ptr 0121 writeEvent(const KCalendarCore::Event::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString()); 0122 static KMime::Message::Ptr 0123 writeTodo(const KCalendarCore::Todo::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString()); 0124 static KMime::Message::Ptr 0125 writeJournal(const KCalendarCore::Journal::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString()); 0126 static KMime::Message::Ptr 0127 writeIncidence(const KCalendarCore::Incidence::Ptr &, Version v = KolabV3, const QString &productId = QString(), const QString &tz = QString()); 0128 static KMime::Message::Ptr writeContact(const KContacts::Addressee &, Version v = KolabV3, const QString &productId = QString()); 0129 static KMime::Message::Ptr writeDistlist(const KContacts::ContactGroup &, Version v = KolabV3, const QString &productId = QString()); 0130 static KMime::Message::Ptr writeNote(const KMime::Message::Ptr &, Version v = KolabV3, const QString &productId = QString()); 0131 static KMime::Message::Ptr writeDictionary(const QStringList &, const QString &lang, Version v = KolabV3, const QString &productId = QString()); 0132 static KMime::Message::Ptr writeFreebusy(const Kolab::Freebusy &, Version v = KolabV3, const QString &productId = QString()); 0133 static KMime::Message::Ptr writeTag(const Akonadi::Tag &, const QStringList &items, Version v = KolabV3, const QString &productId = QString()); 0134 static KMime::Message::Ptr writeRelation(const Akonadi::Relation &, const QStringList &items, Version v = KolabV3, const QString &productId = QString()); 0135 }; 0136 } // Namespace