summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-25 15:06:30 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-25 15:06:30 (GMT)
commitd10bfa66e27b927c0eddfb63e914dd7233e6e44e (patch)
treef74d81fca4b3617ff5584deeab604820b777ed6f
parent11e85473757e4eb380a26ba82f92850a72b4e3bb (diff)
downloadkolab-utils-d10bfa66e27b927c0eddfb63e914dd7233e6e44e.tar.gz
Contacts work, todos almost.
-rw-r--r--migrationutility/sourceaccount.cpp43
-rw-r--r--migrationutility/tests/exchangeimaptest.cpp87
2 files changed, 124 insertions, 6 deletions
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index bfa4096..ff987bd 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -26,6 +26,7 @@
#include <kimap/namespacejob.h>
#include <kolab/errorhandler.h>
#include <kolab/kolabobject.h>
+#include <kabc/vcardconverter.h>
#include <kcalcore/memorycalendar.h>
#include <kcalcore/icalformat.h>
@@ -225,12 +226,16 @@ ExchangeIMAPSourceAccount::ExchangeIMAPSourceAccount(KIMAP::Session* session, QO
QPair<Kolab::ObjectType, KMime::Content*> ExchangeIMAPSourceAccount::getObjectType(const KMime::Message::Ptr &msg)
{
QByteArray calendarType("text/calendar");
+ QByteArray vcardType("text/vcard");
Q_FOREACH(KMime::Content *c, msg->contents()) {
Debug() << c->contentType()->mimeType();
- if (c->contentType()->mimeType() == calendarType) {
+ if (c->contentType()->mimeType() == calendarType) {
//TODO maybe distinguish between todos, events, etc
return QPair<Kolab::ObjectType, KMime::Content*>(Kolab::EventObject, c);
}
+ if (c->contentType()->mimeType() == vcardType) {
+ return QPair<Kolab::ObjectType, KMime::Content*>(Kolab::ContactObject, c);
+ }
}
return QPair<Kolab::ObjectType, KMime::Content*>(Kolab::InvalidObject, 0);
}
@@ -246,6 +251,9 @@ Kolab::FolderType ExchangeIMAPSourceAccount::getFolderType(const QString &folder
if (type == Kolab::EventObject) {
return Kolab::EventType;
}
+ if (type == Kolab::ContactObject) {
+ return Kolab::ContactType;
+ }
}
return Kolab::MailType;
}
@@ -291,7 +299,38 @@ QList<Object> ExchangeIMAPSourceAccount::getObjects(const QString& folder)
}
messages.append(obj);
}
- }
+ } else if (type.first == Kolab::TodoObject) {
+ const QByteArray content = type.second->decodedContent();
+ Debug() << "Found todo object: " << content;
+ KCalCore::ICalFormat format;
+ KCalCore::MemoryCalendar::Ptr calendar(new KCalCore::MemoryCalendar(KDateTime::Spec::UTC()));
+ format.fromRawString(calendar, content);
+
+ foreach (const KCalCore::Todo::Ptr &event, calendar->todos()) {
+ Object obj;
+ obj.message = Kolab::KolabObjectWriter::writeTodo(event, Kolab::KolabV3, "kolab-migration");
+ obj.flags = fetchJob->getFlags(msg);
+ if (!obj.message) {
+ Error() << "got empty message";
+ continue;
+ }
+ messages.append(obj);
+ }
+ } else if (type.first == Kolab::ContactObject) {
+ const QByteArray content = type.second->decodedContent();
+ Debug() << "Found contact object: " << content;
+ KABC::VCardConverter format;
+ const KABC::Addressee addressee = format.parseVCard(content);
+
+ Object obj;
+ obj.message = Kolab::KolabObjectWriter::writeContact(addressee, Kolab::KolabV3, "kolab-migration");
+ obj.flags = fetchJob->getFlags(msg);
+ if (!obj.message) {
+ Error() << "got empty message";
+ continue;
+ }
+ messages.append(obj);
+ }
}
return messages;
diff --git a/migrationutility/tests/exchangeimaptest.cpp b/migrationutility/tests/exchangeimaptest.cpp
index 44fd097..33d8012 100644
--- a/migrationutility/tests/exchangeimaptest.cpp
+++ b/migrationutility/tests/exchangeimaptest.cpp
@@ -19,6 +19,7 @@
#include <QTest>
#include <QDebug>
#include <kolabobject.h>
+#include <kabc/vcardconverter.h>
#include <kcalcore/memorycalendar.h>
#include <kcalcore/icalformat.h>
#include "migrationutility/coordinationjob.h"
@@ -82,6 +83,73 @@ class ExchangeIMAPTest: public QObject
return QPair<Object,Object>(calObj1, targetObject);
}
+
+ QPair<Object, Object> createTodo(const QString &uid)
+ {
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->userAgent()->from7BitString( "exchangeimaptest" );
+ msg->contentType()->setMimeType( "multipart/mixed" );
+ msg->contentType()->setBoundary( KMime::multiPartBoundary() );
+
+ KMime::Content* content = new KMime::Content();
+ content->contentType()->setMimeType( "text/calendar" );
+ content->contentTransferEncoding()->setEncoding( KMime::Headers::CEbase64 );
+ content->contentDisposition()->setDisposition( KMime::Headers::CDattachment );
+ KCalCore::Todo::Ptr event(new KCalCore::Todo());
+ event->setUid(uid);
+ event->setDtStart(KDateTime::currentUtcDateTime());
+ KCalCore::ICalFormat format;
+ KCalCore::MemoryCalendar::Ptr calendar(new KCalCore::MemoryCalendar(KDateTime::Spec::UTC()));
+ calendar->addTodo(event);
+ QByteArray decodedContent = format.toString(calendar, QString(), false).toLatin1();
+ content->setBody( decodedContent );
+
+ msg->addContent(content);
+ msg->assemble();
+
+ Object calObj1;
+ calObj1.message = msg;
+ calObj1.flags << QByteArray("\\Seen");
+
+ Object targetObject;
+ targetObject.message = Kolab::KolabObjectWriter::writeTodo(event);
+ targetObject.flags << QByteArray("\\Seen");
+ return QPair<Object,Object>(calObj1, targetObject);
+
+ }
+
+ QPair<Object, Object> createContact(const QString &name)
+ {
+
+ KABC::Addressee addressee;
+ addressee.setNameFromString(name);
+
+ KMime::Message::Ptr msg(new KMime::Message);
+ msg->userAgent()->from7BitString( "exchangeimaptest" );
+ msg->contentType()->setMimeType( "multipart/mixed" );
+ msg->contentType()->setBoundary( KMime::multiPartBoundary() );
+
+ KMime::Content* content = new KMime::Content();
+ content->contentType()->setMimeType( "text/vcard" );
+ content->contentTransferEncoding()->setEncoding( KMime::Headers::CEbase64 );
+ content->contentDisposition()->setDisposition( KMime::Headers::CDattachment );
+ KABC::VCardConverter converter;
+ QByteArray decodedContent = converter.createVCard(addressee);
+ content->setBody( decodedContent );
+
+ msg->addContent(content);
+ msg->assemble();
+
+ Object calObj1;
+ calObj1.message = msg;
+ calObj1.flags << QByteArray("\\Seen");
+
+ Object targetObject;
+ targetObject.message = Kolab::KolabObjectWriter::writeContact(addressee);
+ targetObject.flags << QByteArray("\\Seen");
+ return QPair<Object,Object>(calObj1, targetObject);
+
+ }
public:
explicit ExchangeIMAPTest(QObject* parent = 0)
@@ -95,7 +163,8 @@ public:
{
folders << Folder("INBOX");
folders << Folder("Calendar", Kolab::MailType, QList<Object>() << createEvent("uid1").first);
- folders << Folder("Contacts", Kolab::MailType);
+ folders << Folder("Tasks", Kolab::MailType, QList<Object>() << createTodo("uid2").first);
+ folders << Folder("Contacts", Kolab::MailType, QList<Object>() << createContact("John Doe").first);
folders << Folder("Drafts");
folders << Folder("Sent");
folders << Folder("Trash");
@@ -104,12 +173,12 @@ public:
targetFolders << Folder("Calendar", Kolab::EventType, QList<Object>() << createEvent("uid1").second);
// targetFolders << Folder("Calendar/Personal Calendar", Kolab::EventType, QList<Object>() << createEvent("uid2"));
targetFolders << Folder("Configuration", Kolab::ConfigurationType);
- targetFolders << Folder("Contacts", Kolab::ContactType);
+ targetFolders << Folder("Contacts", Kolab::ContactType, QList<Object>() << createContact("John Doe").second);
targetFolders << Folder("Drafts");
targetFolders << Folder("Journal", Kolab::JournalType);
targetFolders << Folder("Notes", Kolab::NoteType);
targetFolders << Folder("Sent");
- targetFolders << Folder("Tasks", Kolab::TaskType);
+ targetFolders << Folder("Tasks", Kolab::TaskType, QList<Object>() << createTodo("uid2").second);
targetFolders << Folder("Trash");
}
@@ -166,7 +235,17 @@ private:
QList<Object>::const_iterator recObjIt = objects.constBegin();
QList<Object>::const_iterator objIt = foldersIt->objects.constBegin();
for (;objIt != foldersIt->objects.constEnd() && recObjIt != objects.constEnd(); ++objIt, ++recObjIt) {
- QCOMPARE(*Kolab::KolabObjectReader(recObjIt->message).getEvent(), *Kolab::KolabObjectReader(objIt->message).getEvent());
+ Kolab::KolabObjectReader reader(objIt->message);
+ Kolab::ObjectType type = reader.getType();
+ if (type == Kolab::EventObject) {
+ QCOMPARE(*Kolab::KolabObjectReader(recObjIt->message).getEvent(), *Kolab::KolabObjectReader(objIt->message).getEvent());
+ } else if (type == Kolab::TodoObject) {
+ QCOMPARE(*Kolab::KolabObjectReader(recObjIt->message).getTodo(), *Kolab::KolabObjectReader(objIt->message).getTodo());
+ } else if (type == Kolab::ContactObject) {
+ QCOMPARE(Kolab::KolabObjectReader(recObjIt->message).getContact().name(), Kolab::KolabObjectReader(objIt->message).getContact().name());
+ } else {
+// QCOMPARE(Kolab::KolabObjectReader(recObjIt->message).getEvent(), *Kolab::KolabObjectReader(objIt->message).getEvent());
+ }
foreach (const QByteArray &flag, objIt->flags) {
QVERIFY(recObjIt->flags.contains(flag));
}