summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-09-27 09:42:13 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-09-27 09:42:13 (GMT)
commit28b63970538c1e4bb8f801604aeb2bd47cd668db (patch)
tree39213cc29170b852e32f4e0a930068231f071860
parentf8fc27d068aee9cd75ce25fa721f5e7120ba7fcd (diff)
downloadkolab-utils-28b63970538c1e4bb8f801604aeb2bd47cd668db.tar.gz
We can already list objects, and clean the target server. Now we need to setup the folders properly and implement the folder mapping.
-rw-r--r--migrationutility/CMakeLists.txt4
-rw-r--r--migrationutility/coordinationjob.cpp10
-rw-r--r--migrationutility/coordinationjob.h6
-rw-r--r--migrationutility/kolabaccount.cpp192
-rw-r--r--migrationutility/kolabaccount.h60
-rw-r--r--migrationutility/kolabserver.cpp49
-rw-r--r--migrationutility/kolabserver.h49
-rw-r--r--migrationutility/main.cpp14
-rw-r--r--migrationutility/migratefolderjob.cpp11
-rw-r--r--migrationutility/migratefolderjob.h7
-rw-r--r--migrationutility/migrateuserjob.cpp16
-rw-r--r--migrationutility/migrateuserjob.h9
-rw-r--r--migrationutility/sourceaccount.cpp114
-rw-r--r--migrationutility/sourceaccount.h12
-rw-r--r--migrationutility/sourceserver.cpp22
-rw-r--r--migrationutility/sourceserver.h8
-rw-r--r--migrationutility/uiproxy.h24
17 files changed, 544 insertions, 63 deletions
diff --git a/migrationutility/CMakeLists.txt b/migrationutility/CMakeLists.txt
index 235bf9c..6a22a41 100644
--- a/migrationutility/CMakeLists.txt
+++ b/migrationutility/CMakeLists.txt
@@ -15,6 +15,8 @@ set(MIGRATION_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/coordinationjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sourceaccount.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sourceserver.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/kolabaccount.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/kolabserver.cpp
)
@@ -24,6 +26,8 @@ QT4_WRAP_CPP(MIGRATION_MOC
${CMAKE_CURRENT_SOURCE_DIR}/coordinationjob.h
${CMAKE_CURRENT_SOURCE_DIR}/sourceaccount.h
${CMAKE_CURRENT_SOURCE_DIR}/sourceserver.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/kolabaccount.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/kolabserver.h
)
diff --git a/migrationutility/coordinationjob.cpp b/migrationutility/coordinationjob.cpp
index e69c843..542ba57 100644
--- a/migrationutility/coordinationjob.cpp
+++ b/migrationutility/coordinationjob.cpp
@@ -16,10 +16,14 @@
*/
#include "coordinationjob.h"
+#include "sourceserver.h"
+#include "kolabserver.h"
+#include "migrateuserjob.h"
-CoordinationJob::CoordinationJob(SourceServer *sourceServer, QObject* parent)
+CoordinationJob::CoordinationJob(SourceServer *sourceServer, KolabServer *kolabServer, QObject* parent)
: KJob(parent),
- mSourceServer(sourceServer)
+ mSourceServer(sourceServer),
+ mKolabServer(kolabServer)
{
}
@@ -27,7 +31,7 @@ CoordinationJob::CoordinationJob(SourceServer *sourceServer, QObject* parent)
void CoordinationJob::start()
{
foreach (const QString &user, mSourceServer->getUserList()) {
- MigrateUserJob *job = mSourceServer->createMigrationJob(user);
+ MigrateUserJob *job = new MigrateUserJob(mSourceServer->getSourceAccount(user), mKolabServer->getAccount(user), this);
Q_ASSERT(job);
job->exec();
}
diff --git a/migrationutility/coordinationjob.h b/migrationutility/coordinationjob.h
index 9e7bc8d..e112b2d 100644
--- a/migrationutility/coordinationjob.h
+++ b/migrationutility/coordinationjob.h
@@ -18,16 +18,18 @@
#ifndef COORDINATIONJOB_H
#define COORDINATIONJOB_H
#include <kjob.h>
-#include "sourceserver.h"
+class KolabServer;
+class SourceServer;
class CoordinationJob: public KJob
{
Q_OBJECT
public:
- explicit CoordinationJob(SourceServer *sourceServer, QObject* parent = 0);
+ explicit CoordinationJob(SourceServer *sourceServer, KolabServer *kolabServer, QObject* parent = 0);
virtual void start();
private:
SourceServer *mSourceServer;
+ KolabServer *mKolabServer;
};
#endif // COORDINATIONJOB_H
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
new file mode 100644
index 0000000..9f6a235
--- /dev/null
+++ b/migrationutility/kolabaccount.cpp
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "kolabaccount.h"
+#include "uiproxy.h"
+#include <kimap/session.h>
+#include <kimap/logoutjob.h>
+#include <kimap/appendjob.h>
+#include <kimap/createjob.h>
+#include <kimap/deletejob.h>
+#include <kimap/listjob.h>
+#include <kimap/capabilitiesjob.h>
+#include <kimap/namespacejob.h>
+#include <kimap/storejob.h>
+#include <kimap/selectjob.h>
+#include <kimap/expungejob.h>
+#include <kolab/errorhandler.h>
+
+
+KolabAccount::KolabAccount(QObject* parent)
+: QObject(parent),
+ mSession(0),
+ mEncryptionMode(KIMAP::LoginJob::TlsV1),
+ mAuthenticationMode(KIMAP::LoginJob::Plain)
+{
+
+}
+
+void KolabAccount::setHost(const QString& host, qint16 port)
+{
+ mHost = host;
+ mPort = port;
+}
+
+void KolabAccount::setCredentials(const QString& username, const QString& pw)
+{
+ mUsername = username;
+ mPw = pw;
+}
+
+void KolabAccount::init()
+{
+ if (mSession) {
+ return;
+ }
+ mSession = new KIMAP::Session( mHost, mPort, this );
+ mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
+ KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( mSession );
+ loginJob->setUserName( mUsername );
+ loginJob->setPassword( mPw );
+ loginJob->setEncryptionMode( mEncryptionMode );
+ loginJob->setAuthenticationMode( mAuthenticationMode );
+ loginJob->exec();
+
+ if ( loginJob->error() ) {
+ Warning() << "Failed to login: " << loginJob->errorString();
+ return;
+ } 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();
+ mExcludedNamespaces = nsJob->userNamespaces();
+ mExcludedNamespaces.append(nsJob->sharedNamespaces());
+ Debug() << "personal namespaces";
+ foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->personalNamespaces()) {
+ Debug() << desc.name;
+ }
+ foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->userNamespaces()) {
+ Debug() << desc.name;
+ }
+ foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->sharedNamespaces()) {
+ Debug() << desc.name;
+ }
+ }
+}
+
+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);
+ KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
+ job->setMailBox( folder );
+ job->setContent( obj->encodedContent( true ) );
+ //TODO copy flags over
+// job->setFlags( m_flags );
+ job->exec();
+ Debug() << "appended object";
+ if (job->error()) {
+ Error() << job->errorString();
+ }
+}
+
+void KolabAccount::logout()
+{
+ KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(mSession);
+ logoutJob->exec();
+ mSession->close();
+ mSession->deleteLater();
+ mSession = 0;
+ Debug() << "logout done";
+}
+
+const char* FlagDeleted2 = "\\Deleted";
+
+void KolabAccount::cleanAccount()
+{
+ init();
+ KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
+ listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
+ listJob->setQueriedNamespaces(mPersonalNamespaces); //FIXME exclude shared namespaces
+ 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")) {
+ continue;
+ }
+ bool skip = false;
+ foreach(const KIMAP::MailBoxDescriptor &excluded, mExcludedNamespaces) {
+ if (desc.name.contains(excluded.name)) {
+ skip = true;
+ break;
+ }
+ }
+ if (skip) {
+ continue;
+ }
+
+ KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
+ selectJob->setMailBox(desc.name);
+ selectJob->exec();
+ const int messageCount = selectJob->messageCount();
+
+ if (messageCount > 0) {
+ KIMAP::StoreJob *storeJob = new KIMAP::StoreJob(mSession);
+ storeJob->setMode(KIMAP::StoreJob::AppendFlags);
+ storeJob->setFlags(KIMAP::MessageFlags() << FlagDeleted2);
+ storeJob->setSequenceSet( KIMAP::ImapSet( 1, messageCount ) );
+ storeJob->exec();
+
+ KIMAP::ExpungeJob *expungeJob = new KIMAP::ExpungeJob(mSession);
+ expungeJob->exec();
+ }
+
+ KIMAP::DeleteJob *deleteJob = new KIMAP::DeleteJob(mSession);
+ Debug() << "deleting: " << desc.name;
+ deleteJob->setMailBox(desc.name);
+ deleteJob->exec();
+ if (deleteJob->error()) {
+ Error() << deleteJob->errorString();
+ }
+ }
+}
+
+void KolabAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
+{
+ mMailboxes.append(descriptors);
+}
+
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
new file mode 100644
index 0000000..ac9bc97
--- /dev/null
+++ b/migrationutility/kolabaccount.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KOLABACCOUNT_H
+#define KOLABACCOUNT_H
+#include <QObject>
+#include <kimap/loginjob.h>
+#include <kimap/listjob.h>
+#include <kmime/kmime_message.h>
+
+namespace KIMAP {
+class Session;
+}
+
+class KolabAccount: public QObject
+{
+ Q_OBJECT
+public:
+ explicit KolabAccount(QObject* parent = 0);
+
+ void setHost(const QString &host, qint16 port);
+ void setCredentials(const QString &username, const QString &pw);
+
+ void cleanAccount();
+ void appendObject(KMime::Message::Ptr obj, const QString &folder);
+
+ void logout();
+
+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;
+ QString mUsername;
+ QString mPw;
+ KIMAP::LoginJob::EncryptionMode mEncryptionMode;
+ KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
+ QList<KIMAP::MailBoxDescriptor> mMailboxes;
+ QList<KIMAP::MailBoxDescriptor> mPersonalNamespaces;
+ QList<KIMAP::MailBoxDescriptor> mExcludedNamespaces;
+};
+
+#endif // KOLABACCOUNT_H
diff --git a/migrationutility/kolabserver.cpp b/migrationutility/kolabserver.cpp
new file mode 100644
index 0000000..fa7dd28
--- /dev/null
+++ b/migrationutility/kolabserver.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "kolabserver.h"
+#include "kolabaccount.h"
+#include <kolab/errorhandler.h>
+
+KolabServer::KolabServer(QObject* parent)
+: QObject(parent),
+ mSession(0),
+ mEncryptionMode(KIMAP::LoginJob::TlsV1),
+ mAuthenticationMode(KIMAP::LoginJob::Plain)
+{
+
+}
+
+void KolabServer::setHost(const QString& host, qint16 port)
+{
+ mHost = host;
+ mPort = port;
+}
+
+void KolabServer::setAdminCredentials(const QString& username, const QString& pw)
+{
+ mUsername = username;
+ mPw = pw;
+}
+
+KolabAccount* KolabServer::getAccount(const QString& user)
+{
+ KolabAccount *account = new KolabAccount(this);
+ account->setHost(mHost, mPort);
+ account->setCredentials(user, mPw);
+ return account;
+}
diff --git a/migrationutility/kolabserver.h b/migrationutility/kolabserver.h
new file mode 100644
index 0000000..6762821
--- /dev/null
+++ b/migrationutility/kolabserver.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef KOLABSERVER_H
+#define KOLABSERVER_H
+#include <QObject>
+#include <kimap/loginjob.h>
+
+namespace KIMAP {
+class Session;
+}
+
+class KolabAccount;
+class KolabServer: public QObject
+{
+ Q_OBJECT
+public:
+ explicit KolabServer(QObject* parent = 0);
+
+ void setHost(const QString &host, qint16 port);
+ void setAdminCredentials(const QString &username, const QString &pw);
+
+ KolabAccount *getAccount(const QString &user);
+private:
+ void logout();
+ KIMAP::Session *mSession;
+ QString mHost;
+ int mPort;
+ QString mUsername;
+ QString mPw;
+ KIMAP::LoginJob::EncryptionMode mEncryptionMode;
+ KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
+};
+
+#endif // KOLABSERVER_H
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 9d166e8..1e52a9d 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -23,6 +23,8 @@
#include <kolab/errorhandler.h>
#include "coordinationjob.h"
+#include "sourceserver.h"
+#include "kolabserver.h"
/**
* kolab-migrate --from caldav --to kolab (implied?) --caldav-host caldav.example.org --caldav-authn <admin> --caldav-authz <user> --caldav-pass <pass> --<folder-selection> --<folder-mapping> --kolab-host kolab.example.org --kolab-authn <admin> --kolab-authz <user> --kolab-pass <pass>
@@ -42,6 +44,12 @@ int main(int argc, char *argv[])
options.add("u").add("from-user <loginname>", ki18n("Username for IMAP Account"));
options.add("y").add("from-proxyauth <loginname>", ki18n("Username to be used for authentication together with password (optional, works with PLAIN/SASL authentication)"));
options.add("p").add("from-password <password>", ki18n("Password for IMAP Account"));
+
+ options.add("to <host>", ki18n("Username for IMAP Account"));
+ options.add("to-port <port>", ki18n("Port to be used on IMAP Server"), "143");
+ options.add("to-user <loginname>", ki18n("Username for IMAP Account"));
+ options.add("to-proxyauth <loginname>", ki18n("Username to be used for authentication together with password (optional, works with PLAIN/SASL authentication)"));
+ options.add("to-password <password>", ki18n("Password for IMAP Account"));
// options.add("e").add("encrypt <mode>", ki18n("Encryption mode to be used (NONE, TLS, SSL)"), "TLS");
// options.add("a").add("auth <mode>", ki18n("Authentication mode to be used (PLAIN, LOGIN, CRAMMD5, DIGESTMD5, NTLM, GSSAPI, ANONYMOUS, CLEARTEXT)"), "PLAIN");
// options.add("+[server/file]", ki18n("IMAP Server/File"));
@@ -55,7 +63,11 @@ int main(int argc, char *argv[])
sourceServer->setAdminCredentials(args->getOption("from-proxyauth"), args->getOption("from-password"));
sourceServer->setSingleUser(args->getOption("from-user"));
- CoordinationJob *job = new CoordinationJob(sourceServer, &app);
+ KolabServer *kolabServer = new KolabServer(&app);
+ kolabServer->setHost(args->getOption("to"), args->getOption("to-port").toInt());
+ 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()));
job->start();
app.exec();
diff --git a/migrationutility/migratefolderjob.cpp b/migrationutility/migratefolderjob.cpp
index 84df5cd..f02df15 100644
--- a/migrationutility/migratefolderjob.cpp
+++ b/migrationutility/migratefolderjob.cpp
@@ -16,10 +16,13 @@
*/
#include "migratefolderjob.h"
+#include "sourceaccount.h"
+#include "kolabaccount.h"
#include <kolab/errorhandler.h>
-MigrateFolderJob::MigrateFolderJob(const QString &folder, SourceAccount* sourceAccount, QObject* parent)
+MigrateFolderJob::MigrateFolderJob(const QString &folder, SourceAccount* sourceAccount, KolabAccount *kolabAccount, QObject* parent)
: mSourceAccount(sourceAccount),
+ mKolabAccount(kolabAccount),
mFolder(folder)
{
@@ -27,6 +30,10 @@ MigrateFolderJob::MigrateFolderJob(const QString &folder, SourceAccount* sourceA
void MigrateFolderJob::start()
{
- mSourceAccount->getObjects(mFolder);
+ const QString &targetFolder = mSourceAccount->translateFolder(mFolder);
+ QList<KMime::Message::Ptr> messages = mSourceAccount->getObjects(mFolder);
+ foreach (const KMime::Message::Ptr &msg, messages) {
+ mKolabAccount->appendObject(msg, targetFolder);
+ }
emitResult();
} \ No newline at end of file
diff --git a/migrationutility/migratefolderjob.h b/migrationutility/migratefolderjob.h
index cad9414..e9e4332 100644
--- a/migrationutility/migratefolderjob.h
+++ b/migrationutility/migratefolderjob.h
@@ -19,17 +19,18 @@
#define MIGRATEFOLDERJOB_H
#include <kjob.h>
-#include <qsharedpointer.h>
-#include "sourceaccount.h"
+class SourceAccount;
+class KolabAccount;
class MigrateFolderJob: public KJob
{
Q_OBJECT
public:
- explicit MigrateFolderJob(const QString &folder, SourceAccount *sourceAccount, QObject* parent = 0);
+ explicit MigrateFolderJob(const QString &folder, SourceAccount *sourceAccount, KolabAccount *kolabAccount, QObject* parent = 0);
virtual void start();
private:
SourceAccount *mSourceAccount;
+ KolabAccount *mKolabAccount;
QString mFolder;
};
diff --git a/migrationutility/migrateuserjob.cpp b/migrationutility/migrateuserjob.cpp
index 99feac0..412202b 100644
--- a/migrationutility/migrateuserjob.cpp
+++ b/migrationutility/migrateuserjob.cpp
@@ -17,24 +17,28 @@
#include "migrateuserjob.h"
#include "migratefolderjob.h"
+#include "sourceaccount.h"
+#include "kolabaccount.h"
#include <kolab/errorhandler.h>
-MigrateUserJob::MigrateUserJob(SourceAccount *sourceAccount, QObject* parent)
+MigrateUserJob::MigrateUserJob(SourceAccount *sourceAccount, KolabAccount *kolabAccount, QObject* parent)
: KJob(parent),
- mSourceAccount(sourceAccount)
+ mSourceAccount(sourceAccount),
+ mKolabAccount(kolabAccount)
{
- connect(mSourceAccount, SIGNAL(folderList(QStringList)), this, SLOT(receivedFolderList(QStringList)));
+ connect(mSourceAccount, SIGNAL(folderList(QStringList)), this, SLOT(migrateFolders(QStringList)));
}
void MigrateUserJob::start()
{
- receivedFolderList(mSourceAccount->lookupFolderList());
+ mKolabAccount->cleanAccount();
+ migrateFolders(mSourceAccount->lookupFolderList());
}
-void MigrateUserJob::receivedFolderList(const QStringList &folders)
+void MigrateUserJob::migrateFolders(const QStringList &folders)
{
foreach (const QString &folder, folders) {
- MigrateFolderJob *job = new MigrateFolderJob(folder, mSourceAccount, this);
+ MigrateFolderJob *job = new MigrateFolderJob(folder, mSourceAccount, mKolabAccount, this);
job->exec();
}
mSourceAccount->logout();
diff --git a/migrationutility/migrateuserjob.h b/migrationutility/migrateuserjob.h
index b5b13f2..a667708 100644
--- a/migrationutility/migrateuserjob.h
+++ b/migrationutility/migrateuserjob.h
@@ -19,19 +19,20 @@
#define MIGRATEUSERJOB_H
#include <kjob.h>
-#include <qsharedpointer.h>
-#include "sourceaccount.h"
+class SourceAccount;
+class KolabAccount;
class MigrateUserJob: public KJob
{
Q_OBJECT
public:
- explicit MigrateUserJob(SourceAccount *sourceAccount, QObject* parent = 0);
+ explicit MigrateUserJob(SourceAccount *sourceAccount, KolabAccount *kolabAccount, QObject* parent = 0);
virtual void start();
private slots:
- void receivedFolderList(const QStringList &);
+ void migrateFolders(const QStringList &);
private:
SourceAccount *mSourceAccount;
+ KolabAccount *mKolabAccount;
};
#endif // MIGRATEUSERJOB_H
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index 11affb0..fb98a82 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -16,11 +16,15 @@
*/
#include "sourceaccount.h"
+#include "uiproxy.h"
#include <jobs/fetchmessagesjob.h>
#include <kimap/session.h>
#include <kimap/listjob.h>
#include <kimap/logoutjob.h>
+#include <kimap/capabilitiesjob.h>
+#include <kimap/namespacejob.h>
#include <kolab/errorhandler.h>
+#include <kolab/kolabobject.h>
SourceAccount::SourceAccount(QObject* parent)
: QObject(parent)
@@ -33,9 +37,9 @@ QStringList SourceAccount::lookupFolderList()
return QStringList();
}
-void SourceAccount::getObjects(const QString& folder)
+QList<KMime::Message::Ptr> SourceAccount::getObjects(const QString& folder)
{
-
+ return QList<KMime::Message::Ptr>();
}
void SourceAccount::logout()
@@ -43,6 +47,12 @@ void SourceAccount::logout()
}
+QString SourceAccount::translateFolder(const QString& folder)
+{
+ return folder;
+}
+
+
TestAccount::TestAccount(QObject* parent)
{
@@ -56,20 +66,15 @@ QStringList TestAccount::lookupFolderList()
return mFolderList;
}
-void TestAccount::getObjects(const QString& folder)
+QList<KMime::Message::Ptr> TestAccount::getObjects(const QString& folder)
{
Debug() << folder;
Q_ASSERT(mFolderList.removeAll(folder) == 1);
+ return QList<KMime::Message::Ptr>();
}
//--------------------------------------------------------------
-class UiProxy: public KIMAP::SessionUiProxy {
- public:
- bool ignoreSslError(const KSslErrorUiData& /*errorData*/) {
- return true; //Necessary due to the untrusted certificate
- }
-};
KolabSourceAccount::KolabSourceAccount(QObject* parent)
: SourceAccount(parent),
@@ -100,14 +105,6 @@ void KolabSourceAccount::init()
}
mSession = new KIMAP::Session( mHost, mPort, this );
mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
-}
-
-
-QStringList KolabSourceAccount::lookupFolderList()
-{
- Debug() << "lookupFolderList" << mHost << mPort << mUsername << mPw;
- init();
-
KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( mSession );
loginJob->setUserName( mUsername );
loginJob->setPassword( mPw );
@@ -121,15 +118,42 @@ QStringList KolabSourceAccount::lookupFolderList()
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() << "---";
+ }
+}
+
+
+QStringList KolabSourceAccount::lookupFolderList()
+{
+ Debug() << "lookupFolderList" << mHost << mPort << mUsername << mPw;
+ init();
+
KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
- //listJob->setQueriedNamespaces(); //FIXME no 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();
Debug() << "found " << mMailboxes.size();
-
QStringList mailboxes;
foreach (const KIMAP::MailBoxDescriptor &descriptor, mMailboxes) {
mailboxes.append(descriptor.name);
@@ -140,14 +164,58 @@ 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
+// for (int i = 0; i < descriptors.size(); i++) {
+// Debug() << descriptors.at(i).name;
+// foreach (const QByteArray &arr, flags.at(i)) {
+// Debug() << arr;
+// }
+// }
}
-void KolabSourceAccount::getObjects(const QString& folder)
+KMime::Message::Ptr upgradeMessage(KMime::Message::Ptr msg, Kolab::ObjectType overrideObjectType)
+{
+ Kolab::KolabObjectReader reader;
+ if (overrideObjectType != Kolab::InvalidObject) {
+ reader.setObjectType(overrideObjectType);
+ }
+ switch (reader.parseMimeMessage(msg)) {
+ case Kolab::EventObject:
+ return Kolab::KolabObjectWriter::writeEvent(reader.getEvent());
+ case Kolab::TodoObject:
+ return Kolab::KolabObjectWriter::writeTodo(reader.getTodo());
+ case Kolab::JournalObject:
+ return Kolab::KolabObjectWriter::writeJournal(reader.getJournal());
+ case Kolab::ContactObject:
+ return Kolab::KolabObjectWriter::writeContact(reader.getContact());
+ case Kolab::DistlistObject:
+ return Kolab::KolabObjectWriter::writeDistlist(reader.getDistlist());
+ case Kolab::NoteObject:
+ return Kolab::KolabObjectWriter::writeNote(reader.getNote());
+ case Kolab::DictionaryConfigurationObject: {
+ QString lang;
+ const QStringList &dict = reader.getDictionary(lang);
+ return Kolab::KolabObjectWriter::writeDictionary(dict, lang);
+ }
+ case Kolab::InvalidObject:
+ //TODO handle configuration objects
+ Error() << "failed to read mime file";
+ }
+ return KMime::Message::Ptr();
+}
+
+QList<KMime::Message::Ptr> KolabSourceAccount::getObjects(const QString& folder)
{
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));
+ }
+ return messages;
}
void KolabSourceAccount::logout()
@@ -160,4 +228,10 @@ 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 1a62de5..6287494 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -22,6 +22,7 @@
#include <QStringList>
#include <kimap/loginjob.h>
#include <kimap/listjob.h>
+#include <kmime/kmime_message.h>
class SourceAccount: public QObject
{
@@ -30,8 +31,9 @@ public:
explicit SourceAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual void getObjects(const QString &folder);
+ virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
virtual void logout();
+ virtual QString translateFolder(const QString &folder);
signals:
void folderList(const QStringList &);
// FindFoldersJob *getFolderList();
@@ -46,7 +48,7 @@ class TestAccount: public SourceAccount
public:
explicit TestAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual void getObjects(const QString &folder);
+ virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
QStringList mFolderList;
};
@@ -57,14 +59,15 @@ class KolabSourceAccount: public SourceAccount
public:
explicit KolabSourceAccount(QObject* parent = 0);
virtual QStringList lookupFolderList();
- virtual void getObjects(const QString &folder);
+ virtual QList<KMime::Message::Ptr> getObjects(const QString &folder);
+ virtual QString translateFolder(const QString& folder);
void setHost(const QString &host, qint16 port);
void setCredentials(const QString &username, const QString &pw);
void logout();
-private slots:
+private slots:
void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
private:
void init();
@@ -76,6 +79,7 @@ private:
KIMAP::LoginJob::EncryptionMode mEncryptionMode;
KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
QList<KIMAP::MailBoxDescriptor> mMailboxes;
+ QList<KIMAP::MailBoxDescriptor> mPersonalNamespaces;
};
#endif // SOURCEACCOUNT_H
diff --git a/migrationutility/sourceserver.cpp b/migrationutility/sourceserver.cpp
index 61598bf..23f0913 100644
--- a/migrationutility/sourceserver.cpp
+++ b/migrationutility/sourceserver.cpp
@@ -16,6 +16,7 @@
*/
#include "sourceserver.h"
+#include "uiproxy.h"
#include <commonconversion.h>
#include <kimap/listjob.h>
#include <kimap/logoutjob.h>
@@ -27,11 +28,12 @@ SourceServer::SourceServer(QObject* parent): QObject(parent)
}
-MigrateUserJob* SourceServer::createMigrationJob(const QString& user)
+SourceAccount* SourceServer::getSourceAccount(const QString& user)
{
- return new MigrateUserJob(new SourceAccount(this), this);
+ return new SourceAccount(this);
}
+
QStringList SourceServer::getUserList()
{
return QStringList();
@@ -57,20 +59,14 @@ QStringList TestServer::getUserList()
return mUsers;
}
-MigrateUserJob* TestServer::createMigrationJob(const QString& user)
+SourceAccount* TestServer::getSourceAccount(const QString& user)
{
Q_ASSERT(mUsers.removeAll(user) == 1);
- return new MigrateUserJob(new TestAccount(this), this);
+ return new TestAccount(this);
}
-//---------------------------------------------------------------------------
-class UiProxy: public KIMAP::SessionUiProxy {
- public:
- bool ignoreSslError(const KSslErrorUiData& /*errorData*/) {
- return true; //Necessary due to the untrusted certificate
- }
-};
+//---------------------------------------------------------------------------
KolabSourceServer::KolabSourceServer(QObject* parent)
: SourceServer(parent),
@@ -93,12 +89,12 @@ void KolabSourceServer::setAdminCredentials(const QString& username, const QStri
mPw = pw;
}
-MigrateUserJob* KolabSourceServer::createMigrationJob(const QString& user)
+SourceAccount* KolabSourceServer::getSourceAccount(const QString& user)
{
KolabSourceAccount *account = new KolabSourceAccount(this);
account->setHost(mHost, mPort);
account->setCredentials(mUsername, mPw);
- return new MigrateUserJob(account, this);
+ return account;
}
QStringList KolabSourceServer::getUserList()
diff --git a/migrationutility/sourceserver.h b/migrationutility/sourceserver.h
index 7d5bc01..5fe381c 100644
--- a/migrationutility/sourceserver.h
+++ b/migrationutility/sourceserver.h
@@ -23,7 +23,6 @@
#include <qsharedpointer.h>
#include <QStringList>
#include "sourceaccount.h"
-#include "migrateuserjob.h"
class SourceServer: public QObject
{
@@ -31,8 +30,7 @@ class SourceServer: public QObject
public:
explicit SourceServer(QObject* parent = 0);
// void setAdminCredentials(const QString &username, const QString &pw);
- virtual MigrateUserJob *createMigrationJob(const QString &user);
-// QSharedPointer<SourceAccount> getSourceAccount(const QString &username, const QString &pw);
+ virtual SourceAccount *getSourceAccount(const QString &user);
virtual QStringList getUserList();
void setSingleUser(const QString &);
protected:
@@ -46,7 +44,7 @@ class TestServer: public SourceServer
public:
explicit TestServer(QObject* parent = 0);
- virtual MigrateUserJob *createMigrationJob(const QString &user);
+ virtual SourceAccount *getSourceAccount(const QString &user);
virtual QStringList getUserList();
QStringList mUsers;
};
@@ -57,7 +55,7 @@ class KolabSourceServer: public SourceServer
public:
explicit KolabSourceServer(QObject* parent = 0);
- virtual MigrateUserJob *createMigrationJob(const QString &user);
+ virtual SourceAccount *getSourceAccount(const QString &user);
virtual QStringList getUserList();
void setHost(const QString &host, qint16 port);
diff --git a/migrationutility/uiproxy.h b/migrationutility/uiproxy.h
new file mode 100644
index 0000000..d91e95b
--- /dev/null
+++ b/migrationutility/uiproxy.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <kimap/sessionuiproxy.h>
+
+class UiProxy: public KIMAP::SessionUiProxy {
+ public:
+ bool ignoreSslError(const KSslErrorUiData& /*errorData*/) {
+ return true; //Necessary due to the untrusted certificate
+ }
+}; \ No newline at end of file