summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-09-28 09:16:54 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-09-28 09:16:54 (GMT)
commit7bd55debd99d15da8316dce7721550c2516016bc (patch)
tree918c17318c668f23041567ece225d6c0fd9d376a
parentc4387c90885b98ea93e78ab40d3ebd0b68a4c22c (diff)
downloadkolab-utils-7bd55debd99d15da8316dce7721550c2516016bc.tar.gz
Got rid of some assumtions, most basic Kolab-to-Kolab migration works. (Although there is an uncaught exception at the end...)
-rw-r--r--migrationutility/coordinationjob.cpp3
-rw-r--r--migrationutility/coordinationjob.h2
-rw-r--r--migrationutility/kolabaccount.cpp81
-rw-r--r--migrationutility/kolabaccount.h6
-rw-r--r--migrationutility/main.cpp6
-rw-r--r--migrationutility/migratefolderjob.cpp5
-rw-r--r--migrationutility/migrateuserjob.cpp1
-rw-r--r--migrationutility/sourceaccount.cpp23
-rw-r--r--migrationutility/sourceaccount.h6
-rw-r--r--upgradetool/kolabformatupgradejob.cpp3
10 files changed, 98 insertions, 38 deletions
diff --git a/migrationutility/coordinationjob.cpp b/migrationutility/coordinationjob.cpp
index 542ba57..a1bc809 100644
--- a/migrationutility/coordinationjob.cpp
+++ b/migrationutility/coordinationjob.cpp
@@ -19,6 +19,7 @@
#include "sourceserver.h"
#include "kolabserver.h"
#include "migrateuserjob.h"
+#include <kolab/errorhandler.h>
CoordinationJob::CoordinationJob(SourceServer *sourceServer, KolabServer *kolabServer, QObject* parent)
: KJob(parent),
@@ -36,7 +37,9 @@ void CoordinationJob::start()
job->exec();
}
+ Debug() << "done";
emitResult();
+ emit done();
}
// #include "moc_coordinationjob.cxx"
diff --git a/migrationutility/coordinationjob.h b/migrationutility/coordinationjob.h
index e112b2d..229d4fc 100644
--- a/migrationutility/coordinationjob.h
+++ b/migrationutility/coordinationjob.h
@@ -27,6 +27,8 @@ class CoordinationJob: public KJob
public:
explicit CoordinationJob(SourceServer *sourceServer, KolabServer *kolabServer, QObject* parent = 0);
virtual void start();
+signals:
+ void done();
private:
SourceServer *mSourceServer;
KolabServer *mKolabServer;
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
index 88326ff..c269d19 100644
--- a/migrationutility/kolabaccount.cpp
+++ b/migrationutility/kolabaccount.cpp
@@ -29,8 +29,10 @@
#include <kimap/storejob.h>
#include <kimap/selectjob.h>
#include <kimap/expungejob.h>
+#include <kimap/setmetadatajob.h>
#include <kolab/errorhandler.h>
#include <kolab/kolabdefinitions.h>
+#include <formathelpers.h>
KolabAccount::KolabAccount(QObject* parent)
@@ -76,7 +78,9 @@ void KolabAccount::init()
}
KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession);
capabilities->exec();
- if ( capabilities->capabilities().contains( "NAMESPACE" ) ) {
+ mCapabilities = capabilities->capabilities();
+
+ if ( mCapabilities.contains( "NAMESPACE" ) ) {
KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession );
nsJob->exec();
mPersonalNamespaces = nsJob->personalNamespaces();
@@ -95,24 +99,9 @@ void KolabAccount::init()
}
}
-void KolabAccount::createFolder(const QString& folder)
-{
- KIMAP::CreateJob *createJob = new KIMAP::CreateJob(mSession);
- createJob->setMailBox(folder);
- createJob->exec();
-
- //TODO user setupkolabfoldersjob for toplevel hierarchy
-
- Debug() << "created folder " << folder;
- if (createJob->error()) {
- Error() << createJob->errorString();
- }
-}
-
void KolabAccount::appendObject(KMime::Message::Ptr obj, const QString& folder)
{
- init();
- createFolder(folder);
+ Q_ASSERT(mFolders.contains(folder));
KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
job->setMailBox( folder );
job->setContent( obj->encodedContent( true ) );
@@ -130,7 +119,7 @@ void KolabAccount::logout()
KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(mSession);
logoutJob->exec();
mSession->close();
- mSession->deleteLater();
+// mSession->deleteLater();
mSession = 0;
Debug() << "logout done";
}
@@ -142,12 +131,12 @@ void KolabAccount::cleanAccount()
init();
KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
- listJob->setQueriedNamespaces(mPersonalNamespaces); //FIXME exclude shared namespaces
+ listJob->setQueriedNamespaces(mPersonalNamespaces);
QObject::connect( listJob, SIGNAL(mailBoxesReceived(QList<KIMAP::MailBoxDescriptor>,QList<QList<QByteArray> >)),
this, SLOT(mailBoxesReceived(QList<KIMAP::MailBoxDescriptor>,QList<QList<QByteArray> >)));
listJob->exec();
foreach (const KIMAP::MailBoxDescriptor &desc, mMailboxes) {
- if (desc.name.toLower().contains("inbox")) {
+ if (desc.name.contains(QLatin1String("inbox"), Qt::CaseInsensitive)) {
continue;
}
bool skip = false;
@@ -185,6 +174,7 @@ void KolabAccount::cleanAccount()
Error() << deleteJob->errorString();
}
}
+ mFolders.append(QLatin1String("inbox"));
}
void KolabAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
@@ -192,15 +182,62 @@ void KolabAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &desc
mMailboxes.append(descriptors);
}
+#define KOLAB_FOLDER_TYPE_DRAFT_SUFFIX ".draft"
+#define KOLAB_FOLDER_TYPE_SENT_SUFFIX ".sentitems"
+#define KOLAB_FOLDER_TYPE_OUTBOX_SUFFIX ".outbox"
+#define KOLAB_FOLDER_TYPE_TRASH_SUFFIX ".wastebasket"
+#define KOLAB_FOLDER_TYPE_JUNK_SUFFIX ".junkemail"
+
+//TODO setup drafts/sent/
+void KolabAccount::createFolder(const QString &name, const QByteArray &annotation)
+{
+ if (mFolders.contains(name, Qt::CaseInsensitive)) {
+ Warning() << "folder is already existing: " << name;
+ return;
+ }
+
+ KIMAP::CreateJob *createJob = new KIMAP::CreateJob(mSession);
+ createJob->setMailBox(name);
+ createJob->exec();
+ Debug() << "created folder " << name;
+ if (createJob->error()) {
+ Error() << createJob->errorString();
+ }
+
+ KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(mSession);
+ setMetadataJob->setMailBox(createJob->mailBox());
+// 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(folderType, true)).toLatin1() );
+// } else {
+ setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
+ setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
+ setMetadataJob->addMetaData( "value.shared", annotation );
+// }
+
+ mFolders.append(name);
+}
+
+void KolabAccount::createFolder(const QString& name, Kolab::FolderType folderType)
+{
+ createFolder(name, QString::fromStdString(Kolab::folderAnnotation(folderType)).toLatin1());
+}
+
+
void KolabAccount::setupFolders()
{
- //TODO test properly
- SetupKolabFoldersJob *setupJob = new SetupKolabFoldersJob(QStringList() << QLatin1String("ANNOTATEMORE"), QString(), mSession, this);
+ SetupKolabFoldersJob *setupJob = new SetupKolabFoldersJob(mCapabilities, 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();
}
+ KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
+ selectJob->setMailBox(QString());
+ createFolder("Drafts", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_DRAFT_SUFFIX);
+ createFolder("Sent", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_SENT_SUFFIX);
+ createFolder("Trash", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_TRASH_SUFFIX);
}
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
index a4dd72a..512716f 100644
--- a/migrationutility/kolabaccount.h
+++ b/migrationutility/kolabaccount.h
@@ -18,6 +18,7 @@
#ifndef KOLABACCOUNT_H
#define KOLABACCOUNT_H
#include <QObject>
+#include <formathelpers.h>
#include <kimap/loginjob.h>
#include <kimap/listjob.h>
#include <kmime/kmime_message.h>
@@ -38,6 +39,8 @@ public:
void cleanAccount();
void setupFolders();
void appendObject(KMime::Message::Ptr obj, const QString &folder);
+ void createFolder(const QString &name, Kolab::FolderType folderType);
+ void createFolder(const QString &name, const QByteArray &annotation);
void logout();
@@ -45,7 +48,6 @@ private slots:
void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
private:
void init();
- void createFolder(const QString &folder);
KIMAP::Session *mSession;
QString mHost;
int mPort;
@@ -56,6 +58,8 @@ private:
QList<KIMAP::MailBoxDescriptor> mMailboxes;
QList<KIMAP::MailBoxDescriptor> mPersonalNamespaces;
QList<KIMAP::MailBoxDescriptor> mExcludedNamespaces;
+ QStringList mFolders;
+ QStringList mCapabilities;
};
#endif // KOLABACCOUNT_H
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 1e52a9d..d6f0235 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -18,7 +18,6 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/QStringList>
#include <QtCore/qfile.h>
-#include <kdebug.h>
#include <kcmdlineargs.h>
#include <kolab/errorhandler.h>
@@ -68,9 +67,10 @@ int main(int argc, char *argv[])
kolabServer->setAdminCredentials(args->getOption("to-proxyauth"), args->getOption("to-password"));
CoordinationJob *job = new CoordinationJob(sourceServer, kolabServer, &app);
- QObject::connect(job, SIGNAL(result(KJob*)), &app, SLOT(quit()));
+ QObject::connect(job, SIGNAL(done()), &app, SLOT(quit()));
job->start();
- app.exec();
+ //TODO reenable once we have async jobs which don't execute everything using exec
+ //app.exec();
if (Kolab::ErrorHandler::instance().error() >= Kolab::ErrorHandler::Error) {
return -1;
diff --git a/migrationutility/migratefolderjob.cpp b/migrationutility/migratefolderjob.cpp
index f02df15..09d3d1e 100644
--- a/migrationutility/migratefolderjob.cpp
+++ b/migrationutility/migratefolderjob.cpp
@@ -30,10 +30,11 @@ MigrateFolderJob::MigrateFolderJob(const QString &folder, SourceAccount* sourceA
void MigrateFolderJob::start()
{
- const QString &targetFolder = mSourceAccount->translateFolder(mFolder);
+ const QPair<Kolab::FolderType, QString> &targetFolder = mSourceAccount->translateFolder(mFolder);
+ mKolabAccount->createFolder(targetFolder.second, targetFolder.first);
QList<KMime::Message::Ptr> messages = mSourceAccount->getObjects(mFolder);
foreach (const KMime::Message::Ptr &msg, messages) {
- mKolabAccount->appendObject(msg, targetFolder);
+ mKolabAccount->appendObject(msg, targetFolder.second);
}
emitResult();
} \ No newline at end of file
diff --git a/migrationutility/migrateuserjob.cpp b/migrationutility/migrateuserjob.cpp
index 2598ba2..e56a003 100644
--- a/migrationutility/migrateuserjob.cpp
+++ b/migrationutility/migrateuserjob.cpp
@@ -43,6 +43,7 @@ void MigrateUserJob::migrateFolders(const QStringList &folders)
job->exec();
}
mSourceAccount->logout();
+ mKolabAccount->logout();
emitResult();
}
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index 1a860c6..fa52ad8 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -48,9 +48,9 @@ void SourceAccount::logout()
}
-QString SourceAccount::translateFolder(const QString& folder)
+QPair<Kolab::FolderType, QString> SourceAccount::translateFolder(const QString& folder)
{
- return folder;
+ return QPair<Kolab::FolderType, QString>(Kolab::MailType, folder);
}
@@ -125,6 +125,18 @@ void KolabSourceAccount::init()
mPersonalNamespaces = probeJob->personalNamespace();
}
+Kolab::FolderType KolabSourceAccount::getFolderType(const QString &folder)
+{
+ if (mKolabFolders.values().contains(folder)) {
+ return Kolab::folderTypeFromString(mKolabFolders.key(folder).toStdString());
+ }
+ return Kolab::MailType;
+}
+
+QPair<Kolab::FolderType, QString> KolabSourceAccount::translateFolder(const QString& folder)
+{
+ return QPair<Kolab::FolderType, QString>(getFolderType(folder), folder);
+}
QStringList KolabSourceAccount::lookupFolderList()
{
@@ -201,7 +213,7 @@ QList<KMime::Message::Ptr> KolabSourceAccount::getObjects(const QString& folder)
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 to pass around
+ //TODO writing the message again would rather belong to the KolabAccount, but for that we'd need some Kolab object container to pass around (aka QPair<Type,Object>)
if (type != Kolab::InvalidObject) {
messages.append(upgradeMessage(msg, Kolab::InvalidObject));
} else {
@@ -221,10 +233,5 @@ void KolabSourceAccount::logout()
Debug() << "logout done";
}
-QString KolabSourceAccount::translateFolder(const QString& folder)
-{
- return SourceAccount::translateFolder(folder);
-}
-
// #include "sourceaccount.moc"
diff --git a/migrationutility/sourceaccount.h b/migrationutility/sourceaccount.h
index 307b590..50f6095 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -20,6 +20,7 @@
#include <QObject>
#include <QStringList>
+#include <formathelpers.h>
#include <kimap/loginjob.h>
#include <kimap/listjob.h>
#include <kmime/kmime_message.h>
@@ -33,7 +34,7 @@ public:
virtual QStringList lookupFolderList();
virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
virtual void logout();
- virtual QString translateFolder(const QString &folder);
+ virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);
signals:
void folderList(const QStringList &);
// FindFoldersJob *getFolderList();
@@ -60,7 +61,7 @@ public:
explicit KolabSourceAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
- virtual QString translateFolder(const QString& folder);
+ virtual QPair<Kolab::FolderType, QString> translateFolder(const QString& folder);
void setHost(const QString &host, qint16 port);
void setCredentials(const QString &username, const QString &pw);
@@ -71,6 +72,7 @@ private slots:
void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
private:
void init();
+ Kolab::FolderType getFolderType(const QString &folder);
KIMAP::Session *mSession;
QString mHost;
int mPort;
diff --git a/upgradetool/kolabformatupgradejob.cpp b/upgradetool/kolabformatupgradejob.cpp
index b3c94a2..4c48d37 100644
--- a/upgradetool/kolabformatupgradejob.cpp
+++ b/upgradetool/kolabformatupgradejob.cpp
@@ -49,6 +49,9 @@ void KolabFormatUpgradeJob::setOverrideObjectType(Kolab::ObjectType type)
void KolabFormatUpgradeJob::start()
{
Debug() << "Processing Mailbox....... " << m_folder;
+// KJob *job = KIMAPFactory::select(m_folder);
+// connect( job, SIGNAL(result(KJob*)), this, SLOT(onSelectDone(KJob*)) );
+
KIMAP::SelectJob *select = new KIMAP::SelectJob( m_session );
select->setMailBox( m_folder );
connect( select, SIGNAL(result(KJob*)), this, SLOT(onSelectDone(KJob*)) );