summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2012-10-05 12:11:17 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2012-10-05 12:11:17 (GMT)
commita5403604dc9e090a7bd9baf43da9475683354f88 (patch)
treed655660d1a92465d1592263fe6a2782a0476d7db
parentfbd448e99d4d02a10e17baa36d0030ed877b7580 (diff)
downloadkolab-utils-a5403604dc9e090a7bd9baf43da9475683354f88.tar.gz
Various fixes:
* actually set metadata on folder * don't crash if we can't convert an object * abort migration if we coulnd't connect to the account *
-rw-r--r--migrationutility/kolabaccount.cpp67
-rw-r--r--migrationutility/kolabaccount.h5
-rw-r--r--migrationutility/kolabserver.cpp6
-rw-r--r--migrationutility/main.cpp1
-rw-r--r--migrationutility/sourceaccount.cpp4
5 files changed, 62 insertions, 21 deletions
diff --git a/migrationutility/kolabaccount.cpp b/migrationutility/kolabaccount.cpp
index 08c5b64..3924095 100644
--- a/migrationutility/kolabaccount.cpp
+++ b/migrationutility/kolabaccount.cpp
@@ -51,10 +51,11 @@ void KolabAccount::setHost(const QString& host, qint16 port)
mPort = port;
}
-void KolabAccount::setCredentials(const QString& username, const QString& pw)
+void KolabAccount::setCredentials(const QString& username, const QString& pw, const QString &authorizationName)
{
mUsername = username;
mPw = pw;
+ mAuthorizationName = authorizationName;
}
void KolabAccount::setDryRun(bool enable)
@@ -62,14 +63,17 @@ void KolabAccount::setDryRun(bool enable)
mDryRun = enable;
}
-void KolabAccount::init()
+bool KolabAccount::init()
{
if (mSession) {
- return;
+ return false;
}
mSession = new KIMAP::Session( mHost, mPort, this );
mSession->setUiProxy( KIMAP::SessionUiProxy::Ptr(new UiProxy()) );
KIMAP::LoginJob *loginJob = new KIMAP::LoginJob( mSession );
+ if (mAuthorizationName != mUsername) {
+ loginJob->setAuthorizationName(mAuthorizationName);
+ }
loginJob->setUserName( mUsername );
loginJob->setPassword( mPw );
loginJob->setEncryptionMode( mEncryptionMode );
@@ -77,11 +81,12 @@ void KolabAccount::init()
loginJob->exec();
if ( loginJob->error() ) {
- Warning() << "Failed to login: " << loginJob->errorString();
- return;
- } else {
- Debug() << "authentication successful";
+ Error() << "Failed to login: " << loginJob->errorString();
+ mSession->close();
+ return false;
}
+ Debug() << "authentication successful";
+
KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession);
capabilities->exec();
mCapabilities = capabilities->capabilities();
@@ -92,17 +97,18 @@ void KolabAccount::init()
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;
- }
+// 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;
+// }
}
+ return true;
}
const char* FlagRecent2 = "\\Recent";
@@ -114,6 +120,11 @@ void KolabAccount::appendObject(Object obj, const QString& folder)
return;
}
Q_ASSERT(mFolders.contains(folder));
+ if (!obj.message) {
+ Error() << "got empty message";
+ return;
+ }
+ Q_ASSERT(obj.message.get());
KIMAP::AppendJob *job = new KIMAP::AppendJob( mSession );
job->setMailBox( folder );
job->setContent( obj.message->encodedContent( true ) );
@@ -129,6 +140,7 @@ void KolabAccount::appendObject(Object obj, const QString& folder)
void KolabAccount::logout()
{
+ Q_ASSERT(mSession);
KIMAP::LogoutJob *logoutJob = new KIMAP::LogoutJob(mSession);
logoutJob->exec();
mSession->close();
@@ -141,13 +153,16 @@ const char* FlagDeleted2 = "\\Deleted";
void KolabAccount::cleanAccount()
{
- init();
+ Q_ASSERT(mSession);
KIMAP::ListJob *listJob = new KIMAP::ListJob(mSession);
listJob->setOption(KIMAP::ListJob::IncludeUnsubscribed);
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();
+ if (listJob->error()) {
+ Error() << listJob->errorString();
+ }
foreach (const KIMAP::MailBoxDescriptor &desc, mMailboxes) {
if (desc.name.contains(QLatin1String("inbox"), Qt::CaseInsensitive)) {
continue;
@@ -166,6 +181,9 @@ void KolabAccount::cleanAccount()
KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
selectJob->setMailBox(desc.name);
selectJob->exec();
+ if (selectJob->error()) {
+ Error() << selectJob->errorString();
+ }
const int messageCount = selectJob->messageCount();
if (mDryRun) {
Debug() << "removing folder: " << desc.name << messageCount;
@@ -178,9 +196,15 @@ void KolabAccount::cleanAccount()
storeJob->setFlags(KIMAP::MessageFlags() << FlagDeleted2);
storeJob->setSequenceSet( KIMAP::ImapSet( 1, messageCount ) );
storeJob->exec();
+ if (storeJob->error()) {
+ Error() << storeJob->errorString();
+ }
KIMAP::ExpungeJob *expungeJob = new KIMAP::ExpungeJob(mSession);
expungeJob->exec();
+ if (expungeJob->error()) {
+ Error() << expungeJob->errorString();
+ }
}
KIMAP::DeleteJob *deleteJob = new KIMAP::DeleteJob(mSession);
@@ -236,6 +260,10 @@ void KolabAccount::createFolder(const QString &name, const QByteArray &annotatio
setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
setMetadataJob->addMetaData( "value.shared", annotation );
}
+ setMetadataJob->exec();
+ if (setMetadataJob->error()) {
+ Error() << setMetadataJob->errorString();
+ }
mFolders.append(name);
}
@@ -258,6 +286,9 @@ void KolabAccount::setupFolders()
if (setupJob->error()) {
Error() << setupJob->errorString();
}
+ foreach (const QString &folder, setupJob->createdFolders().values()) {
+ mFolders.append(folder);
+ }
KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
selectJob->setMailBox(QString());
//TODO internationalize folder names
diff --git a/migrationutility/kolabaccount.h b/migrationutility/kolabaccount.h
index fb3e8c3..d2bdea8 100644
--- a/migrationutility/kolabaccount.h
+++ b/migrationutility/kolabaccount.h
@@ -35,7 +35,8 @@ public:
explicit KolabAccount(QObject* parent = 0);
void setHost(const QString &host, qint16 port);
- void setCredentials(const QString &username, const QString &pw);
+ void setCredentials(const QString &username, const QString &pw, const QString &authorizationName);
+ bool init();
void cleanAccount();
void setupFolders();
@@ -49,10 +50,10 @@ public:
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 mAuthorizationName;
QString mUsername;
QString mPw;
KIMAP::LoginJob::EncryptionMode mEncryptionMode;
diff --git a/migrationutility/kolabserver.cpp b/migrationutility/kolabserver.cpp
index b4197c6..e1cd5a5 100644
--- a/migrationutility/kolabserver.cpp
+++ b/migrationutility/kolabserver.cpp
@@ -51,7 +51,11 @@ KolabAccount* KolabServer::getAccount(const QString& user)
{
KolabAccount *account = new KolabAccount(this);
account->setHost(mHost, mPort);
- account->setCredentials(user, mPw);
+ account->setCredentials(user, mPw, mUsername);
account->setDryRun(mDryRun);
+ if (!account->init()) {
+ account->deleteLater();
+ return 0;
+ }
return account;
}
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 3410f6c..eb962b2 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -107,6 +107,7 @@ int main(int argc, char *argv[])
//app.exec();
if (Kolab::ErrorHandler::instance().error() >= Kolab::ErrorHandler::Error) {
+ Error() << Kolab::ErrorHandler::instance().errorMessage();
return -1;
}
return 0;
diff --git a/migrationutility/sourceaccount.cpp b/migrationutility/sourceaccount.cpp
index e239b17..f3074d2 100644
--- a/migrationutility/sourceaccount.cpp
+++ b/migrationutility/sourceaccount.cpp
@@ -190,6 +190,10 @@ QList<Object> KolabSourceAccount::getObjects(const QString& folder)
obj.message = msg;
}
obj.flags = fetchJob->getFlags(msg);
+ if (!obj.message) {
+ Error() << "got empty message";
+ continue;
+ }
messages.append(obj);
}
return messages;