Changeset View
Changeset View
Standalone View
Standalone View
kolabformat/mimeobject.cpp
Show All 23 Lines | |||||
#include "kolabformat/kolabobject.h" | #include "kolabformat/kolabobject.h" | ||||
#include "kolabformat/xmlobject.h" | #include "kolabformat/xmlobject.h" | ||||
#include "kolabformat/errorhandler.h" | #include "kolabformat/errorhandler.h" | ||||
#include "kolabformat/v2helpers.h" | #include "kolabformat/v2helpers.h" | ||||
#include "mime/mimeutils.h" | #include "mime/mimeutils.h" | ||||
#include "libkolab-version.h" | #include "libkolab-version.h" | ||||
#include <QString> | #include <QString> | ||||
#include <QtGlobal> | #include <QtGlobal> | ||||
#include <KRandom> | |||||
#include <boost/algorithm/string/predicate.hpp> | #include <boost/algorithm/string/predicate.hpp> | ||||
Q_DECLARE_METATYPE(Kolab::Event); | Q_DECLARE_METATYPE(Kolab::Event); | ||||
Q_DECLARE_METATYPE(Kolab::Todo); | Q_DECLARE_METATYPE(Kolab::Todo); | ||||
Q_DECLARE_METATYPE(Kolab::Journal); | Q_DECLARE_METATYPE(Kolab::Journal); | ||||
Q_DECLARE_METATYPE(Kolab::Contact); | Q_DECLARE_METATYPE(Kolab::Contact); | ||||
Q_DECLARE_METATYPE(Kolab::DistList); | Q_DECLARE_METATYPE(Kolab::DistList); | ||||
▲ Show 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | QVariant MIMEObject::Private::parseMimeMessage(const KMime::Message::Ptr &msg) | ||||
mObjectType = InvalidObject; | mObjectType = InvalidObject; | ||||
if (msg->contents().isEmpty()) { | if (msg->contents().isEmpty()) { | ||||
Critical() << "message has no contents (we likely failed to parse it correctly)"; | Critical() << "message has no contents (we likely failed to parse it correctly)"; | ||||
printMessageDebugInfo(msg); | printMessageDebugInfo(msg); | ||||
return QVariant(); | return QVariant(); | ||||
} | } | ||||
Kolab::ObjectType objectType = InvalidObject; | Kolab::ObjectType objectType = InvalidObject; | ||||
if (mOverrideObjectType == InvalidObject) { | if (mOverrideObjectType == InvalidObject) { | ||||
if (KMime::Headers::Base *xKolabHeader = msg->getHeaderByType(X_KOLAB_TYPE_HEADER)) { | if (KMime::Headers::Base *xKolabHeader = msg->headerByType(X_KOLAB_TYPE_HEADER)) { | ||||
objectType = getObjectType(xKolabHeader->asUnicodeString().trimmed().toStdString()); | objectType = getObjectType(xKolabHeader->asUnicodeString().trimmed().toStdString()); | ||||
} else { | } else { | ||||
Warning() << "could not find the X-Kolab-Type Header, trying autodetection" ; | Warning() << "could not find the X-Kolab-Type Header, trying autodetection" ; | ||||
//This works only for v2 messages atm. | //This works only for v2 messages atm. | ||||
objectType = detectType(msg); | objectType = detectType(msg); | ||||
} | } | ||||
} else { | } else { | ||||
objectType = mOverrideObjectType; | objectType = mOverrideObjectType; | ||||
} | } | ||||
if (objectType == InvalidObject) { | if (objectType == InvalidObject) { | ||||
Critical() << "unable to detect object type"; | Critical() << "unable to detect object type"; | ||||
printMessageDebugInfo(msg); | printMessageDebugInfo(msg); | ||||
return QVariant(); | return QVariant(); | ||||
} | } | ||||
if (!mDoOverrideVersion) { | if (!mDoOverrideVersion) { | ||||
KMime::Headers::Base *xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER); | KMime::Headers::Base *xKolabVersion = msg->headerByType(X_KOLAB_MIME_VERSION_HEADER); | ||||
if (!xKolabVersion) { | if (!xKolabVersion) { | ||||
//For backwards compatibility to development versions, can be removed in future versions | //For backwards compatibility to development versions, can be removed in future versions | ||||
xKolabVersion = msg->getHeaderByType(X_KOLAB_MIME_VERSION_HEADER_COMPAT); | xKolabVersion = msg->headerByType(X_KOLAB_MIME_VERSION_HEADER_COMPAT); | ||||
} | } | ||||
if (!xKolabVersion || xKolabVersion->asUnicodeString() == KOLAB_VERSION_V2) { | if (!xKolabVersion || xKolabVersion->asUnicodeString() == KOLAB_VERSION_V2) { | ||||
mVersion = KolabV2; | mVersion = KolabV2; | ||||
} else { | } else { | ||||
if (xKolabVersion->asUnicodeString() != KOLAB_VERSION_V3) { //TODO version compatibility check? | if (xKolabVersion->asUnicodeString() != KOLAB_VERSION_V3) { //TODO version compatibility check? | ||||
Warning() << "Kolab Version Header available but not on the same version as the implementation: " << xKolabVersion->asUnicodeString(); | Warning() << "Kolab Version Header available but not on the same version as the implementation: " << xKolabVersion->asUnicodeString(); | ||||
} | } | ||||
mVersion = KolabV3; | mVersion = KolabV3; | ||||
Show All 30 Lines | |||||
void MIMEObject::setVersion(Version version) | void MIMEObject::setVersion(Version version) | ||||
{ | { | ||||
d->mOverrideVersion = version; | d->mOverrideVersion = version; | ||||
d->mDoOverrideVersion = true; | d->mDoOverrideVersion = true; | ||||
} | } | ||||
static std::string createCid() | static std::string createCid() | ||||
{ | { | ||||
return QString::fromLatin1("cid:%1@%2").arg(QString::fromLatin1(KMime::uniqueString())).arg("kolab.resource.akonadi").toStdString(); | return QString::fromLatin1("cid:%1@%2").arg(KRandom::randomString(16)).arg("kolab.resource.akonadi").toStdString(); | ||||
} | } | ||||
std::vector<Kolab::Attachment> convertToReferences(const std::vector<Kolab::Attachment> &attachments, std::vector<std::string> &attachmentCids) | std::vector<Kolab::Attachment> convertToReferences(const std::vector<Kolab::Attachment> &attachments, std::vector<std::string> &attachmentCids) | ||||
{ | { | ||||
std::vector<Kolab::Attachment> attachmentsWithReferences; | std::vector<Kolab::Attachment> attachmentsWithReferences; | ||||
Q_FOREACH (const Kolab::Attachment &a, attachments) { | Q_FOREACH (const Kolab::Attachment &a, attachments) { | ||||
Kolab::Attachment attachment; | Kolab::Attachment attachment; | ||||
attachment.setLabel(a.label()); | attachment.setLabel(a.label()); | ||||
▲ Show 20 Lines • Show All 302 Lines • Show Last 20 Lines |