annotate src/plugins/convert/convert-tool.c @ 8467:03c418eadc8b HEAD

mail_user_*() now handles home directory lookups when necessary. Namespace owner is now a pointer to struct mail_user rather than a string.
author Timo Sirainen <tss@iki.fi>
date Fri, 21 Nov 2008 18:32:02 +0200
parents bf83aa9c3f4a
children b9faf4db2a9f
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;
8082
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 7239
diff changeset
21 struct mail_user *user;
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
22 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
23 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
24 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
25 const char *error;
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
26 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
27
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 lib_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 lib_signals_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 random_init();
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
31 mail_users_init(getenv("AUTH_SOCKET_PATH"), getenv("DEBUG") != NULL);
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 mail_storage_init();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 mail_storage_register_all();
4891
6ab2712f1a93 Only imap binary was actually working.
Timo Sirainen <tss@iki.fi>
parents: 4860
diff changeset
34 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
35
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
36 if (argc <= 4)
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
37 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
38
5249
784dc7224718 Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents: 4891
diff changeset
39 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
40
5534
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
41 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
42 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
43 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
44 set.skip_broken_mailboxes = TRUE;
5535
7aa36ab24c3b Changed convert_skip_dotfiles to convert_skip_dotdirs.
Timo Sirainen <tss@iki.fi>
parents: 5534
diff changeset
45 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
46 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
47 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
48 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
49 }
c69786bd2017 Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents: 5249
diff changeset
50
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
51 mail_storage_parse_env(&dest_flags, &lock_method);
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
52 user = mail_user_init(argv[1]);
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
53 mail_user_set_home(user, argv[2]);
8085
bf83aa9c3f4a Removed pool parameter from mail_namespaces_init*(). Use mail_user's pool intead.
Timo Sirainen <tss@iki.fi>
parents: 8082
diff changeset
54 dest_ns = mail_namespaces_init_empty(user);
8082
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 7239
diff changeset
55
db66611fd195 Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents: 7239
diff changeset
56 if (mail_storage_create(dest_ns, NULL, argv[4],
6976
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
57 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
58 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
59 "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
60 }
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
61
7cedc391e6c5 Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
62 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
63 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_info("Successfully converted");
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 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
66 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
67 else
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 i_error("Internal failure");
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
69 mail_user_unref(&user);
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 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
72 mail_storage_deinit();
8467
03c418eadc8b mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents: 8085
diff changeset
73 mail_users_deinit();
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 lib_signals_deinit();
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 lib_deinit();
7239
0e8339ad1932 convert-tool returned inverted exit status.
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
76 return ret <= 0 ? 1 : 0;
3972
a506ee4ec31e Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 }