summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-09-26 10:01:14 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-09-26 10:01:14 (GMT)
commit40c2ccd47eb90437c9e9889f1b8dce5b0a7f499a (patch)
treeec7c1ee0235c1b94abbf44bc7754817b3a407ffe
parentdd02093cedd7466180295fe70953614735dec651 (diff)
downloadkolab-utils-40c2ccd47eb90437c9e9889f1b8dce5b0a7f499a.tar.gz
We can query mailboxes
-rw-r--r--CMakeLists.txt2
-rw-r--r--fbdaemon/CMakeLists.txt1
-rw-r--r--fbdaemon/fbcoordinator.cpp32
-rw-r--r--jobs/CMakeLists.txt1
-rw-r--r--jobs/getuserlistjob.cpp (renamed from fbdaemon/getuserlistjob.cpp)125
-rw-r--r--jobs/getuserlistjob.h (renamed from fbdaemon/getuserlistjob.h)16
-rw-r--r--migrationutility/CMakeLists.txt2
-rw-r--r--migrationutility/main.cpp24
-rw-r--r--migrationutility/migratefolderjob.cpp1
-rw-r--r--migrationutility/migrateuserjob.cpp2
-rw-r--r--migrationutility/sourceaccount.cpp109
-rw-r--r--migrationutility/sourceaccount.h31
-rw-r--r--migrationutility/sourceserver.cpp67
-rw-r--r--migrationutility/sourceserver.h15
14 files changed, 286 insertions, 142 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ddabff0..6c6f550 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,7 @@ QT4_WRAP_CPP(JOB_MOC
${CMAKE_CURRENT_SOURCE_DIR}/jobs/messagemodifyjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/fetchmessagesjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/setupkolabfoldersjob.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/jobs/getuserlistjob.h
)
set( JOBS_SRCS ${JOBS_SRCS} ${JOB_MOC} )
@@ -83,7 +84,6 @@ QT4_WRAP_CPP(FB_MOC
fbdaemon/fbcoordinator.h
fbdaemon/fbgeneratorjob.h
fbdaemon/generatefbjob.h
- fbdaemon/getuserlistjob.h
fbdaemon/kolabjob.h
fbdaemon/fbaggregatorjob.h
)
diff --git a/fbdaemon/CMakeLists.txt b/fbdaemon/CMakeLists.txt
index d649e34..df5c2fa 100644
--- a/fbdaemon/CMakeLists.txt
+++ b/fbdaemon/CMakeLists.txt
@@ -5,7 +5,6 @@ set (FBDAEMON_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/fbgeneratorjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/generatefbjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/settings.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/getuserlistjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kolabjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fbaggregatorjob.cpp
PARENT_SCOPE)
diff --git a/fbdaemon/fbcoordinator.cpp b/fbdaemon/fbcoordinator.cpp
index 72256a5..86da467 100644
--- a/fbdaemon/fbcoordinator.cpp
+++ b/fbdaemon/fbcoordinator.cpp
@@ -19,10 +19,12 @@
#include "fbcoordinator.h"
#include "fbgeneratorjob.h"
#include "settings.h"
-#include "getuserlistjob.h"
+#include <jobs/getuserlistjob.h>
#include "fbaggregatorjob.h"
+#include "authenticationjob.h"
#include <kolab/errorhandler.h>
#include <jobs/sequentialcompositejob.h>
+#include <kimap/logoutjob.h>
FBCoordinator::FBCoordinator(QObject* parent)
: QObject(parent),
@@ -33,6 +35,14 @@ FBCoordinator::FBCoordinator(QObject* parent)
//TODO get user from job (trigger)
}
+class UiProxy: public KIMAP::SessionUiProxy {
+ public:
+ bool ignoreSslError(const KSslErrorUiData& errorData) {
+// Warning() << "Error during ssl";
+ return true;
+ }
+};
+
void FBCoordinator::generateForAllUsers(const QString &domain)
{
if (!mUserQueue.isEmpty()) {
@@ -43,10 +53,26 @@ void FBCoordinator::generateForAllUsers(const QString &domain)
mTimerIsRunning = true;
qint16 port;
const QString server = Settings::instance().getServerUri(port);
- GetUserListJob *getUsersJob = new GetUserListJob(server, port, this);
+ SequentialCompositeJob *sequentialJob = new SequentialCompositeJob(true, this);
+ //TODO test if that still works
+ KIMAP::Session *mSession = new KIMAP::Session( server, port, this );
+ mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
+// QObject::connect( mSession, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)),
+// this, SLOT(onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State)) );
+
+ AuthenticationJob *authJob = new AuthenticationJob(mSession, this);
+ sequentialJob->addSubjob(authJob);
+
+ GetUserListJob *getUsersJob = new GetUserListJob(mSession, this);
getUsersJob->setFilterDomain(domain);
+ sequentialJob->addSubjob(getUsersJob);
+ //FIXME use sequentialJob result (abort in case of failure)
connect(getUsersJob, SIGNAL(result(KJob*)), this, SLOT(onGotUserList(KJob*)));
- getUsersJob->start();
+
+ KIMAP::LogoutJob *logoutjob = new KIMAP::LogoutJob(mSession);
+ sequentialJob->addSubjob(logoutjob);
+
+ sequentialJob->start();
}
void FBCoordinator::onGotUserList(KJob *job)
diff --git a/jobs/CMakeLists.txt b/jobs/CMakeLists.txt
index 3d849cb..a9796ef 100644
--- a/jobs/CMakeLists.txt
+++ b/jobs/CMakeLists.txt
@@ -5,5 +5,6 @@ set (JOBS_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/messagemodifyjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fetchmessagesjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/setupkolabfoldersjob.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/getuserlistjob.cpp
PARENT_SCOPE)
diff --git a/fbdaemon/getuserlistjob.cpp b/jobs/getuserlistjob.cpp
index 0a3dac0..3e0b561 100644
--- a/fbdaemon/getuserlistjob.cpp
+++ b/jobs/getuserlistjob.cpp
@@ -16,31 +16,16 @@
*/
#include "getuserlistjob.h"
-#include "authenticationjob.h"
#include <kimap/listjob.h>
#include <kimap/selectjob.h>
#include <kimap/namespacejob.h>
-#include <kimap/logoutjob.h>
#include <kolab/errorhandler.h>
-class UiProxy: public KIMAP::SessionUiProxy {
- public:
- bool ignoreSslError(const KSslErrorUiData& errorData) {
-// Warning() << "Error during ssl";
- return true;
- }
-};
-GetUserListJob::GetUserListJob(const QString& hostName, qint16 port, QObject* parent)
+GetUserListJob::GetUserListJob(KIMAP::Session *session, QObject* parent)
: KJob(parent),
- mHostName(hostName),
- mPort(port),
- mSession(new KIMAP::Session( hostName, port, this ))
+ mSession(session)
{
- mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
- QObject::connect( mSession, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)),
- this, SLOT(onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State)) );
- connect(mSession, SIGNAL(destroyed(QObject*)), this, SLOT(onDone()));
}
void GetUserListJob::setFilterDomain(const QString &domain)
@@ -48,39 +33,8 @@ void GetUserListJob::setFilterDomain(const QString &domain)
mFilterDomain = domain;
}
-
-void GetUserListJob::onSessionStateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState)
-{
- if (newState == KIMAP::Session::Disconnected && oldState != KIMAP::Session::Disconnected) {
- Warning() << "lost connenction";
-// emitResult();
- }
-}
-
void GetUserListJob::start()
{
- AuthenticationJob *job = new AuthenticationJob(mSession, this);
- QObject::connect( job, SIGNAL(result(KJob*)),
- this, SLOT(onAuthDone(KJob*)) );
- job->start();
-}
-
-void GetUserListJob::onAuthDone(KJob *job)
-{
- if ( job->error() ) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- logout();
- return;
- }
- Debug() << "login successful";
-
-// KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
-// selectJob->setMailBox(QLatin1String("user"));
-// selectJob->setOpenReadOnly(true);
-// QObject::connect(selectJob, SIGNAL(result(KJob*)), this, SLOT(onSelectDone(KJob*)));
-// selectJob->start();
-
// KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession );
// QObject::connect( nsJob, SIGNAL(result(KJob*)), SLOT(onNamespacesTestDone(KJob*)));
// nsJob->start();
@@ -98,36 +52,22 @@ void GetUserListJob::onAuthDone(KJob *job)
QObject::connect( listJob, SIGNAL(result(KJob*)),
this, SLOT(onListDone(KJob*)) );
listJob->start();
-
-}
-
-void GetUserListJob::onNamespacesTestDone(KJob *job)
-{
- KIMAP::NamespaceJob *nsJob = qobject_cast<KIMAP::NamespaceJob*>( job );
- Q_ASSERT(nsJob);
- foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->personalNamespaces()) {
- Debug() << "personal " << desc.name;
- }
- foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->userNamespaces()) {
- Debug() << "user " << desc.name << desc.separator;
- }
- foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->sharedNamespaces()) {
- Debug() << "shared " << desc.name;
- }
}
-
-void GetUserListJob::onSelectDone(KJob *job)
-{
- if ( job->error() ) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- logout();
- return;
- }
-
-
-}
+// void GetUserListJob::onNamespacesTestDone(KJob *job)
+// {
+// KIMAP::NamespaceJob *nsJob = qobject_cast<KIMAP::NamespaceJob*>( job );
+// Q_ASSERT(nsJob);
+// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->personalNamespaces()) {
+// Debug() << "personal " << desc.name;
+// }
+// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->userNamespaces()) {
+// Debug() << "user " << desc.name << desc.separator;
+// }
+// foreach (const KIMAP::MailBoxDescriptor &desc, nsJob->sharedNamespaces()) {
+// Debug() << "shared " << desc.name;
+// }
+// }
void GetUserListJob::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
@@ -157,41 +97,14 @@ void GetUserListJob::onListDone(KJob *job)
if ( job->error() ) {
Warning() << job->errorString();
setError(KJob::UserDefinedError);
- logout();
+ emitResult();
return;
}
-// Debug() << "list successful";
- logout();
+ Debug() << "list successful";
+ emitResult();
}
QStringList GetUserListJob::getUserList() const
{
return mNames;
}
-
-
-void GetUserListJob::logout()
-{
-// Debug() << "logging out";
- KIMAP::LogoutJob *job = new KIMAP::LogoutJob(mSession);
- connect(job, SIGNAL(result(KJob*)), this, SLOT(onLogoutDone(KJob*)));
- job->start();
-}
-
-void GetUserListJob::onLogoutDone(KJob *job )
-{
-// Debug() << "logout done";
- if ( job->error() ) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- }
- mSession->close();
- mSession->deleteLater();
- mSession = 0;
-}
-
-void GetUserListJob::onDone()
-{
- Debug() << "Got user list";
- emitResult();
-}
diff --git a/fbdaemon/getuserlistjob.h b/jobs/getuserlistjob.h
index 6f21042..399b1ec 100644
--- a/fbdaemon/getuserlistjob.h
+++ b/jobs/getuserlistjob.h
@@ -26,30 +26,20 @@ class GetUserListJob: public KJob
{
Q_OBJECT
public:
- explicit GetUserListJob(const QString &hostName, qint16 port, QObject* parent = 0);
+ explicit GetUserListJob(KIMAP::Session* session, QObject* parent = 0);
virtual void start();
QStringList getUserList() const;
void setFilterDomain(const QString &);
-private Q_SLOTS:
- void onSessionStateChanged(KIMAP::Session::State newState, KIMAP::Session::State oldState);
- void onAuthDone(KJob*);
- void onLogoutDone(KJob*);
- void onDone();
private:
- void logout();
- QString mHostName;
- qint16 mPort;
QString mFilterDomain;
-
KIMAP::Session *mSession;
QStringList mNames;
-public slots:
+private slots:
void onListDone(KJob*);
void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &, const QList<QList<QByteArray> > &);
- void onSelectDone(KJob*);
- void onNamespacesTestDone(KJob*);
+// void onNamespacesTestDone(KJob*);
};
#endif // GETUSERLISTJOB_H
diff --git a/migrationutility/CMakeLists.txt b/migrationutility/CMakeLists.txt
index b14578d..235bf9c 100644
--- a/migrationutility/CMakeLists.txt
+++ b/migrationutility/CMakeLists.txt
@@ -36,4 +36,4 @@ install(TARGETS kolab-migration
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
)
-add_subdirectory(tests) \ No newline at end of file
+# add_subdirectory(tests) \ No newline at end of file
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 476baaf..79365cf 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -37,20 +37,26 @@ int main(int argc, char *argv[])
KCmdLineArgs::init(argc, argv, "migrationutility", "migrationutility",ki18n("migrationutility"), "0.1");
KCmdLineOptions options;
- options.add("u").add("user <loginname>", ki18n("Username for IMAP Account"));
- options.add("y").add("proxyauth <loginname>", ki18n("Username to be used for authentication together with password (optional, works with PLAIN/SASL authentication)"));
- options.add("p").add("password <password>", ki18n("Password for IMAP Account"));
- options.add("P").add("port <port>", ki18n("Port to be used on IMAP Server"), "143");
- options.add("e").add("encrypt <mode>", ki18n("Encryption mode to be used (NONE, TLS, SSL)"), "TLS");
- options.add("t").add("type <type>", ki18n("force the type (EVENT, TODO, JOURNAL, CONTACT). Applies only when upgrading a single file or a specific folder."));
- 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"));
+ options.add("from <host>", ki18n("Username for IMAP Account"));
+ options.add("from-port <port>", ki18n("Port to be used on IMAP Server"), "143");
+ 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("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"));
KCmdLineArgs::addCmdLineOptions( options );
QCoreApplication app(argc, argv);
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
- CoordinationJob *job = new CoordinationJob(new SourceServer(&app), &app);
+ KolabSourceServer *sourceServer = new KolabSourceServer(&app);
+// sourceServer->setHost(args->getOption("from"), args->getOption("from-port").toInt());
+ sourceServer->setHost("test.kolab.org", 143);
+ sourceServer->setAdminCredentials("admin@kolab.org", "pw");
+ sourceServer->setSingleUser("user@kolab.org");
+ CoordinationJob *job = new CoordinationJob(sourceServer, &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 d03b82b..84df5cd 100644
--- a/migrationutility/migratefolderjob.cpp
+++ b/migrationutility/migratefolderjob.cpp
@@ -16,6 +16,7 @@
*/
#include "migratefolderjob.h"
+#include <kolab/errorhandler.h>
MigrateFolderJob::MigrateFolderJob(const QString &folder, SourceAccount* sourceAccount, QObject* parent)
: mSourceAccount(sourceAccount),
diff --git a/migrationutility/migrateuserjob.cpp b/migrationutility/migrateuserjob.cpp
index d6fac70..99feac0 100644
--- a/migrationutility/migrateuserjob.cpp
+++ b/migrationutility/migrateuserjob.cpp
@@ -17,6 +17,7 @@
#include "migrateuserjob.h"
#include "migratefolderjob.h"
+#include <kolab/errorhandler.h>
MigrateUserJob::MigrateUserJob(SourceAccount *sourceAccount, QObject* parent)
: KJob(parent),
@@ -36,6 +37,7 @@ void MigrateUserJob::receivedFolderList(const QStringList &folders)
MigrateFolderJob *job = new MigrateFolderJob(folder, mSourceAccount, this);
job->exec();
}
+ mSourceAccount->logout();
emitResult();
}
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index 60d2bbc..11affb0 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -16,6 +16,11 @@
*/
#include "sourceaccount.h"
+#include <jobs/fetchmessagesjob.h>
+#include <kimap/session.h>
+#include <kimap/listjob.h>
+#include <kimap/logoutjob.h>
+#include <kolab/errorhandler.h>
SourceAccount::SourceAccount(QObject* parent)
: QObject(parent)
@@ -33,6 +38,12 @@ void SourceAccount::getObjects(const QString& folder)
}
+void SourceAccount::logout()
+{
+
+}
+
+
TestAccount::TestAccount(QObject* parent)
{
mFolderList << QLatin1String("folder1");
@@ -47,8 +58,106 @@ QStringList TestAccount::lookupFolderList()
void TestAccount::getObjects(const QString& folder)
{
+ Debug() << folder;
Q_ASSERT(mFolderList.removeAll(folder) == 1);
}
+//--------------------------------------------------------------
+
+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),
+ mSession(0),
+ mEncryptionMode(KIMAP::LoginJob::TlsV1),
+ mAuthenticationMode(KIMAP::LoginJob::Plain)
+{
+
+}
+
+void KolabSourceAccount::setHost(const QString& host, qint16 port)
+{
+ mHost = host;
+ mPort = port;
+}
+
+void KolabSourceAccount::setCredentials(const QString& username, const QString& pw)
+{
+ mUsername = username;
+ mPw = pw;
+}
+
+void KolabSourceAccount::init()
+{
+
+ if (mSession) {
+ return;
+ }
+ 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 );
+ loginJob->setEncryptionMode( mEncryptionMode );
+ loginJob->setAuthenticationMode( mAuthenticationMode );
+ loginJob->exec();
+
+ if ( loginJob->error() ) {
+ Warning() << "Failed to login: " << loginJob->errorString();
+ } else {
+ Debug() << "authentication successful";
+ }
+
+ KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
+ listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
+ //listJob->setQueriedNamespaces(); //FIXME no shared namespaces
+ 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);
+ }
+ return mailboxes;
+}
+
+void KolabSourceAccount::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
+{
+ mMailboxes.append(descriptors);
+}
+
+void KolabSourceAccount::getObjects(const QString& folder)
+{
+ Debug() << folder;
+ FetchMessagesJob *fetchJob = new FetchMessagesJob(folder, mSession, this);
+ fetchJob->exec();
+ Debug() << fetchJob->getMessages().size();
+}
+
+void KolabSourceAccount::logout()
+{
+ KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(mSession);
+ logoutJob->exec();
+ mSession->close();
+ mSession->deleteLater();
+ mSession = 0;
+ Debug() << "logout done";
+}
// #include "sourceaccount.moc"
diff --git a/migrationutility/sourceaccount.h b/migrationutility/sourceaccount.h
index 60c8bfe..1a62de5 100644
--- a/migrationutility/sourceaccount.h
+++ b/migrationutility/sourceaccount.h
@@ -20,6 +20,8 @@
#include <QObject>
#include <QStringList>
+#include <kimap/loginjob.h>
+#include <kimap/listjob.h>
class SourceAccount: public QObject
{
@@ -29,6 +31,7 @@ public:
virtual QStringList lookupFolderList();
virtual void getObjects(const QString &folder);
+ virtual void logout();
signals:
void folderList(const QStringList &);
// FindFoldersJob *getFolderList();
@@ -47,4 +50,32 @@ public:
QStringList mFolderList;
};
+
+class KolabSourceAccount: public SourceAccount
+{
+ Q_OBJECT
+public:
+ explicit KolabSourceAccount(QObject* parent = 0);
+ virtual QStringList lookupFolderList();
+ virtual void getObjects(const QString &folder);
+
+ void setHost(const QString &host, qint16 port);
+ void setCredentials(const QString &username, const QString &pw);
+
+ void logout();
+private slots:
+
+ void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
+private:
+ void init();
+ KIMAP::Session *mSession;
+ QString mHost;
+ int mPort;
+ QString mUsername;
+ QString mPw;
+ KIMAP::LoginJob::EncryptionMode mEncryptionMode;
+ KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
+ QList<KIMAP::MailBoxDescriptor> mMailboxes;
+};
+
#endif // SOURCEACCOUNT_H
diff --git a/migrationutility/sourceserver.cpp b/migrationutility/sourceserver.cpp
index 94deefa..61598bf 100644
--- a/migrationutility/sourceserver.cpp
+++ b/migrationutility/sourceserver.cpp
@@ -18,6 +18,8 @@
#include "sourceserver.h"
#include <commonconversion.h>
#include <kimap/listjob.h>
+#include <kimap/logoutjob.h>
+#include <kolab/errorhandler.h>
SourceServer::SourceServer(QObject* parent): QObject(parent)
@@ -35,6 +37,12 @@ QStringList SourceServer::getUserList()
return QStringList();
}
+void SourceServer::setSingleUser(const QString &user)
+{
+ mExplicitUsers.append(user);
+}
+
+
TestServer::TestServer(QObject* parent)
: SourceServer(parent)
@@ -65,19 +73,42 @@ class UiProxy: public KIMAP::SessionUiProxy {
};
KolabSourceServer::KolabSourceServer(QObject* parent)
+: SourceServer(parent),
+ mSession(0),
+ mEncryptionMode(KIMAP::LoginJob::TlsV1),
+ mAuthenticationMode(KIMAP::LoginJob::Plain)
+{
+
+}
+
+void KolabSourceServer::setHost(const QString& host, qint16 port)
{
+ mHost = host;
+ mPort = port;
+}
+void KolabSourceServer::setAdminCredentials(const QString& username, const QString& pw)
+{
+ mUsername = username;
+ mPw = pw;
}
MigrateUserJob* KolabSourceServer::createMigrationJob(const QString& user)
{
- return 0;
+ KolabSourceAccount *account = new KolabSourceAccount(this);
+ account->setHost(mHost, mPort);
+ account->setCredentials(mUsername, mPw);
+ return new MigrateUserJob(account, this);
}
QStringList KolabSourceServer::getUserList()
{
+ if (!mExplicitUsers.isEmpty()) {
+ return mExplicitUsers;
+ }
+ //TODO split into retrieve user list
- KIMAP::Session *mSession = new KIMAP::Session( mHostName, mPort, this );
+ mSession = new KIMAP::Session( mHost, mPort, this );
mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
// QObject::connect( mSession, SIGNAL(stateChanged(KIMAP::Session::State,KIMAP::Session::State)),
// this, SLOT(onSessionStateChanged(KIMAP::Session::State,KIMAP::Session::State)) );
@@ -86,27 +117,47 @@ QStringList KolabSourceServer::getUserList()
// if (!proxyauth.isEmpty()) {
// loginJob->setAuthorizationName(proxyauth);
// }
- loginJob->setUserName( username );
- loginJob->setPassword( pw );
- loginJob->setEncryptionMode( encryptionMode );
+ loginJob->setUserName( mUsername );
+ loginJob->setPassword( mPw );
+ loginJob->setEncryptionMode( mEncryptionMode );
// if (encryptionMode != KIMAP::LoginJob::Unencrypted) {
// m_requireEncryption = true;
// } else {
// m_requireEncryption = false;
// }
- loginJob->setAuthenticationMode( authenticationMode );
-/*
- QObject::connect( loginJob, SIGNAL(result(KJob*)),
+ loginJob->setAuthenticationMode( mAuthenticationMode );
+/* Object::connect( loginJob, SIGNAL(result(KJob*)),
this, SLOT(onLoginDone(KJob*)) );
loginJob->start(); */
loginJob->exec();
+
+
+ if ( loginJob->error() ) {
+ Warning() << "Failed to login: " << loginJob->errorString();
+ } else {
+ Debug() << "authentication successful";
+ }
// KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
// listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
// listJob->exec();
// listJob->mailBoxes();
+
+ logout();
+
+ return QStringList();
}
+void KolabSourceServer::logout()
+{
+ Q_ASSERT(mSession);
+ KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(mSession);
+ logoutJob->exec();
+ mSession->close();
+ mSession->deleteLater();
+ mSession = 0;
+ Debug() << "logout done";
+}
// #include "moc_sourceserver.cxx"
// #include "sourceserver.moc"
diff --git a/migrationutility/sourceserver.h b/migrationutility/sourceserver.h
index fb3caa0..7d5bc01 100644
--- a/migrationutility/sourceserver.h
+++ b/migrationutility/sourceserver.h
@@ -34,6 +34,9 @@ public:
virtual MigrateUserJob *createMigrationJob(const QString &user);
// QSharedPointer<SourceAccount> getSourceAccount(const QString &username, const QString &pw);
virtual QStringList getUserList();
+ void setSingleUser(const QString &);
+protected:
+ QStringList mExplicitUsers;
};
@@ -56,6 +59,18 @@ public:
virtual MigrateUserJob *createMigrationJob(const QString &user);
virtual QStringList getUserList();
+
+ void setHost(const QString &host, qint16 port);
+ void setAdminCredentials(const QString &username, const QString &pw);
+private:
+ void logout();
+ KIMAP::Session *mSession;
+ QString mHost;
+ int mPort;
+ QString mUsername;
+ QString mPw;
+ KIMAP::LoginJob::EncryptionMode mEncryptionMode;
+ KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
};
#endif // SOURCESERVER_H