summaryrefslogtreecommitdiff
path: root/lib/kolabaccount.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kolabaccount.cpp')
-rw-r--r--lib/kolabaccount.cpp34
1 files changed, 27 insertions, 7 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;
}
}