summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-04 09:13:13 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-04 09:13:13 (GMT)
commit295c5d4e2bd7cf415927b514fac18edc424a5f02 (patch)
tree2f16b23607c02fe1c692c9362e3e97d0bd6cd0e5
parent143f8b8ecb35118c7ed19564dc36b2f7918be61f (diff)
downloadkolab-utils-295c5d4e2bd7cf415927b514fac18edc424a5f02.tar.gz
Added dry-run
-rw-r--r--migrationutility/kolabaccount.cpp24
-rw-r--r--migrationutility/kolabaccount.h2
-rw-r--r--migrationutility/kolabserver.cpp10
-rw-r--r--migrationutility/kolabserver.h2
-rw-r--r--migrationutility/main.cpp4
5 files changed, 40 insertions, 2 deletions
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
index ea32799..08c5b64 100644
--- a/migrationutility/kolabaccount.cpp
+++ b/migrationutility/kolabaccount.cpp
@@ -39,7 +39,8 @@ KolabAccount::KolabAccount(QObject* parent)
: QObject(parent),
mSession(0),
mEncryptionMode(KIMAP::LoginJob::TlsV1),
- mAuthenticationMode(KIMAP::LoginJob::Plain)
+ mAuthenticationMode(KIMAP::LoginJob::Plain),
+ mDryRun(false)
{
}
@@ -56,6 +57,11 @@ void KolabAccount::setCredentials(const QString& username, const QString& pw)
mPw = pw;
}
+void KolabAccount::setDryRun(bool enable)
+{
+ mDryRun = enable;
+}
+
void KolabAccount::init()
{
if (mSession) {
@@ -103,6 +109,10 @@ const char* FlagRecent2 = "\\Recent";
void KolabAccount::appendObject(Object obj, const QString& folder)
{
+ if (mDryRun) {
+ Debug() << "append object in folder: " << folder;
+ return;
+ }
Q_ASSERT(mFolders.contains(folder));
KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
job->setMailBox( folder );
@@ -157,6 +167,10 @@ void KolabAccount::cleanAccount()
selectJob->setMailBox(desc.name);
selectJob->exec();
const int messageCount = selectJob->messageCount();
+ if (mDryRun) {
+ Debug() << "removing folder: " << desc.name << messageCount;
+ continue;
+ }
if (messageCount > 0) {
KIMAP::StoreJob *storeJob = new KIMAP::StoreJob(mSession);
@@ -198,6 +212,10 @@ void KolabAccount::createFolder(const QString &name, const QByteArray &annotatio
Warning() << "folder is already existing: " << name;
return;
}
+ if (mDryRun) {
+ Debug() << "creating folder: " << name << annotation;
+ return;
+ }
KIMAP::CreateJob *createJob = new KIMAP::CreateJob(mSession);
createJob->setMailBox(name);
@@ -230,6 +248,10 @@ void KolabAccount::createFolder(const QString& name, Kolab::FolderType folderTyp
void KolabAccount::setupFolders()
{
+ if (mDryRun) {
+ Debug() << "setup default folders";
+ return;
+ }
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();
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
index 7b93325..fb3e8c3 100644
--- a/migrationutility/kolabaccount.h
+++ b/migrationutility/kolabaccount.h
@@ -42,6 +42,7 @@ public:
void appendObject(Object obj, const QString &folder);
void createFolder(const QString &name, Kolab::FolderType folderType);
void createFolder(const QString &name, const QByteArray &annotation);
+ void setDryRun(bool);
void logout();
@@ -61,6 +62,7 @@ private:
QList<KIMAP::MailBoxDescriptor> mExcludedNamespaces;
QStringList mFolders;
QStringList mCapabilities;
+ bool mDryRun;
};
#endif // KOLABACCOUNT_H
diff --git a/migrationutility/kolabserver.cpp b/migrationutility/kolabserver.cpp
index fa7dd28..b4197c6 100644
--- a/migrationutility/kolabserver.cpp
+++ b/migrationutility/kolabserver.cpp
@@ -23,7 +23,8 @@ KolabServer::KolabServer(QObject* parent)
: QObject(parent),
mSession(0),
mEncryptionMode(KIMAP::LoginJob::TlsV1),
- mAuthenticationMode(KIMAP::LoginJob::Plain)
+ mAuthenticationMode(KIMAP::LoginJob::Plain),
+ mDryRun(false)
{
}
@@ -40,10 +41,17 @@ void KolabServer::setAdminCredentials(const QString& username, const QString& pw
mPw = pw;
}
+void KolabServer::setDryRun(bool enable)
+{
+ mDryRun = enable;
+}
+
+
KolabAccount* KolabServer::getAccount(const QString& user)
{
KolabAccount *account = new KolabAccount(this);
account->setHost(mHost, mPort);
account->setCredentials(user, mPw);
+ account->setDryRun(mDryRun);
return account;
}
diff --git a/migrationutility/kolabserver.h b/migrationutility/kolabserver.h
index 6762821..1c009ac 100644
--- a/migrationutility/kolabserver.h
+++ b/migrationutility/kolabserver.h
@@ -33,6 +33,7 @@ public:
void setHost(const QString &host, qint16 port);
void setAdminCredentials(const QString &username, const QString &pw);
+ void setDryRun(bool);
KolabAccount *getAccount(const QString &user);
private:
@@ -44,6 +45,7 @@ private:
QString mPw;
KIMAP::LoginJob::EncryptionMode mEncryptionMode;
KIMAP::LoginJob::AuthenticationMode mAuthenticationMode;
+ bool mDryRun;
};
#endif // KOLABSERVER_H
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 7eea659..d887998 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -38,6 +38,7 @@ int main(int argc, char *argv[])
KCmdLineArgs::init(argc, argv, "migrationutility", "migrationutility",ki18n("migrationutility"), "0.1");
KCmdLineOptions options;
+ options.add("dry", ki18n("Dry run, doesn't change anything on the server, but only prints what would be done (Use with care until this is well tested)."));
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"));
@@ -67,6 +68,9 @@ int main(int argc, char *argv[])
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"));
+ if (args->isSet("dry")) {
+ kolabServer->setDryRun(true);
+ }
CoordinationJob *job = new CoordinationJob(sourceServer, kolabServer, &app);
QObject::connect(job, SIGNAL(done()), &app, SLOT(quit()));