Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/plugins/imap-quota/imap-quota-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 | efe0efc22d22 |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
8959
diff
changeset
|
1 /* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */ |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "str.h" |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
5 #include "ostream.h" |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "imap-quote.h" |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
7 #include "mail-namespace.h" |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "commands.h" |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "quota.h" |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "quota-plugin.h" |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "imap-quota-plugin.h" |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <stdlib.h> |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
15 #define QUOTA_USER_SEPARATOR ':' |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
16 |
5185
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4796
diff
changeset
|
17 const char *imap_quota_plugin_version = PACKAGE_VERSION; |
24f4a959a24c
Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents:
4796
diff
changeset
|
18 |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
19 static const char * |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
20 imap_quota_root_get_name(struct mail_user *user, struct mail_user *owner, |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
21 struct quota_root *root) |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
22 { |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
23 const char *name; |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
24 |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
25 name = quota_root_get_name(root); |
8959
33f3016673aa
imap-quota: Allow GETQUOTAROOT for public namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
26 if (user == owner || owner == NULL) |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
27 return name; |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
28 return t_strdup_printf("%s%c%s", owner->username, |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
29 QUOTA_USER_SEPARATOR, name); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
30 } |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
31 |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 static void |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
33 quota_reply_write(string_t *str, struct mail_user *user, |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
34 struct mail_user *owner, struct quota_root *root) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 { |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
36 const char *name, *const *list; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 unsigned int i; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 uint64_t value, limit; |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
39 int ret = 0; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 str_append(str, "* QUOTA "); |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
42 name = imap_quota_root_get_name(user, owner, root); |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
43 imap_quote_append_string(str, name, FALSE); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 str_append(str, " ("); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 list = quota_root_get_resources(root); |
4241
4fa5cda580db
Don't add extra spaces to reply if some of the resources aren't really found.
Timo Sirainen <tss@iki.fi>
parents:
4084
diff
changeset
|
47 for (i = 0; *list != NULL; list++) { |
4513
f91f3bcb7939
Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4473
diff
changeset
|
48 ret = quota_get_resource(root, "", *list, &value, &limit); |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
49 if (ret < 0) |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
50 break; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 if (ret > 0) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 if (i > 0) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 str_append_c(str, ' '); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 str_printfa(str, "%s %llu %llu", *list, |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 (unsigned long long)value, |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 (unsigned long long)limit); |
4241
4fa5cda580db
Don't add extra spaces to reply if some of the resources aren't really found.
Timo Sirainen <tss@iki.fi>
parents:
4084
diff
changeset
|
57 i++; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 } |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
60 str_append(str, ")\r\n"); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
61 |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
62 if (ret < 0) |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
63 str_append(str, "* BAD Internal quota calculation error\r\n"); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3750
diff
changeset
|
66 static bool cmd_getquotaroot(struct client_command_context *cmd) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 { |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
68 struct client *client = cmd->client; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 struct mail_storage *storage; |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
70 struct mail_namespace *ns; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 struct mailbox *box; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 struct quota_root_iter *iter; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 struct quota_root *root; |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
74 const char *orig_mailbox, *mailbox, *name; |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
75 string_t *quotaroot_reply, *quota_reply; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 /* <mailbox> */ |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 if (!client_read_string_args(cmd, 1, &mailbox)) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 return FALSE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
5253
535ff7687388
When returning mailbox name with GETQUOTAROOT, return the original name
Timo Sirainen <tss@iki.fi>
parents:
5185
diff
changeset
|
81 orig_mailbox = mailbox; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 storage = client_find_storage(cmd, &mailbox); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 if (storage == NULL) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
8468
d4eab639c253
mailbox_open() now takes struct mail_storage ** so it can be changed.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
86 box = mailbox_open(&storage, mailbox, NULL, (MAILBOX_OPEN_READONLY | |
d4eab639c253
mailbox_open() now takes struct mail_storage ** so it can be changed.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
87 MAILBOX_OPEN_FAST | |
d4eab639c253
mailbox_open() now takes struct mail_storage ** so it can be changed.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
88 MAILBOX_OPEN_KEEP_RECENT)); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 if (box == NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 client_send_storage_error(cmd, storage); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
94 ns = mail_storage_get_namespace(storage); |
8959
33f3016673aa
imap-quota: Allow GETQUOTAROOT for public namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
95 if (quota_set == NULL) { |
4473
5811b2c183fd
If there is no quota for the user, GETQUOTAROOT leaked memory
Timo Sirainen <tss@iki.fi>
parents:
4241
diff
changeset
|
96 mailbox_close(&box); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 client_send_tagline(cmd, "OK No quota."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 } |
8959
33f3016673aa
imap-quota: Allow GETQUOTAROOT for public namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
100 if (ns->owner != NULL && ns->owner != client->user && |
33f3016673aa
imap-quota: Allow GETQUOTAROOT for public namespaces.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
101 !client->user->admin) { |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
102 mailbox_close(&box); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
103 client_send_tagline(cmd, "NO Not showing other users' quota."); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
104 return TRUE; |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
105 } |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
107 /* build QUOTAROOT reply and QUOTA reply for all quota roots */ |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
108 quotaroot_reply = t_str_new(128); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
109 quota_reply = t_str_new(256); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
110 str_append(quotaroot_reply, "* QUOTAROOT "); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
111 imap_quote_append_string(quotaroot_reply, mailbox, FALSE); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 |
8082
db66611fd195
Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
113 iter = quota_root_iter_init(box); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 while ((root = quota_root_iter_next(iter)) != NULL) { |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
115 str_append_c(quotaroot_reply, ' '); |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
116 name = imap_quota_root_get_name(client->user, ns->owner, root); |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
117 imap_quote_append_string(quotaroot_reply, name, FALSE); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
118 |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
119 quota_reply_write(quota_reply, client->user, ns->owner, root); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 } |
5566
88307a648e0e
Use sync_notify() callback to count expunges. This makes the calculation
Timo Sirainen <tss@iki.fi>
parents:
5253
diff
changeset
|
121 quota_root_iter_deinit(&iter); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
122 mailbox_close(&box); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
124 /* send replies */ |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
125 client_send_line(client, str_c(quotaroot_reply)); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
126 o_stream_send(client->output, str_data(quota_reply), |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
127 str_len(quota_reply)); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 client_send_tagline(cmd, "OK Getquotaroot completed."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3750
diff
changeset
|
132 static bool cmd_getquota(struct client_command_context *cmd) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 { |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
134 struct mail_user *owner = cmd->client->user; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 struct quota_root *root; |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
136 const char *root_name, *p; |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
137 string_t *quota_reply; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 /* <quota root> */ |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 if (!client_read_string_args(cmd, 1, &root_name)) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 return FALSE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
4796
49c9e7588de4
s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents:
4513
diff
changeset
|
143 if (quota_set == NULL) { |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 client_send_tagline(cmd, "OK No quota."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 |
8082
db66611fd195
Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
148 root = quota_root_lookup(cmd->client->user, root_name); |
8470
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
149 if (root == NULL && cmd->client->user->admin) { |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
150 /* we're an admin. see if there's a quota root for another |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
151 user. */ |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
152 p = strchr(root_name, QUOTA_USER_SEPARATOR); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
153 if (p != NULL) { |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
154 owner = mail_user_find(cmd->client->user, |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
155 t_strdup_until(root_name, p)); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
156 root = owner == NULL ? NULL : |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
157 quota_root_lookup(owner, p + 1); |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
158 } |
e4f319453cb2
Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8468
diff
changeset
|
159 } |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 if (root == NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 client_send_tagline(cmd, "NO Quota root doesn't exist."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 |
9564
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
165 quota_reply = t_str_new(128); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
166 quota_reply_write(quota_reply, cmd->client->user, owner, root); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
167 o_stream_send(cmd->client->output, str_data(quota_reply), |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
168 str_len(quota_reply)); |
efe0efc22d22
imap-quota: Iterate quota roots only once when replying to GETQUOTAROOT.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
169 |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
170 client_send_tagline(cmd, "OK Getquota completed."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
173 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3750
diff
changeset
|
174 static bool cmd_setquota(struct client_command_context *cmd) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 struct quota_root *root; |
5835
d59ed6a31b66
Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents:
5568
diff
changeset
|
177 const struct imap_arg *args, *arg; |
4513
f91f3bcb7939
Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4473
diff
changeset
|
178 const char *root_name, *name, *error; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 uint64_t value; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
180 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 /* <quota root> <resource limits> */ |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
182 if (!client_read_args(cmd, 2, 0, &args)) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 return FALSE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 root_name = imap_arg_string(&args[0]); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 if (args[1].type != IMAP_ARG_LIST || root_name == NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 client_send_command_error(cmd, "Invalid arguments."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
4796
49c9e7588de4
s/quota/quota_set/ so we don't conflict with the quota symbol already
Timo Sirainen <tss@iki.fi>
parents:
4513
diff
changeset
|
191 if (quota_set == NULL) { |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 client_send_tagline(cmd, "OK No quota."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 |
8082
db66611fd195
Added struct mail_user and fixed the code to support multiple users per process.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
196 root = quota_root_lookup(cmd->client->user, root_name); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 if (root == NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 client_send_tagline(cmd, "NO Quota root doesn't exist."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 |
5836
9f869a7a3d73
Changed imap-parser API to use standard arrays for lists instead of its own
Timo Sirainen <tss@iki.fi>
parents:
5835
diff
changeset
|
202 arg = IMAP_ARG_LIST_ARGS(&args[1]); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 for (; arg->type != IMAP_ARG_EOL; arg += 2) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 name = imap_arg_string(arg); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 if (name == NULL || arg[1].type != IMAP_ARG_ATOM || |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 !is_numeric(IMAP_ARG_STR(&arg[1]), '\0')) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 client_send_command_error(cmd, "Invalid arguments."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 value = strtoull(IMAP_ARG_STR_NONULL(&arg[1]), NULL, 10); |
4513
f91f3bcb7939
Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4473
diff
changeset
|
212 if (quota_set_resource(root, name, value, &error) < 0) { |
f91f3bcb7939
Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4473
diff
changeset
|
213 client_send_command_error(cmd, error); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 client_send_tagline(cmd, "OK Setquota completed."); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 return TRUE; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 |
3750
b752272e6355
Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
222 void imap_quota_plugin_init(void) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 { |
5568
cce4074b7876
Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents:
5566
diff
changeset
|
224 command_register("GETQUOTAROOT", cmd_getquotaroot, 0); |
cce4074b7876
Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents:
5566
diff
changeset
|
225 command_register("GETQUOTA", cmd_getquota, 0); |
cce4074b7876
Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents:
5566
diff
changeset
|
226 command_register("SETQUOTA", cmd_setquota, 0); |
3993
12ff7067ce62
Advertise the QUOTA capability if the plugin is loaded.
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
227 str_append(capability_string, " QUOTA"); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 |
3750
b752272e6355
Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
230 void imap_quota_plugin_deinit(void) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 command_unregister("GETQUOTAROOT"); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 command_unregister("GETQUOTA"); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 command_unregister("SETQUOTA"); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 } |