summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-17 02:27:39 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-17 02:27:39 (GMT)
commit0d1e249c7cf6aaa7263e25e49674bd90fe971b17 (patch)
treece87aa77b7f12fc7a09ccd0d35f721eb7accc414
parentfd55973ddccff9ed5feee1f488c218c50f517f62 (diff)
downloadkolab-utils-0d1e249c7cf6aaa7263e25e49674bd90fe971b17.tar.gz
Fixed the replaceString extraction, support for wildcards and prefixes (prefix/*).
-rw-r--r--lib/kolabaccount.cpp34
-rw-r--r--migrationutility/main.cpp2
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/kolabaccount.cpp b/lib/kolabaccount.cpp
index 4c03524..394a737 100644
--- a/lib/kolabaccount.cpp
+++ b/lib/kolabaccount.cpp
@@ -415,17 +415,31 @@ QStringList KolabAccount::lookupFolderList()
return mailboxes;
}
+static int findSeparator(const QString &trans)
+{
+ if (trans.size() < 3) {
+ return -1;
+ }
+ //Find unescaped separator
+ for (int i = 2; i < trans.size(); i++) {
+ if (trans[i] == '/' && trans[i-1] != '\\') {
+ return i;
+ }
+ }
+ return -1;
+}
+
void KolabAccount::setRegextrans(const QStringList &regextrans)
{
foreach (const QString &transformation, regextrans) {
- if (!transformation.startsWith("s/") || !transformation.endsWith("/")) {
+ const int separator = findSeparator(transformation);
+ if (separator < 0|| !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);
+ const QString searchString = transformation.mid(2, separator - 2).replace("\\/", "/");
+ const QString replaceString = transformation.mid(separator + 1, transformation.length() - separator - 2).replace("\\/", "/");
+ Debug() << transformation;
Debug() << "s/" << searchString << "/" << replaceString;
mRegextrans.insert(searchString, replaceString);
}
@@ -435,8 +449,14 @@ QString KolabAccount::applyTargetFolderTransformations(const QString &folder) co
{
QString newName(folder);
foreach (const QString &searchString, mRegextrans.keys()) {
- if (folder.contains(searchString)) {
- newName = mRegextrans.value(searchString);
+ QRegExp exp(searchString, Qt::CaseSensitive, QRegExp::WildcardUnix);
+ if (exp.exactMatch(folder)) {
+ const QString replaceString = mRegextrans.value(searchString);
+ if (replaceString.endsWith("*")) {
+ newName = replaceString.left(replaceString.size()-1) + folder;
+ } else {
+ newName = replaceString;
+ }
break;
}
}
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index 50d4cc4..ef4dd6a 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -90,7 +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("regextrans2 <s/MATCH/REPLACE/>", ki18n("Allows to translate target folder names. Use --dry to figure out the names that are used by default. Wilcards can be used in the MATCH part, and prefixes can be created in the REPLACE part using \"prefix/*\"."));
options.add("from <type>", ki18n("Source host type (kolab2, kolab3, exchangeimap, google)"));