changeset 19554:fddcd9016d78

virtual plugin: Don't treat "+-box" as a negative entry. This was already documented by wiki to work as a mailbox named "-box", although it didn't actually work that way. There wasn't any practical difference between "+-box" and "-box", so this change is unlikely to break anyone's config. It was mainly done as code cleanup.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 13 Jan 2016 13:41:05 +0200
parents 30b51b37f4c5
children d68d75446bcc
files src/plugins/virtual/virtual-config.c src/plugins/virtual/virtual-storage.h
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/virtual/virtual-config.c	Wed Jan 13 13:31:54 2016 +0200
+++ b/src/plugins/virtual/virtual-config.c	Wed Jan 13 13:41:05 2016 +0200
@@ -116,7 +116,6 @@
 {
 	struct mail_user *user = ctx->mbox->storage->storage.user;
 	struct virtual_backend_box *bbox;
-	const char *name;
 
 	if (*line == ' ' || *line == '\t') {
 		/* continues the previous search rule */
@@ -147,15 +146,20 @@
 	if (strcasecmp(line, "INBOX") == 0)
 		line = "INBOX";
 	bbox->name = p_strdup(ctx->pool, line);
-	if (bbox->name[0] == '+') {
+	switch (bbox->name[0]) {
+	case '+':
 		bbox->name++;
 		bbox->clear_recent = TRUE;
+		break;
+	case '-':
+		bbox->name++;
+		bbox->negative_match = TRUE;
+		break;
 	}
 
 	if (strchr(bbox->name, '*') != NULL ||
 	    strchr(bbox->name, '%') != NULL) {
-		name = bbox->name[0] == '-' ? bbox->name + 1 : bbox->name;
-		bbox->glob = imap_match_init(ctx->pool, name, TRUE, ctx->sep);
+		bbox->glob = imap_match_init(ctx->pool, bbox->name, TRUE, ctx->sep);
 		ctx->have_wildcards = TRUE;
 	} else if (bbox->name[0] == '!') {
 		/* save messages here */
@@ -202,7 +206,7 @@
 	for (i = 0; i < count; i++) {
 		pattern.ns = bboxes[i]->ns;
 		pattern.pattern = bboxes[i]->name;
-		if (*pattern.pattern != '-')
+		if (bboxes[i]->negative_match)
 			dest = &mbox->list_include_patterns;
 		else {
 			dest = &mbox->list_exclude_patterns;
@@ -225,7 +229,7 @@
 	t_array_init(wildcard_boxes, I_MIN(16, count));
 	t_array_init(neg_boxes, 4);
 	for (i = 0; i < count;) {
-		if (*bboxes[i]->name == '-')
+		if (bboxes[i]->negative_match)
 			dest = neg_boxes;
 		else if (bboxes[i]->glob != NULL)
 			dest = wildcard_boxes;
@@ -297,8 +301,7 @@
 				return TRUE;
 			}
 		} else {
-			i_assert(boxes[i]->name[0] == '-');
-			if (strcmp(boxes[i]->name + 1, info->vname) == 0) {
+			if (strcmp(boxes[i]->name, info->vname) == 0) {
 				*idx_r = i;
 				return TRUE;
 			}
--- a/src/plugins/virtual/virtual-storage.h	Wed Jan 13 13:31:54 2016 +0200
+++ b/src/plugins/virtual/virtual-storage.h	Wed Jan 13 13:41:05 2016 +0200
@@ -105,6 +105,7 @@
 	unsigned int sync_seen:1;
 	unsigned int wildcard:1;
 	unsigned int clear_recent:1;
+	unsigned int negative_match:1;
 	unsigned int uids_nonsorted:1;
 	unsigned int search_args_initialized:1;
 };