summaryrefslogtreecommitdiff
path: root/fbdaemon
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 /fbdaemon
parentdd02093cedd7466180295fe70953614735dec651 (diff)
downloadkolab-utils-40c2ccd47eb90437c9e9889f1b8dce5b0a7f499a.tar.gz
We can query mailboxes
Diffstat (limited to 'fbdaemon')
-rw-r--r--fbdaemon/CMakeLists.txt1
-rw-r--r--fbdaemon/fbcoordinator.cpp32
-rw-r--r--fbdaemon/getuserlistjob.cpp197
-rw-r--r--fbdaemon/getuserlistjob.h55
4 files changed, 29 insertions, 256 deletions
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/fbdaemon/getuserlistjob.cpp b/fbdaemon/getuserlistjob.cpp
deleted file mode 100644
index 0a3dac0..0000000
--- a/fbdaemon/getuserlistjob.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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 "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)
-: KJob(parent),
- mHostName(hostName),
- mPort(port),
- mSession(new KIMAP::Session( hostName, 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)) );
- connect(mSession, SIGNAL(destroyed(QObject*)), this, SLOT(onDone()));
-}
-
-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();
-
- KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
- listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
-// KIMAP::MailBoxDescriptor desc;
-// desc.name = QLatin1String("user/");
-// desc.separator = QLatin1Char('/');
-// QList<KIMAP::MailBoxDescriptor> namespaces;
-// namespaces.append(desc);
-// listJob->setQueriedNamespaces(namespaces);
- QObject::connect( listJob, SIGNAL(mailBoxesReceived(QList<KIMAP::MailBoxDescriptor>,QList<QList<QByteArray> >)),
- this, SLOT(mailBoxesReceived(QList<KIMAP::MailBoxDescriptor>,QList<QList<QByteArray> >)));
- 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::mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags)
-{
- // For now we simply extract the name from: user/christian.mollekopf@klab.cc
- foreach (const KIMAP::MailBoxDescriptor &descriptor, descriptors) {
- //FIXME this contains to many assumptions about the server, maybe we can use the namespace result instead?
- if (!mFilterDomain.isEmpty() && !descriptor.name.contains(mFilterDomain)) {
- continue;
- }
-// int firstSep = descriptor.name.indexOf(QLatin1Char('/'));
- int secondSep = descriptor.name.indexOf(QLatin1Char('/'), 6);
- int index = descriptor.name.indexOf(QLatin1Char('@'), 6);
-// Debug() << secondSep << index << descriptor.name;
- if (descriptor.name.startsWith(QLatin1String("user/")) && (index >= 0) && (secondSep < 0)) {
- const QString name = descriptor.name.mid(5);
-// Debug() << name << descriptor.name;
- if (!mNames.contains(name)) {
- mNames.append(name);
- }
- }
- }
-}
-
-void GetUserListJob::onListDone(KJob *job)
-{
- if ( job->error() ) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- logout();
- return;
- }
-// Debug() << "list successful";
- logout();
-}
-
-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/fbdaemon/getuserlistjob.h
deleted file mode 100644
index 6f21042..0000000
--- a/fbdaemon/getuserlistjob.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 GETUSERLISTJOB_H
-#define GETUSERLISTJOB_H
-#include <kjob.h>
-#include <qstringlist.h>
-#include <kimap/session.h>
-#include <kimap/listjob.h>
-
-class GetUserListJob: public KJob
-{
- Q_OBJECT
-public:
- explicit GetUserListJob(const QString &hostName, qint16 port, 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:
- void onListDone(KJob*);
- void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &, const QList<QList<QByteArray> > &);
- void onSelectDone(KJob*);
- void onNamespacesTestDone(KJob*);
-};
-
-#endif // GETUSERLISTJOB_H