[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-mail.c, 1.15, 1.16 maildir-storage.c, 1.99, 1.100 maildir-storage.h, 1.37, 1.38 maildir-sync.c, 1.54, 1.55 maildir-util.c, 1.11, 1.12

cras at dovecot.org cras at dovecot.org
Thu Jun 9 17:31:46 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv1587

Modified Files:
	maildir-mail.c maildir-storage.c maildir-storage.h 
	maildir-sync.c maildir-util.c 
Log Message:
Replaced ':' and ',' character usages with #defines, so they can be changed
easily if needed.



Index: maildir-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-mail.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- maildir-mail.c	8 Apr 2005 14:32:51 -0000	1.15
+++ maildir-mail.c	9 Jun 2005 14:31:43 -0000	1.16
@@ -129,7 +129,7 @@
 		return (uoff_t)-1;
 
 	/* size can be included in filename */
-	p = strstr(fname, ",W=");
+	p = strstr(fname, MAILDIR_EXTRA_SEP_S"W=");
 	if (p != NULL) {
 		p += 3;
 		virtual_size = 0;
@@ -138,7 +138,8 @@
 			p++;
 		}
 
-		if (*p == ':' || *p == ',' || *p == '\0') {
+		if (*p == MAILDIR_INFO_SEP || *p == MAILDIR_EXTRA_SEP ||
+		    *p == '\0') {
 			mail_cache_add(mail->trans->cache_trans, mail->data.seq,
 				       MAIL_CACHE_VIRTUAL_FULL_SIZE,
 				       &virtual_size, sizeof(virtual_size));
@@ -160,7 +161,7 @@
 	if (field == MAIL_FETCH_UIDL_FILE_NAME) {
 	    	fname = maildir_uidlist_lookup(mbox->uidlist,
 					       mail->mail.mail.uid, &flags);
-		end = strchr(fname, ':');
+		end = strchr(fname, MAILDIR_INFO_SEP);
 		return end == NULL ? fname : t_strdup_until(fname, end);
 	}
 
@@ -187,7 +188,7 @@
 		return (uoff_t)-1;
 
 	/* size can be included in filename */
-	p = strstr(fname, ",S=");
+	p = strstr(fname, MAILDIR_EXTRA_SEP_S"S=");
 	if (p != NULL) {
 		p += 3;
 		size = 0;
@@ -196,7 +197,8 @@
 			p++;
 		}
 
-		if (*p != ':' && *p != ',' && *p != '\0')
+		if (*p != MAILDIR_INFO_SEP &&
+		    *p != MAILDIR_EXTRA_SEP && *p != '\0')
 			size = (uoff_t)-1;
 	}
 

Index: maildir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -d -r1.99 -r1.100
--- maildir-storage.c	16 Apr 2005 19:44:11 -0000	1.99
+++ maildir-storage.c	9 Jun 2005 14:31:43 -0000	1.100
@@ -266,15 +266,33 @@
 static const char *maildir_get_control_path(struct maildir_storage *storage,
 					    const char *name)
 {
+	const char *default_path, *path, *default_uidlist;
+	struct stat st;
+
+	default_path = maildir_get_path(INDEX_STORAGE(storage), name);
 	if (storage->control_dir == NULL)
-		return maildir_get_path(INDEX_STORAGE(storage), name);
+		return default_path;
 
 	if ((STORAGE(storage)->flags & MAIL_STORAGE_FLAG_FULL_FS_ACCESS) != 0 &&
 	    (*name == '/' || *name == '~'))
-		return maildir_get_absolute_path(name, FALSE);
+		path = maildir_get_absolute_path(name, FALSE);
+	else {
+		path = t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
+				   name, NULL);
+	}
 
-	return t_strconcat(storage->control_dir, "/"MAILDIR_FS_SEP_S,
-			   name, NULL);
+	default_uidlist =
+		t_strconcat(default_path, "/" MAILDIR_UIDLIST_NAME, NULL);
+	if (stat(default_uidlist, &st) == 0) {
+		const char *dest_uidlist =
+			t_strconcat(path, "/" MAILDIR_UIDLIST_NAME, NULL);
+
+		if (rename(default_uidlist, dest_uidlist) < 0) {
+			i_error("rename(%s, %s) failed: %m",
+				default_uidlist, dest_uidlist);
+		}
+	}
+	return path;
 }
 
 static int mkdir_verify(struct index_storage *storage,

Index: maildir-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- maildir-storage.h	8 Apr 2005 14:32:51 -0000	1.37
+++ maildir-storage.h	9 Jun 2005 14:31:43 -0000	1.38
@@ -8,6 +8,19 @@
 #define SUBSCRIPTION_FILE_NAME "subscriptions"
 #define MAILDIR_INDEX_PREFIX "dovecot.index"
 
+/* "base,S=123:2," means:
+   <base> [<extra sep> <extra data> [..]] <info sep> 2 <flags sep> */
+#define MAILDIR_INFO_SEP ':'
+#define MAILDIR_EXTRA_SEP ','
+#define MAILDIR_FLAGS_SEP ','
+
+#define MAILDIR_INFO_SEP_S ":"
+#define MAILDIR_EXTRA_SEP_S ","
+#define MAILDIR_FLAGS_SEP_S ","
+
+/* ":2," is the standard flags separator */
+#define MAILDIR_FLAGS_FULL_SEP MAILDIR_INFO_SEP_S "2" MAILDIR_FLAGS_SEP_S
+
 #include "index-storage.h"
 
 #define STORAGE(maildir_storage) \

Index: maildir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- maildir-sync.c	26 Apr 2005 14:45:46 -0000	1.54
+++ maildir-sync.c	9 Jun 2005 14:31:43 -0000	1.55
@@ -461,8 +461,9 @@
 			str_truncate(dest, 0);
 			str_printfa(src, "%s/%s", ctx->new_dir, dp->d_name);
 			str_printfa(dest, "%s/%s", ctx->cur_dir, dp->d_name);
-			if (strchr(dp->d_name, ':') == NULL)
-				str_append(dest, ":2,");
+			if (strchr(dp->d_name, MAILDIR_INFO_SEP) == NULL) {
+				str_append(dest, MAILDIR_FLAGS_FULL_SEP);
+			}
 			if (rename(str_c(src), str_c(dest)) == 0) {
 				/* we moved it - it's \Recent for us */
                                 ctx->mbox->dirty_cur_time = ioloop_time;

Index: maildir-util.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-util.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-util.c	8 Apr 2005 14:32:51 -0000	1.11
+++ maildir-util.c	9 Jun 2005 14:31:43 -0000	1.12
@@ -73,11 +73,11 @@
 	*flags_r = 0;
 	*keywords_r = NULL;
 
-	info = strchr(fname, ':');
-	if (info == NULL || info[1] != '2' || info[2] != ',')
+	info = strchr(fname, MAILDIR_INFO_SEP);
+	if (info == NULL || info[1] != '2' || info[2] != MAILDIR_FLAGS_SEP)
 		return 0;
 
-	for (info += 3; *info != '\0' && *info != ','; info++) {
+	for (info += 3; *info != '\0' && *info != MAILDIR_FLAGS_SEP; info++) {
 		switch (*info) {
 		case 'R': /* replied */
 			*flags_r |= MAIL_ANSWERED;
@@ -118,14 +118,14 @@
 	int nextflag;
 
 	/* remove the old :info from file name, and get the old flags */
-	info = strrchr(fname, ':');
+	info = strrchr(fname, MAILDIR_INFO_SEP);
 	if (info != NULL && strrchr(fname, '/') > info)
 		info = NULL;
 
 	oldflags = "";
 	if (info != NULL) {
 		fname = t_strdup_until(fname, info);
-		if (info[1] == '2' && info[2] == ',')
+		if (info[1] == '2' && info[2] == MAILDIR_FLAGS_SEP)
 			oldflags = info+3;
 	}
 
@@ -133,7 +133,7 @@
 	   their ASCII code. unknown flags are kept. */
 	flags_str = t_str_new(256);
 	str_append(flags_str, fname);
-	str_append(flags_str, ":2,");
+	str_append(flags_str, MAILDIR_FLAGS_FULL_SEP);
 	flags_left = flags;
 	for (;;) {
 		/* skip all known flags */
@@ -143,8 +143,8 @@
 		       (*oldflags >= 'a' && *oldflags <= 'z'))
 			oldflags++;
 
-		nextflag = *oldflags == '\0' || *oldflags == ',' ? 256 :
-			(unsigned char) *oldflags;
+		nextflag = *oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP ?
+			256 : (unsigned char) *oldflags;
 
 		if ((flags_left & MAIL_DRAFT) && nextflag > 'D') {
 			str_append_c(flags_str, 'D');
@@ -171,14 +171,14 @@
 			// FIXME
 		}
 
-		if (*oldflags == '\0' || *oldflags == ',')
+		if (*oldflags == '\0' || *oldflags == MAILDIR_FLAGS_SEP)
 			break;
 
 		str_append_c(flags_str, *oldflags);
 		oldflags++;
 	}
 
-	if (*oldflags == ',') {
+	if (*oldflags == MAILDIR_FLAGS_SEP) {
 		/* another flagset, we don't know about these, just keep them */
 		while (*oldflags != '\0')
 			str_append_c(flags_str, *oldflags++);
@@ -262,7 +262,7 @@
         const unsigned char *s = p;
 	unsigned int g, h = 0;
 
-	while (*s != ':' && *s != '\0') {
+	while (*s != MAILDIR_INFO_SEP && *s != '\0') {
 		h = (h << 4) + *s;
 		if ((g = h & 0xf0000000UL)) {
 			h = h ^ (g >> 24);
@@ -279,11 +279,11 @@
 {
 	const char *s1 = p1, *s2 = p2;
 
-	while (*s1 == *s2 && *s1 != ':' && *s1 != '\0') {
+	while (*s1 == *s2 && *s1 != MAILDIR_INFO_SEP && *s1 != '\0') {
 		s1++; s2++;
 	}
-	if ((*s1 == '\0' || *s1 == ':') &&
-	    (*s2 == '\0' || *s2 == ':'))
+	if ((*s1 == '\0' || *s1 == MAILDIR_INFO_SEP) &&
+	    (*s2 == '\0' || *s2 == MAILDIR_INFO_SEP))
 		return 0;
 	return *s1 - *s2;
 }



More information about the dovecot-cvs mailing list