[dovecot-cvs] dovecot/src/plugins/convert convert-plugin.c, 1.3, 1.4 convert-storage.c, 1.20, 1.21 convert-storage.h, 1.2, 1.3 convert-tool.c, 1.5, 1.6

tss at dovecot.org tss at dovecot.org
Tue Apr 10 17:30:34 EEST 2007


Update of /var/lib/cvs/dovecot/src/plugins/convert
In directory talvi:/tmp/cvs-serv16125/src/plugins/convert

Modified Files:
	convert-plugin.c convert-storage.c convert-storage.h 
	convert-tool.c 
Log Message:
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.



Index: convert-plugin.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-plugin.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- convert-plugin.c	22 Feb 2007 14:27:32 -0000	1.3
+++ convert-plugin.c	10 Apr 2007 14:30:31 -0000	1.4
@@ -10,27 +10,32 @@
 
 void convert_plugin_init(void)
 {
-	const char *convert_mail, *mail, *home, *user;
-	bool skip_broken_mailboxes;
+	const char *convert_mail, *mail, *str;
+	struct convert_settings set;
 
 	convert_mail = getenv("CONVERT_MAIL");
 	if (convert_mail == NULL)
 		return;
 
-	skip_broken_mailboxes = getenv("CONVERT_SKIP_BROKEN_MAILBOXES") != NULL;
-
 	mail = getenv("MAIL");
 	if (mail == NULL)
 		i_fatal("convert plugin: MAIL unset");
-	user = getenv("USER");
-	if (mail == NULL)
+
+	memset(&set, 0, sizeof(set));
+	set.user = getenv("USER");
+	if (set.user == NULL)
 		i_fatal("convert plugin: USER unset");
-	home = getenv("HOME");
-	if (mail == NULL)
+	set.home = getenv("HOME");
+	if (set.home == NULL)
 		i_fatal("convert plugin: HOME unset");
 
-	if (convert_storage(user, home, convert_mail, mail,
-			    skip_broken_mailboxes) < 0)
+	set.skip_broken_mailboxes = getenv("CONVERT_SKIP_BROKEN_MAILBOXES") != NULL;
+	set.skip_dotfiles = getenv("CONVERT_SKIP_DOTFILES") != NULL;
+
+	str = getenv("CONVERT_ALT_HIERARCHY_CHAR");
+	set.alt_hierarchy_char = *str != '\0' ? *str : '_';
+
+	if (convert_storage(convert_mail, mail, &set) < 0)
 		exit(FATAL_DEFAULT);
 }
 

Index: convert-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-storage.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- convert-storage.c	10 Apr 2007 14:14:58 -0000	1.20
+++ convert-storage.c	10 Apr 2007 14:30:31 -0000	1.21
@@ -108,7 +108,8 @@
 
 static const char *
 mailbox_name_convert(struct mail_storage *dest_storage,
-		     struct mail_storage *source_storage, const char *name)
+		     struct mail_storage *source_storage,
+		     const struct convert_settings *set, const char *name)
 {
 	char *dest_name, *p, src_sep, dest_sep;
 
@@ -117,6 +118,8 @@
 
 	dest_name = t_strdup_noconst(name);
 	for (p = dest_name; *p != '\0'; p++) {
+		if (*p == dest_sep)
+			*p = set->alt_hierarchy_char;
 		if (*p == src_sep)
 			*p = dest_sep;
 	}
@@ -127,7 +130,7 @@
 				     struct mail_storage *dest_storage,
 				     struct mailbox_info *info,
 				     struct dotlock *dotlock,
-				     bool skip_broken_mailboxes)
+				     const struct convert_settings *set)
 {
 	const char *name, *dest_name;
 	struct mailbox *srcbox, *destbox;
@@ -135,12 +138,14 @@
 
 	if ((info->flags & MAILBOX_NONEXISTENT) != 0)
 		return 0;
+	if (*info->name == '.' && set->skip_dotfiles)
+		return 0;
 
 	name = strcasecmp(info->name, "INBOX") == 0 ? "INBOX" : info->name;
 	if ((info->flags & MAILBOX_NOSELECT) != 0) {
 		/* \NoSelect mailbox, so it's probably a "directory" */
 		dest_name = mailbox_name_convert(dest_storage, source_storage,
-						 name);
+						 set, name);
 		if (mail_storage_mailbox_create(dest_storage, dest_name,
 						TRUE) < 0) {
 			i_error("Mailbox conversion: Couldn't create mailbox "
@@ -155,7 +160,7 @@
 	srcbox = mailbox_open(source_storage, name, NULL,
 			      MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
 	if (srcbox == NULL) {
-		if (skip_broken_mailboxes)
+		if (set->skip_broken_mailboxes)
 			return 0;
 
 		i_error("Mailbox conversion: "
@@ -165,7 +170,8 @@
 	}
 
 	/* Create and open the destination mailbox. */
-	dest_name = mailbox_name_convert(dest_storage, source_storage, name);
+	dest_name = mailbox_name_convert(dest_storage, source_storage,
+					 set, name);
 	if (mail_storage_mailbox_create(dest_storage, dest_name, FALSE) < 0) {
 		i_error("Mailbox conversion: Couldn't create mailbox %s: %s",
 			dest_name, storage_error(dest_storage));
@@ -195,7 +201,7 @@
 static int mailbox_list_copy(struct mail_storage *source_storage,
 			     struct mail_storage *dest_storage,
 			     struct dotlock *dotlock,
-			     bool skip_broken_mailboxes)
+			     const struct convert_settings *set)
 {
 	struct mailbox_list_iterate_context *iter;
 	struct mailbox_info *info;
@@ -205,8 +211,7 @@
 				      "*", MAILBOX_LIST_ITER_FAST_FLAGS);
 	while ((info = mailbox_list_iter_next(iter)) != NULL) {
 		if (mailbox_convert_list_item(source_storage, dest_storage,
-					      info, dotlock,
-					      skip_broken_mailboxes) < 0) {
+					      info, dotlock, set) < 0) {
 			ret = -1;
 			break;
 		}
@@ -221,7 +226,8 @@
 }
 
 static int mailbox_list_copy_subscriptions(struct mail_storage *source_storage,
-					   struct mail_storage *dest_storage)
+					   struct mail_storage *dest_storage,
+					   const struct convert_settings *set)
 {
 	struct mailbox_list_iterate_context *iter;
 	struct mailbox_info *info;
@@ -235,7 +241,7 @@
 				      MAILBOX_LIST_ITER_FAST_FLAGS);
 	while ((info = mailbox_list_iter_next(iter)) != NULL) {
 		dest_name = mailbox_name_convert(dest_storage, source_storage,
-						 info->name);
+						 set, info->name);
 		if (mailbox_list_set_subscribed(dest_list, dest_name,
 						TRUE) < 0) {
 			ret = -1;
@@ -247,9 +253,8 @@
 	return ret;
 }
 
-int convert_storage(const char *user, const char *home_dir,
-		    const char *source_data, const char *dest_data,
-		    bool skip_broken_mailboxes)
+int convert_storage(const char *source_data, const char *dest_data,
+		    const struct convert_settings *set)
 {
 	struct mail_namespace *source_ns, *dest_ns;
 	struct dotlock *dotlock;
@@ -264,7 +269,7 @@
 	dest_flags = src_flags;
 
 	src_flags |= MAIL_STORAGE_FLAG_NO_AUTOCREATE;
-	if (mail_storage_create(source_ns, NULL, source_data, user,
+	if (mail_storage_create(source_ns, NULL, source_data, set->user,
 				src_flags, lock_method) < 0) {
 		/* No need for conversion. */
 		return 0;
@@ -273,7 +278,7 @@
 	/* If home directory doesn't exist, creating the destination storage
 	   will most likely create it. So do this before locking. */
 	dest_ns = mail_namespaces_init_empty(pool_datastack_create());
-	if (mail_storage_create(dest_ns, NULL, dest_data, user,
+	if (mail_storage_create(dest_ns, NULL, dest_data, set->user,
 				dest_flags, lock_method) < 0) {
 		i_error("Mailbox conversion: Failed to create destination "
 			"storage with data: %s", dest_data);
@@ -282,7 +287,7 @@
 		return -1;
 	}
 
-        path = t_strconcat(home_dir, "/"CONVERT_LOCK_FILENAME, NULL);
+        path = t_strconcat(set->home, "/"CONVERT_LOCK_FILENAME, NULL);
 	dotlock_settings.use_excl_lock =
 		(source_ns->storage->flags &
 		 MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0;
@@ -296,7 +301,7 @@
 	/* just in case if another process just had converted the mailbox,
 	   reopen the source storage */
 	mail_storage_destroy(&source_ns->storage);
-	if (mail_storage_create(source_ns, NULL, source_data, user,
+	if (mail_storage_create(source_ns, NULL, source_data, set->user,
 				src_flags, lock_method) < 0) {
 		/* No need for conversion anymore. */
 		file_dotlock_delete(&dotlock);
@@ -304,10 +309,10 @@
 	}
 
 	ret = mailbox_list_copy(source_ns->storage, dest_ns->storage,
-				dotlock, skip_broken_mailboxes);
+				dotlock, set);
 	if (ret == 0) {
 		ret = mailbox_list_copy_subscriptions(source_ns->storage,
-						      dest_ns->storage);
+						      dest_ns->storage, set);
 	}
 
 	if (ret == 0) {

Index: convert-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-storage.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- convert-storage.h	3 Dec 2006 13:35:19 -0000	1.2
+++ convert-storage.h	10 Apr 2007 14:30:31 -0000	1.3
@@ -1,8 +1,15 @@
 #ifndef __CONVERT_STORAGE_H
 #define __CONVERT_STORAGE_H
 
-int convert_storage(const char *user, const char *home_dir,
-		    const char *source_data, const char *dest_data,
-		    bool skip_broken_mailboxes);
+struct convert_settings {
+	const char *user;
+	const char *home;
+	bool skip_broken_mailboxes;
+	bool skip_dotfiles;
+	char alt_hierarchy_char;
+};
+
+int convert_storage(const char *source_data, const char *dest_data,
+		    const struct convert_settings *set);
 
 #endif

Index: convert-tool.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-tool.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- convert-tool.c	8 Mar 2007 22:07:33 -0000	1.5
+++ convert-tool.c	10 Apr 2007 14:30:31 -0000	1.6
@@ -9,10 +9,15 @@
 
 #include <stdlib.h>
 
+#define USAGE_STRING \
+"Usage: <username> <home dir> <source mail env> <dest mail env>\n" \
+"       [skip_broken_mailboxes] [skip_dotfiles] [alt_hierarchy_char=<c>]"
+
 int main(int argc, const char *argv[])
 {
 	struct ioloop *ioloop;
-	int ret = 0;
+	struct convert_settings set;
+	int i, ret = 0;
 
 	lib_init();
 	lib_signals_init();
@@ -21,16 +26,25 @@
 	mail_storage_register_all();
 	mailbox_list_register_all();
 
-	if (argc <= 4) {
-		i_fatal("Usage: <username> <home dir> "
-			"<source mail env> <dest mail env> "
-			"[<1=skip broken mailboxes>]");
-	}
+	if (argc <= 4)
+		i_fatal(USAGE_STRING);
 
 	ioloop = io_loop_create();
 
-	ret = convert_storage(argv[1], argv[2], argv[3], argv[4],
-			      argv[5] != NULL && atoi(argv[5]) == 1);
+	memset(&set, 0, sizeof(set));
+	set.user = argv[1];
+	set.home = argv[2];
+
+	for (i = 5; i < argc; i++) {
+		if (strcmp(argv[i], "skip_broken_mailboxes") != 0)
+			set.skip_broken_mailboxes = TRUE;
+		else if (strcmp(argv[i], "skip_dotfiles") != 0)
+			set.skip_dotfiles = TRUE;
+		else if (strncmp(argv[i], "alt_hierarchy_char=", 19) != 0)
+			set.alt_hierarchy_char = argv[i][19];
+	}
+
+	ret = convert_storage(argv[3], argv[4], &set);
 	if (ret > 0)
 		i_info("Successfully converted");
 	else if (ret == 0)



More information about the dovecot-cvs mailing list