summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-09-27 22:07:05 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-09-27 22:07:05 (GMT)
commitc4387c90885b98ea93e78ab40d3ebd0b68a4c22c (patch)
tree599e68555a197237bdf387d64e6d0fbf350c4f8a
parent28b63970538c1e4bb8f801604aeb2bd47cd668db (diff)
downloadkolab-utils-c4387c90885b98ea93e78ab40d3ebd0b68a4c22c.tar.gz
Kolab objects are migrated, mails and special mail folders are still a TODO
-rw-r--r--jobs/setupkolabfoldersjob.cpp27
-rw-r--r--migrationutility/kolabaccount.cpp16
-rw-r--r--migrationutility/kolabaccount.h1
-rw-r--r--migrationutility/migrateuserjob.cpp1
-rw-r--r--migrationutility/sourceaccount.cpp41
-rw-r--r--migrationutility/sourceaccount.h1
6 files changed, 51 insertions, 36 deletions
diff --git a/jobs/setupkolabfoldersjob.cpp b/jobs/setupkolabfoldersjob.cpp
index b38d981..3eded47 100644
--- a/jobs/setupkolabfoldersjob.cpp
+++ b/jobs/setupkolabfoldersjob.cpp
@@ -21,8 +21,8 @@
#include <kimap/selectjob.h>
#include <kimap/setmetadatajob.h>
#include <QStringList>
-#include <kdebug.h>
+#include <kolab/errorhandler.h>
#include <kolab/kolabdefinitions.h>
#include <kolab/formathelpers.h>
@@ -60,7 +60,7 @@ void SetupKolabFoldersJob::start()
void SetupKolabFoldersJob::onSelectDone(KJob *job)
{
if ( job->error() ) {
- kWarning() << job->errorString();
+ Warning() << job->errorString();
setError(KJob::UserDefinedError);
emitResult();
return;
@@ -75,8 +75,15 @@ void SetupKolabFoldersJob::createMailbox()
return;
}
m_currentFolderType = m_folderTypes.takeFirst();
+ Kolab::FolderType folderType = Kolab::folderTypeFromString(m_currentFolderType.toStdString());
+ if (folderType == Kolab::MailType) {
+ Warning() << "unknown kolab type: " << m_currentFolderType;
+ setError(KJob::UserDefinedError);
+ emitResult();
+ return;
+ }
KIMAP::CreateJob *createJob = new KIMAP::CreateJob(m_session);
- createJob->setMailBox(QString::fromStdString(Kolab::nameForFolderType(Kolab::FreebusyType)));
+ createJob->setMailBox(QString::fromStdString(Kolab::nameForFolderType(folderType)));
connect(createJob, SIGNAL(result(KJob*)), this, SLOT(onCreateDone(KJob*)));
createJob->start();
}
@@ -84,29 +91,27 @@ void SetupKolabFoldersJob::createMailbox()
void SetupKolabFoldersJob::onCreateDone(KJob *job)
{
if ( job->error() ) {
- kWarning() << job->errorString() << job->error();
+ Warning() << job->errorString() << job->error();
setError(KJob::UserDefinedError);
createMailbox();
//TODO also check metadata in case this fails because the folder is already existing but doesn't contain the annotation
return;
}
KIMAP::CreateJob *createJob = static_cast<KIMAP::CreateJob*>(job);
- kDebug() << "Created folder " << m_rootFolder << createJob->mailBox();
+ Debug() << "Created folder " << m_rootFolder << createJob->mailBox();
m_createdFolders.insert(m_currentFolderType, createJob->mailBox());
KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(m_session);
setMetadataJob->setMailBox(createJob->mailBox());
- const QByteArray folderType = QByteArray(KOLAB_FOLDER_TYPE_FREEBUSY);
+ Kolab::FolderType folderType = Kolab::folderTypeFromString(m_currentFolderType.toStdString());
if ( m_serverCapabilities.contains( "METADATA" ) ) {
setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
- setMetadataJob->addMetaData( KOLAB_FOLDER_TYPE_ANNOTATION, QString::fromStdString(Kolab::folderAnnotation(Kolab::FreebusyType, true)).toLatin1() );
-
-// setMetadataJob->addMetaData(QByteArray("/shared" KOLAB_FOLDER_TYPE_ANNOTATION), folderType);
+ setMetadataJob->addMetaData( KOLAB_FOLDER_TYPE_ANNOTATION, QString::fromStdString(Kolab::folderAnnotation(folderType, true)).toLatin1() );
} else {
setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
- setMetadataJob->addMetaData( "value.shared", KOLAB_FOLDER_TYPE_FREEBUSY );
+ setMetadataJob->addMetaData( "value.shared", m_currentFolderType.toLatin1() );
}
connect(setMetadataJob, SIGNAL(result(KJob*)), this, SLOT(onMetadataSetDone(KJob*)));
setMetadataJob->start();
@@ -115,7 +120,7 @@ void SetupKolabFoldersJob::onCreateDone(KJob *job)
void SetupKolabFoldersJob::onMetadataSetDone(KJob *job)
{
if ( job->error() ) {
- kWarning() << job->errorString();
+ Warning() << job->errorString();
setError(KJob::UserDefinedError);
}
createMailbox();
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
index 9f6a235..88326ff 100644
--- a/migrationutility/kolabaccount.cpp
+++ b/migrationutility/kolabaccount.cpp
@@ -17,6 +17,7 @@
#include "kolabaccount.h"
#include "uiproxy.h"
+#include <jobs/setupkolabfoldersjob.h>
#include <kimap/session.h>
#include <kimap/logoutjob.h>
#include <kimap/appendjob.h>
@@ -29,6 +30,7 @@
#include <kimap/selectjob.h>
#include <kimap/expungejob.h>
#include <kolab/errorhandler.h>
+#include <kolab/kolabdefinitions.h>
KolabAccount::KolabAccount(QObject* parent)
@@ -117,7 +119,7 @@ void KolabAccount::appendObject(KMime::Message::Ptr obj, const QString& folder)
//TODO copy flags over
// job->setFlags( m_flags );
job->exec();
- Debug() << "appended object";
+ Debug() << "appended object in folder: " << folder;
if (job->error()) {
Error() << job->errorString();
}
@@ -190,3 +192,15 @@ void KolabAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &desc
mMailboxes.append(descriptors);
}
+void KolabAccount::setupFolders()
+{
+ //TODO test properly
+ SetupKolabFoldersJob *setupJob = new SetupKolabFoldersJob(QStringList() << QLatin1String("ANNOTATEMORE"), QString(), mSession, this);
+ setupJob->setKolabFolders(QStringList() << KOLAB_FOLDER_TYPE_CONTACT << KOLAB_FOLDER_TYPE_EVENT << KOLAB_FOLDER_TYPE_TASK << KOLAB_FOLDER_TYPE_JOURNAL << KOLAB_FOLDER_TYPE_NOTE << KOLAB_FOLDER_TYPE_CONFIGURATION);
+ setupJob->exec();
+ if (setupJob->error()) {
+ Error() << setupJob->errorString();
+ }
+}
+
+
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
index ac9bc97..a4dd72a 100644
--- a/migrationutility/kolabaccount.h
+++ b/migrationutility/kolabaccount.h
@@ -36,6 +36,7 @@ public:
void setCredentials(const QString &username, const QString &pw);
void cleanAccount();
+ void setupFolders();
void appendObject(KMime::Message::Ptr obj, const QString &folder);
void logout();
diff --git a/migrationutility/migrateuserjob.cpp b/migrationutility/migrateuserjob.cpp
index 412202b..2598ba2 100644
--- a/migrationutility/migrateuserjob.cpp
+++ b/migrationutility/migrateuserjob.cpp
@@ -32,6 +32,7 @@ MigrateUserJob::MigrateUserJob(SourceAccount *sourceAccount, KolabAccount *kolab
void MigrateUserJob::start()
{
mKolabAccount->cleanAccount();
+ mKolabAccount->setupFolders();
migrateFolders(mSourceAccount->lookupFolderList());
}
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index fb98a82..1a860c6 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -18,6 +18,7 @@
#include "sourceaccount.h"
#include "uiproxy.h"
#include <jobs/fetchmessagesjob.h>
+#include <jobs/probekolabserverjob.h>
#include <kimap/session.h>
#include <kimap/listjob.h>
#include <kimap/logoutjob.h>
@@ -117,27 +118,11 @@ void KolabSourceAccount::init()
} else {
Debug() << "authentication successful";
}
-
- KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession);
- capabilities->exec();
- if ( capabilities->capabilities().contains( "NAMESPACE" ) ) {
- KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession );
- nsJob->exec();
- mPersonalNamespaces = nsJob->personalNamespaces();
-// Debug() << "personalNamespaces";
-// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->personalNamespaces()) {
-// Debug() << desc.name;
-// }
-// Debug() << "user";
-// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->userNamespaces()) {
-// Debug() << desc.name;
-// }
-// Debug() << "shared";
-// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->sharedNamespaces()) {
-// Debug() << desc.name;
-// }
-// Debug() << "---";
- }
+
+ ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(mSession, this);
+ probeJob->exec();
+ mKolabFolders = probeJob->kolabFolders();
+ mPersonalNamespaces = probeJob->personalNamespace();
}
@@ -164,7 +149,7 @@ QStringList KolabSourceAccount::lookupFolderList()
void KolabSourceAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
{
mMailboxes.append(descriptors);
- //TODO store folder type form metadata
+ //TODO store folder type from metadata
// for (int i = 0; i < descriptors.size(); i++) {
// Debug() << descriptors.at(i).name;
// foreach (const QByteArray &arr, flags.at(i)) {
@@ -206,14 +191,22 @@ KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, Kolab::ObjectType ov
QList<KMime::Message::Ptr> KolabSourceAccount::getObjects(const QString& folder)
{
+ Kolab::ObjectType type = Kolab::InvalidObject;
+ if (mKolabFolders.values().contains(folder)) {
+ type = Kolab::DictionaryConfigurationObject;//Some random, we use the autodetection afterwards //TODO use the detected type instead
+ }
Debug() << folder;
FetchMessagesJob *fetchJob = new FetchMessagesJob(folder, mSession, this);
fetchJob->exec();
Debug() << fetchJob->getMessages().size();
QList<KMime::Message::Ptr> messages;
foreach (const KMime::Message::Ptr &msg, fetchJob->getMessages()) {
- //TODO writing the message again would rather belong to the KolabAccount, but for that we'd need some Kolab object container
- messages.append(upgradeMessage(msg, Kolab::InvalidObject));
+ //TODO writing the message again would rather belong to the KolabAccount, but for that we'd need some Kolab object container to pass around
+ if (type != Kolab::InvalidObject) {
+ messages.append(upgradeMessage(msg, Kolab::InvalidObject));
+ } else {
+ messages.append(msg);
+ }
}
return messages;
}
diff --git a/migrationutility/sourceaccount.h b/migrationutility/sourceaccount.h
index 6287494..307b590 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -80,6 +80,7 @@ private:
KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
QList<KIMAP::MailBoxDescriptor> mMailboxes;
QList<KIMAP::MailBoxDescriptor> mPersonalNamespaces;
+ QMultiHash<QString, QString> mKolabFolders;
};
#endif // SOURCEACCOUNT_H