[dovecot-cvs] dovecot/src/plugins/convert convert-plugin.c, 1.1, 1.1.2.1 convert-storage.c, 1.5.2.2, 1.5.2.3 convert-storage.h, 1.1, 1.1.2.1 convert-tool.c, 1.1, 1.1.2.1
tss at dovecot.org
tss at dovecot.org
Sun Dec 3 13:35:19 UTC 2006
Update of /var/lib/cvs/dovecot/src/plugins/convert
In directory talvi:/tmp/cvs-serv24665/src/plugins/convert
Modified Files:
Tag: branch_1_0
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.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- convert-plugin.c 2 Feb 2006 20:42:44 -0000 1.1
+++ convert-plugin.c 3 Dec 2006 13:35:16 -0000 1.1.2.1
@@ -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.5.2.2
retrieving revision 1.5.2.3
diff -u -d -r1.5.2.2 -r1.5.2.3
--- convert-storage.c 8 Jun 2006 21:23:33 -0000 1.5.2.2
+++ convert-storage.c 3 Dec 2006 13:35:16 -0000 1.5.2.3
@@ -101,7 +101,8 @@
static int mailbox_convert_list_item(struct mail_storage *source_storage,
struct mail_storage *dest_storage,
struct mailbox_list *list,
- struct dotlock *dotlock)
+ struct dotlock *dotlock,
+ bool skip_broken_mailboxes)
{
const char *name;
struct mailbox *srcbox, *destbox;
@@ -112,6 +113,7 @@
name = strcasecmp(list->name, "INBOX") == 0 ? "INBOX" : list->name;
if ((list->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);
@@ -120,21 +122,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) {
@@ -156,7 +163,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_context *iter;
struct mailbox_list *list;
@@ -166,7 +174,8 @@
MAILBOX_LIST_FAST_FLAGS);
while ((list = mail_storage_mailbox_list_next(iter)) != NULL) {
if (mailbox_convert_list_item(source_storage, dest_storage,
- list, dotlock) < 0) {
+ list, dotlock,
+ skip_broken_mailboxes) < 0) {
ret = -1;
break;
}
@@ -203,7 +212,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;
@@ -213,6 +223,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) {
@@ -246,7 +257,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.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- convert-storage.h 2 Feb 2006 20:42:44 -0000 1.1
+++ convert-storage.h 3 Dec 2006 13:35:16 -0000 1.1.2.1
@@ -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.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1
--- convert-tool.c 2 Feb 2006 20:42:44 -0000 1.1
+++ convert-tool.c 3 Dec 2006 13:35:16 -0000 1.1.2.1
@@ -6,6 +6,8 @@
#include "lib-signals.h"
#include "convert-storage.h"
+#include <stdlib.h>
+
/* ugly, but automake doesn't like having it built as both static and
dynamic object.. */
#include "convert-storage.c"
@@ -23,12 +25,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