annotate src/plugins/convert/convert-tool.c @ 7086:7ed926ed7aa4 HEAD

Updated copyright notices to include year 2008.
author Timo Sirainen <tss@iki.fi>
date Tue, 01 Jan 2008 22:05:21 +0200
parents 7cedc391e6c5
children 0e8339ad1932
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7086
7ed926ed7aa4 Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents: 6976
diff changeset
1 /* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ioloop.h"
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "randgen.h"
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "lib-signals.h"
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
7 #include "mail-namespace.h"
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
8 #include "mail-storage-private.h"
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "convert-storage.h"
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
4860
87ae4d41bc10 Create storages with MAIL_STORAGE_FLAG_NO_AUTOCREATE flag so we don't keep
Timo Sirainen <tss@iki.fi>
parents: 4851
diff changeset
11 #include <stdlib.h>
87ae4d41bc10 Create storages with MAIL_STORAGE_FLAG_NO_AUTOCREATE flag so we don't keep
Timo Sirainen <tss@iki.fi>
parents: 4851
diff changeset
12
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
13 #define USAGE_STRING \
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
14 "Usage: <username> <home dir> <source mail env> <dest mail env>\n" \
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
15 " [skip_broken_mailboxes] [skip_dotfiles] [alt_hierarchy_char=<c>]"
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
16
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 int main(int argc, const char *argv[])
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 {
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 struct ioloop *ioloop;
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
20 struct convert_settings set;
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
21 struct mail_namespace *dest_ns;
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
22 enum mail_storage_flags dest_flags;
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
23 enum file_lock_method lock_method;
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
24 const char *error;
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
25 int i, ret = 0;
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 lib_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 lib_signals_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 random_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 mail_storage_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 mail_storage_register_all();
4891
6ab2712f1a93 Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents: 4860
diff changeset
32 mailbox_list_register_all();
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
34 if (argc <= 4)
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
35 i_fatal(USAGE_STRING);
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36
5249
784dc7224718 Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
37 ioloop = io_loop_create();
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
39 memset(&set, 0, sizeof(set));
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
40 set.user = argv[1];
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
41 set.home = argv[2];
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
42
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
43 for (i = 5; i < argc; i++) {
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
44 if (strcmp(argv[i], "skip_broken_mailboxes") != 0)
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
45 set.skip_broken_mailboxes = TRUE;
5535
7aa36ab24c3b Changed convert_skip_dotfiles to convert_skip_dotdirs.
Timo Sirainen <tss@iki.fi>
parents: 5534
diff changeset
46 else if (strcmp(argv[i], "skip_dotdirs") != 0)
7aa36ab24c3b Changed convert_skip_dotfiles to convert_skip_dotdirs.
Timo Sirainen <tss@iki.fi>
parents: 5534
diff changeset
47 set.skip_dotdirs = TRUE;
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
48 else if (strncmp(argv[i], "alt_hierarchy_char=", 19) != 0)
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
49 set.alt_hierarchy_char = argv[i][19];
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
50 }
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
51
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
52 mail_storage_parse_env(&dest_flags, &lock_method);
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
53 dest_ns = mail_namespaces_init_empty(pool_datastack_create());
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
54 if (mail_storage_create(dest_ns, NULL, argv[4], set.user,
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
55 dest_flags, lock_method, &error) < 0) {
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
56 i_fatal("Failed to create destination "
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
57 "mail storage with data '%s': %s", argv[4], error);
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
58 }
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
59
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
60 ret = convert_storage(argv[3], dest_ns, &set);
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 if (ret > 0)
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 i_info("Successfully converted");
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 else if (ret == 0)
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 i_error("Source storage not found");
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 else
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 i_error("Internal failure");
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
67 mail_namespaces_deinit(&dest_ns);
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 io_loop_destroy(&ioloop);
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 mail_storage_deinit();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 lib_signals_deinit();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 lib_deinit();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 return ret;
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 }