[Dovecot] patch: mailboxcasecmp()

Frank Cusack fcusack at fcusack.com
Mon Oct 9 05:51:34 UTC 2006


Here is a patch which adds mailboxcmp() and mailboxcasecmp() functions,
similar to mailbox_equals().  Names were chosen to match strcmp() and
strcasecmp().  I needed this for Johaness Berg's dspam plugin.  It
watches a folder "SPAM" and forcing this to be uppercase is unacceptable
for me.  (I also had to modify the plugin to use the new routine.)

It's against dovecot-1.0.beta8 but should be trivial to port to CVS.

-frank
-------------- next part --------------
diff -urp dovecot-1.0.beta8.orig/src/imap/commands-util.c dovecot-1.0.beta8/src/imap/commands-util.c
--- dovecot-1.0.beta8.orig/src/imap/commands-util.c	2006-01-13 19:00:10.000000000 -0800
+++ dovecot-1.0.beta8/src/imap/commands-util.c	2006-10-08 15:01:26.919748000 -0700
@@ -328,8 +328,8 @@ bool client_save_keywords(struct mailbox
 	return TRUE;
 }
 
-bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
-		    const char *name2)
+static bool _mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
+			    const char *name2, int ci)
 {
 	struct mail_storage *storage1 = mailbox_get_storage(box1);
 	const char *name1;
@@ -338,13 +338,36 @@ bool mailbox_equals(struct mailbox *box1
 		return FALSE;
 
         name1 = mailbox_get_name(box1);
-	if (strcmp(name1, name2) == 0)
-		return TRUE;
+	if (ci) {
+		if (strcasecmp(name1, name2) == 0)
+			return TRUE;
+	} else {
+		if (strcmp(name1, name2) == 0)
+			return TRUE;
+	}
 
 	return strcasecmp(name1, "INBOX") == 0 &&
 		strcasecmp(name2, "INBOX") == 0;
 }
 
+bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
+		    const char *name2)
+{
+	return _mailbox_equals(box1, storage2, name2, 0);
+}
+
+bool mailboxcmp(struct mailbox *box1, struct mail_storage *storage2,
+		const char *name2)
+{
+	return _mailbox_equals(box1, storage2, name2, 0);
+}
+
+bool mailboxcasecmp(struct mailbox *box1, struct mail_storage *storage2,
+		    const char *name2)
+{
+	return _mailbox_equals(box1, storage2, name2, 1);
+}
+
 void msgset_generator_init(struct msgset_generator_context *ctx, string_t *str)
 {
 	memset(ctx, 0, sizeof(*ctx));
diff -urp dovecot-1.0.beta8.orig/src/imap/commands-util.h dovecot-1.0.beta8/src/imap/commands-util.h
--- dovecot-1.0.beta8.orig/src/imap/commands-util.h	2006-01-13 19:00:10.000000000 -0800
+++ dovecot-1.0.beta8/src/imap/commands-util.h	2006-10-08 15:02:13.410042000 -0700
@@ -53,6 +53,10 @@ bool client_save_keywords(struct mailbox
 
 bool mailbox_equals(struct mailbox *box1, struct mail_storage *storage2,
 		    const char *name2);
+bool mailboxcmp(struct mailbox *box1, struct mail_storage *storage2,
+		const char *name2);
+bool mailboxcasecmp(struct mailbox *box1, struct mail_storage *storage2,
+		    const char *name2);
 
 void msgset_generator_init(struct msgset_generator_context *ctx, string_t *str);
 void msgset_generator_next(struct msgset_generator_context *ctx, uint32_t uid);


More information about the dovecot mailing list