summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-16 22:17:23 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-16 22:17:23 (GMT)
commitc20c1408c4abace04b469509a2ffe0f1f1bc3845 (patch)
tree3b84848204c6a30e0e91299ef74624924b73d32e
parent34d3e8edb4c655360e8c464819d1c438ac23b2f9 (diff)
downloadkolab-utils-c20c1408c4abace04b469509a2ffe0f1f1bc3845.tar.gz
A simple regextrans2 option to translate target names.
-rw-r--r--lib/kolabaccount.cpp26
-rw-r--r--lib/kolabaccount.h10
-rw-r--r--migrationutility/kolabserver.cpp7
-rw-r--r--migrationutility/kolabserver.h3
-rw-r--r--migrationutility/main.cpp4
-rw-r--r--migrationutility/migratefolderjob.cpp4
6 files changed, 52 insertions, 2 deletions
diff --git a/lib/kolabaccount.cpp b/lib/kolabaccount.cpp
index a395f2f..5925fc5 100644
--- a/lib/kolabaccount.cpp
+++ b/lib/kolabaccount.cpp
@@ -415,3 +415,29 @@ QStringList KolabAccount::lookupFolderList()
return mailboxes;
}
+void KolabAccount::setRegextrans(const QStringList &regextrans)
+{
+ foreach (const QString &transformation, regextrans) {
+ if (!transformation.startsWith("s/") || !transformation.endsWith("/")) {
+ Warning() << "invalid transformation: " << transformation;
+ continue;
+ }
+ QString trans = transformation.mid(2, transformation.length() - 3);
+ const int separator = trans.indexOf("/");
+ const QString searchString = trans.left(separator);
+ const QString replaceString = trans.right(separator+1);
+ Debug() << "s/" << searchString << "/" << replaceString;
+ mRegextrans.insert(searchString, replaceString);
+ }
+}
+
+QString KolabAccount::applyTargetFolderTransformations(const QString &folder) const
+{
+ QString newName(folder);
+ foreach (const QString &searchString, mRegextrans.keys()) {
+ if (folder.contains(searchString)) {
+ return mRegextrans.value(searchString);
+ }
+ }
+ return newName;
+}
diff --git a/lib/kolabaccount.h b/lib/kolabaccount.h
index 4887370..ad28ac5 100644
--- a/lib/kolabaccount.h
+++ b/lib/kolabaccount.h
@@ -50,6 +50,7 @@ public:
void createFolder(const QString &name, const QByteArray &annotation);
void setDryRun(bool);
void setWipeTargetFolders(bool);
+ void setRegextrans(const QStringList &);
KJob *logout();
@@ -59,6 +60,14 @@ public:
void setVersion(Kolab::Version);
QString getUsername() const;
+
+ /**
+ * Applies any target folder name transformations.
+ * This includes:
+ * * user-specified regextrans2 transformations
+ * * normalizations to get a valid name according to the IMAP specification
+ */
+ QString applyTargetFolderTransformations(const QString &) const;
private slots:
void mailBoxesReceived(const QList<KIMAP::MailBoxDescriptor> &descriptors, const QList< QList< QByteArray > > &flags);
@@ -80,6 +89,7 @@ private:
bool mDryRun;
bool mWipeTargetFolders;
Kolab::Version mVersion;
+ QMap<QString, QString> mRegextrans;
};
#endif // KOLABACCOUNT_H
diff --git a/migrationutility/kolabserver.cpp b/migrationutility/kolabserver.cpp
index 01a54b0..927eec9 100644
--- a/migrationutility/kolabserver.cpp
+++ b/migrationutility/kolabserver.cpp
@@ -72,6 +72,12 @@ void KolabServer::setWipeTargetFolders(bool enable)
mWipeTargetFolders = enable;
}
+void KolabServer::setRegextrans(const QStringList &regextrans)
+{
+ Debug() << "Regextrans: " << regextrans;
+ mRegextrans = regextrans;
+}
+
KolabAccount* KolabServer::getAccount(const QString& user)
{
KolabAccount *account = new KolabAccount(this);
@@ -85,6 +91,7 @@ KolabAccount* KolabServer::getAccount(const QString& user)
account->setDryRun(mDryRun);
account->setWipeTargetFolders(mWipeTargetFolders);
account->setVersion(mVersion);
+ account->setRegextrans(mRegextrans);
if (!account->init()) {
account->deleteLater();
return 0;
diff --git a/migrationutility/kolabserver.h b/migrationutility/kolabserver.h
index c2c692e..f5e6b8e 100644
--- a/migrationutility/kolabserver.h
+++ b/migrationutility/kolabserver.h
@@ -18,6 +18,7 @@
#ifndef KOLABSERVER_H
#define KOLABSERVER_H
#include <QObject>
+#include <QStringList>
#include <kolabobject.h>
#include <kimap/loginjob.h>
@@ -35,6 +36,7 @@ public:
void addTargetUserForSource(const QString &sourceUser, const QString &targetUser);
void setDryRun(bool);
void setWipeTargetFolders(bool);
+ void setRegextrans(const QStringList &);
KolabAccount *getAccount(const QString &user);
void setVersion(Kolab::Version);
@@ -49,6 +51,7 @@ private:
bool mWipeTargetFolders;
Kolab::Version mVersion;
QHash<QString, QString> mTargetForSourceUser;
+ QStringList mRegextrans;
};
#endif // KOLABSERVER_H
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 2e109d8..50d4cc4 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -90,6 +90,7 @@ int main(int argc, char *argv[])
options.add("statefile", ki18n("Resume from migration-state file"), "/tmp/kolabmigration.state");
options.add("skipFolder <sourcefolder>", ki18n("Source-folders to skip. Uses a simple \"contains\"-filter. Can be stated multiple times."));
options.add("objectType <type>", ki18n("Objects types to migrate (MAIL, CONTACTS, EVENTS, TASKS). By default all types are migrated. Can be stated multiple times. Currently only implemented for the google source type."));
+ options.add("regextrans2 <s/MATCH/REPLACE/>", ki18n("Allows to translate target folder names. Use --dry to figure out the names that are used by default."));
options.add("from <type>", ki18n("Source host type (kolab2, kolab3, exchangeimap, google)"));
@@ -212,6 +213,9 @@ int main(int argc, char *argv[])
if (args->isSet("wipeTargetFolders")) {
kolabServer->setWipeTargetFolders(true);
}
+ if (!args->getOptionList("regextrans2").isEmpty()) {
+ kolabServer->setRegextrans(args->getOptionList("regextrans2"));
+ }
if (args->isSet("statefile")) {
sourceServer->setStatefile(args->getOption("statefile"));
}
diff --git a/migrationutility/migratefolderjob.cpp b/migrationutility/migratefolderjob.cpp
index bd77b42..1313732 100644
--- a/migrationutility/migratefolderjob.cpp
+++ b/migrationutility/migratefolderjob.cpp
@@ -41,8 +41,8 @@ void MigrateFolderJob::doStart()
{
Debug() << "migrating " << mFolder;
const QPair<Kolab::FolderType, QString> &targetFolder = mSourceAccount->translateFolder(mFolder);
- mTargetFolder = targetFolder.second;
- mKolabAccount->createFolder(targetFolder.second, targetFolder.first);
+ mTargetFolder = mKolabAccount->applyTargetFolderTransformations(targetFolder.second);
+ mKolabAccount->createFolder(mTargetFolder, targetFolder.first);
FetchObjectsJob *fetchJob = mSourceAccount->fetchObjects(mFolder);
if (!fetchJob) {