annotate src/plugins/imap-quota/imap-quota-plugin.c @ 8959:33f3016673aa HEAD

imap-quota: Allow GETQUOTAROOT for public namespaces.
author Timo Sirainen <tss@iki.fi>
date Thu, 16 Apr 2009 21:56:20 -0400
parents b9faf4db2a9f
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 8470
diff changeset
1 /* Copyright (c) 2005-2009 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"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "imap-quote.h"
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
6 #include "mail-namespace.h"
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "commands.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "quota.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "imap-quota-plugin.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include <stdlib.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
14 #define QUOTA_USER_SEPARATOR ':'
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
15
5185
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 4796
diff changeset
16 const char *imap_quota_plugin_version = PACKAGE_VERSION;
24f4a959a24c Added <plugin_name>_version string.
Timo Sirainen <tss@iki.fi>
parents: 4796
diff changeset
17
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
18 static const char *
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
19 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
20 struct quota_root *root)
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
21 {
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
22 const char *name;
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
23
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
24 name = quota_root_get_name(root);
8959
33f3016673aa imap-quota: Allow GETQUOTAROOT for public namespaces.
Timo Sirainen <tss@iki.fi>
parents: 8590
diff changeset
25 if (user == owner || owner == NULL)
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
26 return name;
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
27 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
28 QUOTA_USER_SEPARATOR, name);
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
29 }
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
30
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 static void
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
32 quota_send(struct client_command_context *cmd, struct mail_user *owner,
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
33 struct quota_root *root)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 {
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
35 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
36 string_t *str;
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;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 int ret;
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 = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 str_append(str, "* QUOTA ");
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
43 name = imap_quota_root_get_name(cmd->client->user, owner, root);
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
44 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
45
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 str_append(str, " (");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 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
48 for (i = 0; *list != NULL; list++) {
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
49 ret = quota_get_resource(root, "", *list, &value, &limit);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 if (ret > 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 if (i > 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 str_append_c(str, ' ');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 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
54 (unsigned long long)value,
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 (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
56 i++;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 } else if (ret < 0) {
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
58 client_send_line(cmd->client,
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
59 "* BAD Internal quota calculation error");
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 str_append_c(str, ')');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 client_send_line(cmd->client, str_c(str));
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;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 string_t *str;
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
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 /* send QUOTAROOT reply */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 str = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 str_append(str, "* QUOTAROOT ");
5253
535ff7687388 When returning mailbox name with GETQUOTAROOT, return the original name
Timo Sirainen <tss@iki.fi>
parents: 5185
diff changeset
110 imap_quote_append_string(str, orig_mailbox, FALSE);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111
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
112 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
113 while ((root = quota_root_iter_next(iter)) != NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 str_append_c(str, ' ');
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
115 name = imap_quota_root_get_name(client->user, ns->owner, root);
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
116 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
117 }
5566
88307a648e0e Use sync_notify() callback to count expunges. This makes the calculation
Timo Sirainen <tss@iki.fi>
parents: 5253
diff changeset
118 quota_root_iter_deinit(&iter);
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
119 client_send_line(client, str_c(str));
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 /* send QUOTA reply for each quotaroot */
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
122 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
123 while ((root = quota_root_iter_next(iter)) != NULL)
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
124 quota_send(cmd, ns->owner, root);
5566
88307a648e0e Use sync_notify() callback to count expunges. This makes the calculation
Timo Sirainen <tss@iki.fi>
parents: 5253
diff changeset
125 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
126 mailbox_close(&box);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127
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;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 /* <quota root> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 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
140 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141
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
142 if (quota_set == NULL) {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 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
144 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146
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
147 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
148 if (root == NULL && cmd->client->user->admin) {
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
149 /* 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
150 user. */
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
151 p = strchr(root_name, QUOTA_USER_SEPARATOR);
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
152 if (p != NULL) {
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
153 owner = mail_user_find(cmd->client->user,
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
154 t_strdup_until(root_name, p));
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
155 root = owner == NULL ? NULL :
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
156 quota_root_lookup(owner, p + 1);
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
157 }
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
158 }
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 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
161 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163
8470
e4f319453cb2 Quota works now properly with shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents: 8468
diff changeset
164 quota_send(cmd, owner, root);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 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
166 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168
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
169 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
170 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 struct quota_root *root;
5835
d59ed6a31b66 Added more consts to imap-parser API
Timo Sirainen <tss@iki.fi>
parents: 5568
diff changeset
172 const struct imap_arg *args, *arg;
4513
f91f3bcb7939 Fixes to make it compile again.
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4473
diff changeset
173 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
174 uint64_t value;
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 /* <quota root> <resource limits> */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 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
178 return FALSE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 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
181 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
182 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
183 return TRUE;
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
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
186 if (quota_set == NULL) {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 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
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
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
191 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
192 if (root == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 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
194 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
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
197 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
198 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
199 name = imap_arg_string(arg);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 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
201 !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
202 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
203 return TRUE;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
204 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 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
207 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
208 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
209 return TRUE;
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 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
212
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
213 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
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
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
217 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
218 {
5568
cce4074b7876 Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents: 5566
diff changeset
219 command_register("GETQUOTAROOT", cmd_getquotaroot, 0);
cce4074b7876 Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents: 5566
diff changeset
220 command_register("GETQUOTA", cmd_getquota, 0);
cce4074b7876 Added command flags parameter to command_register()
Timo Sirainen <tss@iki.fi>
parents: 5566
diff changeset
221 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
222 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
223 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224
3750
b752272e6355 Init/deinit function names were wrong
Timo Sirainen <tss@iki.fi>
parents: 3738
diff changeset
225 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
226 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
227 command_unregister("GETQUOTAROOT");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
228 command_unregister("GETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
229 command_unregister("SETQUOTA");
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
230 }