File indexing completed on 2025-02-16 04:50:28
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 "kolabdefinitions.h" 0010 0011 #include "kolabformat/errorhandler.h" 0012 #include "kolabformatV2/contact.h" 0013 #include "kolabformatV2/distributionlist.h" 0014 #include "kolabformatV2/event.h" 0015 #include "kolabformatV2/journal.h" 0016 #include "kolabformatV2/kolabbase.h" 0017 #include "kolabformatV2/note.h" 0018 #include "kolabformatV2/task.h" 0019 #include "mime/mimeutils.h" 0020 0021 #include <KCalendarCore/Incidence> 0022 #include <KContacts/Addressee> 0023 #include <KContacts/ContactGroup> 0024 #include <KMime/Message> 0025 0026 #include <Akonadi/NoteUtils> 0027 0028 #include <qdom.h> 0029 0030 namespace Kolab 0031 { 0032 /* 0033 * Parse XML, create KCalendarCore container and extract attachments 0034 */ 0035 template<typename KCalPtr, typename Container> 0036 static KCalPtr fromXML(const QByteArray &xmlData, QStringList &attachments) 0037 { 0038 const QDomDocument xmlDoc = KolabV2::KolabBase::loadDocument(QString::fromUtf8(xmlData)); // TODO extract function from V2 format 0039 if (xmlDoc.isNull()) { 0040 Critical() << "Failed to read the xml document"; 0041 return KCalPtr(); 0042 } 0043 const KCalPtr i = Container::fromXml(xmlDoc, QString()); // For parsing we don't need the timezone, so we don't set one 0044 Q_ASSERT(i); 0045 const QDomNodeList nodes = xmlDoc.elementsByTagName(QStringLiteral("inline-attachment")); 0046 for (int i = 0; i < nodes.size(); i++) { 0047 attachments.append(nodes.at(i).toElement().text()); 0048 } 0049 return i; 0050 } 0051 0052 void getAttachments(KCalendarCore::Incidence::Ptr incidence, const QStringList &attachments, const KMime::Message::Ptr &mimeData); 0053 0054 template<typename IncidencePtr, typename Converter> 0055 static inline IncidencePtr incidenceFromKolabImpl(const KMime::Message::Ptr &data, const QByteArray &mimetype, const QString &timezoneId) 0056 { 0057 Q_UNUSED(timezoneId) 0058 KMime::Content *xmlContent = Mime::findContentByType(data, mimetype); 0059 if (!xmlContent) { 0060 Critical() << "couldn't find part"; 0061 return IncidencePtr(); 0062 } 0063 const QByteArray &xmlData = xmlContent->decodedContent(); 0064 0065 QStringList attachments; 0066 IncidencePtr ptr = fromXML<IncidencePtr, Converter>(xmlData, attachments); // TODO do we care about timezone? 0067 getAttachments(ptr, attachments, data); 0068 0069 return ptr; 0070 } 0071 0072 KContacts::Addressee addresseeFromKolab(const QByteArray &xmlData, const KMime::Message::Ptr &data); 0073 KContacts::Addressee addresseeFromKolab(const QByteArray &xmlData, QString &pictureAttachmentName, QString &logoAttachmentName, QString &soundAttachmentName); 0074 0075 KMime::Message::Ptr contactToKolabFormat(const KolabV2::Contact &contact, const QString &productId); 0076 0077 KContacts::ContactGroup contactGroupFromKolab(const QByteArray &xmlData); 0078 0079 KMime::Message::Ptr distListToKolabFormat(const KolabV2::DistributionList &distList, const QString &productId); 0080 KMime::Message::Ptr noteFromKolab(const QByteArray &xmlData, const QDateTime &creationDate); 0081 0082 KMime::Message::Ptr noteToKolab(const KMime::Message::Ptr &msg, const QString &productId); 0083 QByteArray noteToKolabXML(const KMime::Message::Ptr &msg); 0084 0085 QStringList readLegacyDictionaryConfiguration(const QByteArray &xmlData, QString &language); 0086 }