summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-08-15 12:04:46 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-08-15 12:04:46 (GMT)
commitb123e0604c7d6f9caab245006cc9f18d34af6210 (patch)
tree15cb1737276b0c36e13c0e5565a810751173bfe5
parent896aaff79bdb118a811bc5614a3dac867fadc813 (diff)
downloadlibkolab-libkolab-0.3.1.tar.gz
Autodetect type based on mimetype as fallback for v2 messages lacking the Kolab-Type header.libkolab-0.3.1encoding
-rw-r--r--kolabformat/kolabobject.cpp26
-rw-r--r--mime/mimeutils.cpp11
-rw-r--r--mime/mimeutils.h4
3 files changed, 30 insertions, 11 deletions
diff --git a/kolabformat/kolabobject.cpp b/kolabformat/kolabobject.cpp
index fc97715..a8b1404 100644
--- a/kolabformat/kolabobject.cpp
+++ b/kolabformat/kolabobject.cpp
@@ -188,6 +188,17 @@ QByteArray getMimeType(Kolab::ObjectType type)
return QByteArray();
}
+Kolab::ObjectType detectType(const KMime::Message::Ptr &msg)
+{
+ Q_FOREACH(const QByteArray &type, Mime::getContentMimeTypeList(msg)) {
+ Kolab::ObjectType t = getObjectType(type); //works for v2 types
+ if (t != InvalidObject) {
+ return t;
+ }
+ }
+ return InvalidObject;
+}
+
void printMessageDebugInfo(const KMime::Message::Ptr &msg)
{
//TODO replace by Debug stream for Mimemessage
@@ -342,19 +353,18 @@ ObjectType KolabObjectReader::parseMimeMessage(const KMime::Message::Ptr &msg)
}
Kolab::ObjectType objectType = InvalidObject;
if (d->mOverrideObjectType == InvalidObject) {
- KMime::Headers::Base *xKolabHeader = msg->getHeaderByType(X_KOLAB_TYPE_HEADER);
- if (!xKolabHeader) {
- CRITICAL("could not find the X-Kolab-Type Header");
- printMessageDebugInfo(msg);
- return InvalidObject;
+ if (KMime::Headers::Base *xKolabHeader = msg->getHeaderByType(X_KOLAB_TYPE_HEADER)) {
+ objectType = getObjectType(xKolabHeader->asUnicodeString().trimmed());
+ } else {
+ Warning() << "could not find the X-Kolab-Type Header, trying autodetection" ;
+ //This works only for v2 messages atm.
+ objectType = detectType(msg);
}
- const QString &kolabType = xKolabHeader->asUnicodeString().trimmed();
- objectType = getObjectType(kolabType);
} else {
objectType = d->mOverrideObjectType;
}
if (objectType == InvalidObject) {
- Warning() << "invalid object type";
+ Critical() << "unable to detect object type";
printMessageDebugInfo(msg);
return InvalidObject;
}
diff --git a/mime/mimeutils.cpp b/mime/mimeutils.cpp
index f51e498..a8259d3 100644
--- a/mime/mimeutils.cpp
+++ b/mime/mimeutils.cpp
@@ -75,6 +75,17 @@ KMime::Content* findContentById(const KMime::Message::Ptr &data, const QByteArra
return 0;
}
+QList<QByteArray> getContentMimeTypeList(const KMime::Message::Ptr& data)
+{
+ QList<QByteArray> typeList;
+ Q_ASSERT(!data->contents().isEmpty());
+ Q_FOREACH(KMime::Content *c, data->contents()) {
+ typeList.append(c->contentType()->mimeType());
+ }
+ return typeList;
+}
+
+
QByteArray getXmlDocument(const KMime::Message::Ptr &data, const QByteArray &mimetype)
{
diff --git a/mime/mimeutils.h b/mime/mimeutils.h
index 428cbcf..9d42ac4 100644
--- a/mime/mimeutils.h
+++ b/mime/mimeutils.h
@@ -29,12 +29,10 @@ class QDomDocument;
namespace Kolab {
namespace Mime {
-//TODO Generic
KMime::Content* findContentByName(const KMime::Message::Ptr &data, const QString &name, QByteArray &type);
-//TODO Generic
KMime::Content* findContentByType(const KMime::Message::Ptr &data, const QByteArray &type);
+QList<QByteArray> getContentMimeTypeList(const KMime::Message::Ptr &data);
-//TODO Generic
QByteArray getXmlDocument(const KMime::Message::Ptr &data, const QByteArray &mimetype);
/**