Browse code

[replication] BM-15119 Fix: quote mailbox names correctly when listing subscriptions. Prevents sync_client segfault

Thomas Cataldo authored on 13/08/2019 11:27:19
Showing 3 changed files
... ...
@@ -29,6 +29,7 @@ import net.bluemind.backend.cyrus.replication.server.ReplicationFrame;
29 29
 import net.bluemind.backend.cyrus.replication.server.ReplicationSession;
30 30
 import net.bluemind.backend.cyrus.replication.server.Token;
31 31
 import net.bluemind.backend.cyrus.replication.server.state.ReplicationException;
32
+import net.bluemind.backend.cyrus.replication.server.utils.MailboxNameHelper;
32 33
 import net.bluemind.backend.mail.replica.api.MailboxSub;
33 34
 import net.bluemind.backend.mail.replica.api.SieveScript;
34 35
 
... ...
@@ -67,15 +68,7 @@ public class GetMeta implements IAsyncReplicationCommand {
67 68
 		}
68 69
 
69 70
 		public void addSub(MailboxSub f) {
70
-			subs.add(quoteIfNeeded(f.mboxName));
71
-		}
72
-
73
-		private String quoteIfNeeded(String mboxName) {
74
-			if (mboxName.contains(" ")) {
75
-				return "\"" + mboxName + "\"";
76
-			} else {
77
-				return mboxName;
78
-			}
71
+			subs.add(MailboxNameHelper.quoteIfNeeded(f.mboxName));
79 72
 		}
80 73
 
81 74
 		public void addSieve(SieveScript f) {
... ...
@@ -24,10 +24,9 @@ import org.slf4j.Logger;
24 24
 import org.slf4j.LoggerFactory;
25 25
 import org.vertx.java.core.json.JsonObject;
26 26
 
27
-import com.google.common.base.CharMatcher;
28
-
29 27
 import net.bluemind.backend.cyrus.replication.protocol.parsing.JsUtils;
30 28
 import net.bluemind.backend.cyrus.replication.server.Token;
29
+import net.bluemind.backend.cyrus.replication.server.utils.MailboxNameHelper;
31 30
 import net.bluemind.backend.mail.replica.api.MailboxAnnotation;
32 31
 
33 32
 public class MailboxFolder {
... ...
@@ -216,7 +215,7 @@ public class MailboxFolder {
216 215
 
217 216
 	private void mailboxFields(StringBuilder sb) {
218 217
 		sb.append("UNIQUEID ").append(uniqueId);
219
-		sb.append(" MBOXNAME ").append(quoteIfNeeded(name));
218
+		sb.append(" MBOXNAME ").append(MailboxNameHelper.quoteIfNeeded(name));
220 219
 		sb.append(" SYNC_CRC ").append(syncCRC);
221 220
 		// FIXME cyrus 3 new
222 221
 		sb.append(" SYNC_CRC_ANNOT ").append("0");
... ...
@@ -244,16 +243,6 @@ public class MailboxFolder {
244 243
 		return quotaRoot;
245 244
 	}
246 245
 
247
-	private static final CharMatcher quoteMatcher = CharMatcher.anyOf(" ()");
248
-
249
-	private static String quoteIfNeeded(String s) {
250
-		if (quoteMatcher.matchesAnyOf(s)) {
251
-			return "\"" + s + "\"";
252
-		} else {
253
-			return s;
254
-		}
255
-	}
256
-
257 246
 	public void setQuotaRoot(String quotaRoot) {
258 247
 		this.quotaRoot = quotaRoot;
259 248
 	}
260 249
new file mode 100644
... ...
@@ -0,0 +1,37 @@
1
+/* BEGIN LICENSE
2
+  * Copyright © Blue Mind SAS, 2012-2019
3
+  *
4
+  * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+  * solution.
6
+  *
7
+  * This program is free software; you can redistribute it and/or modify
8
+  * it under the terms of either the GNU Affero General Public License as
9
+  * published by the Free Software Foundation (version 3 of the License).
10
+  *
11
+  * This program is distributed in the hope that it will be useful,
12
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
+  *
15
+  * See LICENSE.txt
16
+  * END LICENSE
17
+  */
18
+package net.bluemind.backend.cyrus.replication.server.utils;
19
+
20
+import com.google.common.base.CharMatcher;
21
+
22
+public class MailboxNameHelper {
23
+
24
+	private static final CharMatcher quoteMatcher = CharMatcher.anyOf(" ()");
25
+
26
+	private MailboxNameHelper() {
27
+	}
28
+
29
+	public static String quoteIfNeeded(String s) {
30
+		if (quoteMatcher.matchesAnyOf(s)) {
31
+			return "\"" + s + "\"";
32
+		} else {
33
+			return s;
34
+		}
35
+	}
36
+
37
+}