Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/plugins/convert/convert-plugin.c @ 9575:0a00dcc4f0ea HEAD
lib-storage: Allow shared namespace prefix to use %variable modifiers.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 26 May 2010 17:07:51 +0100 |
parents | 00cd9aacd03c |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1 /* Copyright (c) 2006-2010 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" |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
4 #include "mail-namespace.h" |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #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
|
6 #include "convert-plugin.h" |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include <stdlib.h> |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
5185
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4860
diff
changeset
|
10 const char *convert_plugin_version = PACKAGE_VERSION; |
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4860
diff
changeset
|
11 |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
12 static void (*convert_next_hook_mail_namespaces_created) |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
13 (struct mail_namespace *namespaces); |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
14 |
7462
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
15 static void convert_mail_storage(struct mail_namespace *namespaces, |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
16 const char *convert_mail) |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 { |
7462
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
18 const char *str; |
5534
c69786bd2017
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
19 struct convert_settings set; |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
5534
c69786bd2017
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
21 memset(&set, 0, sizeof(set)); |
8467
03c418eadc8b
mail_user_*() now handles home directory lookups when necessary.
Timo Sirainen <tss@iki.fi>
parents:
8404
diff
changeset
|
22 if (mail_user_get_home(namespaces->user, &str) <= 0) |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 i_fatal("convert plugin: HOME unset"); |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
25 set.skip_broken_mailboxes = |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
26 getenv("CONVERT_SKIP_BROKEN_MAILBOXES") != NULL; |
5535
7aa36ab24c3b
Changed convert_skip_dotfiles to convert_skip_dotdirs.
Timo Sirainen <tss@iki.fi>
parents:
5534
diff
changeset
|
27 set.skip_dotdirs = getenv("CONVERT_SKIP_DOTDIRS") != NULL; |
5534
c69786bd2017
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
28 |
c69786bd2017
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
29 str = getenv("CONVERT_ALT_HIERARCHY_CHAR"); |
6672
baf570ca608b
Don't crash if convert_alt_hierarchy_char isn't set.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
30 set.alt_hierarchy_char = str != NULL && *str != '\0' ? *str : '_'; |
5534
c69786bd2017
Added convert_skip_dotfiles and convert_alt_hierarchy_char settings.
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
31 |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
32 if (convert_storage(convert_mail, namespaces, &set) < 0) |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
33 i_fatal("Mailbox conversion failed, exiting"); |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
34 } |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
35 |
7462
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
36 static void |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
37 convert_hook_mail_namespaces_created(struct mail_namespace *namespaces) |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
38 { |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
39 const char *convert_mail; |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
40 |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
41 convert_mail = getenv("CONVERT_MAIL"); |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
42 if (convert_mail != NULL) |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
43 convert_mail_storage(namespaces, convert_mail); |
8404
d3cbd3494a8c
Plugins: If mail_debug=yes, log "plugin disabled" if plugin's required setting isn't set.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
44 else if (getenv("DEBUG") != NULL) |
d3cbd3494a8c
Plugins: If mail_debug=yes, log "plugin disabled" if plugin's required setting isn't set.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
45 i_info("convert: No convert_mail setting - plugin disabled"); |
7462
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
46 |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
47 if (convert_next_hook_mail_namespaces_created != NULL) |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
48 convert_next_hook_mail_namespaces_created(namespaces); |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
49 } |
068f6eefc62b
next_hook should be called after our hook is finished with its doings, that
Timo Sirainen <tss@iki.fi>
parents:
7404
diff
changeset
|
50 |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
51 void convert_plugin_init(void) |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
52 { |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
53 convert_next_hook_mail_namespaces_created = |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
54 hook_mail_namespaces_created; |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
55 hook_mail_namespaces_created = convert_hook_mail_namespaces_created; |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 } |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 void convert_plugin_deinit(void) |
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 { |
6976
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
60 hook_mail_namespaces_created = |
7cedc391e6c5
Convert only after namespaces are created. Convert mailboxes to INBOX
Timo Sirainen <tss@iki.fi>
parents:
6672
diff
changeset
|
61 convert_next_hook_mail_namespaces_created; |
3972
a506ee4ec31e
Added "mail storage conversion" plugin. It can be used with IMAP, POP3
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |