Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5534:c69786bd2017 HEAD
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 10 Apr 2007 17:30:30 +0300 |
parents | e607f517d08b |
children | 7aa36ab24c3b |
files | dovecot-example.conf src/plugins/convert/convert-plugin.c src/plugins/convert/convert-storage.c src/plugins/convert/convert-storage.h src/plugins/convert/convert-tool.c |
diffstat | 5 files changed, 76 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Tue Apr 10 17:14:58 2007 +0300 +++ b/dovecot-example.conf Tue Apr 10 17:30:30 2007 +0300 @@ -1064,6 +1064,11 @@ #convert_mail = mbox:%h/mail # Skip mailboxes which we can't open successfully instead of aborting. #convert_skip_broken_mailboxes = no + # Skip mailboxes beginning with '.'. + #convert_skip_dotfiles = no + # If source storage has mailbox names with destination storage's hierarchy + # separators, replace them with this character. + #convert_alt_hierarchy_char = _ # Trash plugin. When saving a message would make user go over quota, this # plugin automatically deletes the oldest mails from configured mailboxes
--- a/src/plugins/convert/convert-plugin.c Tue Apr 10 17:14:58 2007 +0300 +++ b/src/plugins/convert/convert-plugin.c Tue Apr 10 17:30:30 2007 +0300 @@ -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); }
--- a/src/plugins/convert/convert-storage.c Tue Apr 10 17:14:58 2007 +0300 +++ b/src/plugins/convert/convert-storage.c Tue Apr 10 17:30:30 2007 +0300 @@ -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) {
--- a/src/plugins/convert/convert-storage.h Tue Apr 10 17:14:58 2007 +0300 +++ b/src/plugins/convert/convert-storage.h Tue Apr 10 17:30:30 2007 +0300 @@ -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
--- a/src/plugins/convert/convert-tool.c Tue Apr 10 17:14:58 2007 +0300 +++ b/src/plugins/convert/convert-tool.c Tue Apr 10 17:30:30 2007 +0300 @@ -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)