[dovecot-cvs] dovecot/src/plugins/convert convert-plugin.c, 1.1, 1.2 convert-storage.c, 1.9, 1.10 convert-storage.h, 1.1, 1.2 convert-tool.c, 1.2, 1.3

tss at dovecot.org tss at dovecot.org
Sun Dec 3 13:35:22 UTC 2006


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

Modified Files:
	convert-plugin.c convert-storage.c convert-storage.h 
	convert-tool.c 
Log Message:
Create storages with MAIL_STORAGE_FLAG_NO_AUTOCREATE flag so we don't keep
recreating the old storage and converting it all the time. Also added
convert_skip_broken_mailboxes flag.



Index: convert-plugin.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-plugin.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- convert-plugin.c	2 Feb 2006 20:42:44 -0000	1.1
+++ convert-plugin.c	3 Dec 2006 13:35:19 -0000	1.2
@@ -9,11 +9,14 @@
 void convert_plugin_init(void)
 {
 	const char *convert_mail, *mail, *home, *user;
+	bool skip_broken_mailboxes;
 
 	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");
@@ -24,7 +27,8 @@
 	if (mail == NULL)
 		i_fatal("convert plugin: HOME unset");
 
-	if (convert_storage(user, home, convert_mail, mail) < 0)
+	if (convert_storage(user, home, convert_mail, mail,
+			    skip_broken_mailboxes) < 0)
 		exit(FATAL_DEFAULT);
 }
 

Index: convert-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-storage.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- convert-storage.c	25 Nov 2006 22:18:33 -0000	1.9
+++ convert-storage.c	3 Dec 2006 13:35:19 -0000	1.10
@@ -100,7 +100,8 @@
 static int mailbox_convert_list_item(struct mail_storage *source_storage,
 				     struct mail_storage *dest_storage,
 				     struct mailbox_info *info,
-				     struct dotlock *dotlock)
+				     struct dotlock *dotlock,
+				     bool skip_broken_mailboxes)
 {
 	const char *name;
 	struct mailbox *srcbox, *destbox;
@@ -111,6 +112,7 @@
 
 	name = strcasecmp(info->name, "INBOX") == 0 ? "INBOX" : info->name;
 	if ((info->flags & MAILBOX_NOSELECT) != 0) {
+		/* \NoSelect mailbox, so it's probably a "directory" */
 		if (mail_storage_mailbox_create(dest_storage, name, TRUE) < 0) {
 			i_error("Mailbox conversion: Couldn't create mailbox "
 				"directory %s", name);
@@ -119,21 +121,26 @@
 		return 0;
 	}
 
-	/* It's a real mailbox. First create the destination mailbox. */
-	if (mail_storage_mailbox_create(dest_storage, name, FALSE) < 0) {
-		i_error("Mailbox conversion: Couldn't create mailbox %s", name);
-		return -1;
-	}
-
-	/* Open both the mailboxes.. */
+	/* First open the source mailbox. If we can't open it, don't create
+	   the destination mailbox either. */
 	srcbox = mailbox_open(source_storage, name, NULL,
-			   MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
+			      MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT);
 	if (srcbox == NULL) {
+		if (skip_broken_mailboxes)
+			return 0;
+
 		i_error("Mailbox conversion: Couldn't open source mailbox %s",
 			name);
 		return -1;
 	}
 
+	/* Create and open the destination mailbox. */
+	if (mail_storage_mailbox_create(dest_storage, name, FALSE) < 0) {
+		i_error("Mailbox conversion: Couldn't create mailbox %s", name);
+		mailbox_close(&srcbox);
+		return -1;
+	}
+
 	destbox = mailbox_open(dest_storage, name, NULL,
 			       MAILBOX_OPEN_KEEP_RECENT);
 	if (destbox == NULL) {
@@ -155,7 +162,8 @@
 
 static int mailbox_list_copy(struct mail_storage *source_storage,
 			     struct mail_storage *dest_storage,
-			     struct dotlock *dotlock)
+			     struct dotlock *dotlock,
+			     bool skip_broken_mailboxes)
 {
 	struct mailbox_list_iterate_context *iter;
 	struct mailbox_info *info;
@@ -165,7 +173,8 @@
 				      "*", MAILBOX_LIST_ITER_FAST_FLAGS);
 	while ((info = mailbox_list_iter_next(iter)) != NULL) {
 		if (mailbox_convert_list_item(source_storage, dest_storage,
-					      info, dotlock) < 0) {
+					      info, dotlock,
+					      skip_broken_mailboxes) < 0) {
 			ret = -1;
 			break;
 		}
@@ -204,7 +213,8 @@
 }
 
 int convert_storage(const char *user, const char *home_dir,
-		    const char *source_data, const char *dest_data)
+		    const char *source_data, const char *dest_data,
+		    bool skip_broken_mailboxes)
 {
 	struct mail_storage *source_storage, *dest_storage;
 	struct dotlock *dotlock;
@@ -214,6 +224,7 @@
 	int ret;
 
 	mail_storage_parse_env(&flags, &lock_method);
+	flags |= MAIL_STORAGE_FLAG_NO_AUTOCREATE;
 	source_storage = mail_storage_create_with_data(source_data, user,
 						       flags, lock_method);
 	if (source_storage == NULL) {
@@ -247,7 +258,8 @@
 			"storage with data: %s", dest_data);
 		ret = -1;
 	} else {
-		ret = mailbox_list_copy(source_storage, dest_storage, dotlock);
+		ret = mailbox_list_copy(source_storage, dest_storage, dotlock,
+					skip_broken_mailboxes);
 		if (ret == 0) {
 			ret = mailbox_list_copy_subscriptions(source_storage,
 							      dest_storage);

Index: convert-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-storage.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- convert-storage.h	2 Feb 2006 20:42:44 -0000	1.1
+++ convert-storage.h	3 Dec 2006 13:35:19 -0000	1.2
@@ -2,6 +2,7 @@
 #define __CONVERT_STORAGE_H
 
 int convert_storage(const char *user, const char *home_dir,
-		    const char *source_data, const char *dest_data);
+		    const char *source_data, const char *dest_data,
+		    bool skip_broken_mailboxes);
 
 #endif

Index: convert-tool.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/convert/convert-tool.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- convert-tool.c	1 Dec 2006 10:12:18 -0000	1.2
+++ convert-tool.c	3 Dec 2006 13:35:19 -0000	1.3
@@ -7,6 +7,8 @@
 #include "mail-storage.h"
 #include "convert-storage.h"
 
+#include <stdlib.h>
+
 int main(int argc, const char *argv[])
 {
 	struct ioloop *ioloop;
@@ -20,12 +22,14 @@
 
 	if (argc <= 4) {
 		i_fatal("Usage: <username> <home dir> "
-			"<source mail env> <dest mail env>");
+			"<source mail env> <dest mail env> "
+			"[<1=skip broken mailboxes>]");
 	}
 
 	ioloop = io_loop_create(system_pool);
 
-	ret = convert_storage(argv[1], argv[2], argv[3], argv[4]);
+	ret = convert_storage(argv[1], argv[2], argv[3], argv[4],
+			      argv[5] != NULL && atoi(argv[5]) == 1);
 	if (ret > 0)
 		i_info("Successfully converted");
 	else if (ret == 0)



More information about the dovecot-cvs mailing list