4 * Functions which implement RFC2086 (and maybe RFC4314) (IMAP ACL extension)
7 * Copyright (c) 2007-2009 by the citadel.org team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/types.h>
34 #if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
39 # include <sys/time.h>
49 #include <libcitadel.h>
52 #include "sysdep_decls.h"
53 #include "citserver.h"
59 #include "internet_addressing.h"
60 #include "imap_tools.h"
61 #include "serv_imap.h"
62 #include "imap_fetch.h"
63 #include "imap_misc.h"
65 #include "ctdl_module.h"
69 * Implements the SETACL command.
71 void imap_setacl(int num_parms, ConstStr *Params) {
73 cprintf("%s BAD not yet implemented FIXME\r\n", Params[0].Key);
79 * Implements the DELETEACL command.
81 void imap_deleteacl(int num_parms, ConstStr *Params) {
83 cprintf("%s BAD not yet implemented FIXME\r\n", Params[0].Key);
89 * Given the bits returned by CtdlRoomAccess(), populate a string buffer
90 * with IMAP ACL format flags. This code is common to GETACL and MYRIGHTS.
92 void imap_acl_flags(char *rights, int ra)
96 /* l - lookup (mailbox is visible to LIST/LSUB commands)
97 * r - read (SELECT the mailbox, perform STATUS et al)
98 * s - keep seen/unseen information across sessions (STORE SEEN flag)
100 if ( (ra & UA_KNOWN) /* known rooms */
101 || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED)) /* zapped rooms */
107 /* Only output the remaining flags if the room is known */
109 /* w - write (set or clear flags other than SEEN or DELETED, not supported in Citadel */
111 /* i - insert (perform APPEND, COPY into mailbox) */
112 /* p - post (send mail to submission address for mailbox - not enforced) */
113 /* c - create (CREATE new sub-mailboxes) */
114 if (ra & UA_POSTALLOWED) {
120 /* d - delete messages (STORE DELETED flag, perform EXPUNGE) */
121 if (ra & UA_DELETEALLOWED) {
125 /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */
126 if (ra & UA_ADMINALLOWED) {
128 * This is the correct place to put the "a" flag. We are leaving
129 * it commented out for now, because it implies that we could
130 * perform any of SETACL/DELETEACL/GETACL/LISTRIGHTS. Since these
131 * commands are not yet implemented, omitting the flag should
132 * theoretically prevent compliant clients from attempting to
135 * strcat(rights, "a");
143 * Implements the GETACL command.
145 void imap_getacl(int num_parms, ConstStr *Params) {
146 char roomname[ROOMNAMELEN];
147 char savedroom[ROOMNAMELEN];
150 struct ctdluser temp;
151 struct cdbdata *cdbus;
155 if (num_parms != 3) {
156 cprintf("%s BAD usage error\r\n", Params[0].Key);
161 * Search for the specified room or folder
163 ret = imap_grabroom(roomname, Params[2].Key, 1);
165 cprintf("%s NO Invalid mailbox name or access denied\r\n", Params[0].Key);
170 * CtdlUserGoto() formally takes us to the desired room. (If another
171 * folder is selected, save its name so we can return there!!!!!)
173 if (IMAP->selected) {
174 strcpy(savedroom, CC->room.QRname);
176 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
180 imap_strout(&Params[2]);
183 * Traverse the userlist
185 cdb_rewind(CDB_USERS);
186 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
187 memset(&temp, 0, sizeof temp);
188 memcpy(&temp, cdbus->ptr, sizeof temp);
191 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
192 if (!IsEmptyStr(temp.fullname)) {
193 imap_acl_flags(rights, ra);
194 if (!IsEmptyStr(rights)) {
196 plain_imap_strout(temp.fullname);
197 cprintf(" %s", rights);
205 * If another folder is selected, go back to that room so we can resume
206 * our happy day without violent explosions.
208 if (IMAP->selected) {
209 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
212 cprintf("%s OK GETACL completed\r\n", Params[0].Key);
217 * Implements the LISTRIGHTS command.
219 void imap_listrights(int num_parms, ConstStr *Params) {
220 char roomname[ROOMNAMELEN];
221 char savedroom[ROOMNAMELEN];
224 struct recptypes *valid;
225 struct ctdluser temp;
227 if (num_parms != 4) {
228 cprintf("%s BAD usage error\r\n", Params[0].Key);
233 * Search for the specified room/folder
235 ret = imap_grabroom(roomname, Params[2].Key, 1);
237 cprintf("%s NO Invalid mailbox name or access denied\r\n", Params[0].Key);
242 * Search for the specified user
245 valid = validate_recipients(Params[3].Key, NULL, 0);
247 if (valid->num_local == 1) {
248 ret = CtdlGetUser(&temp, valid->recp_local);
250 free_recipients(valid);
253 cprintf("%s NO Invalid user name or access denied\r\n", Params[0].Key);
258 * CtdlUserGoto() formally takes us to the desired room. (If another
259 * folder is selected, save its name so we can return there!!!!!)
261 if (IMAP->selected) {
262 strcpy(savedroom, CC->room.QRname);
264 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
267 * Now output the list of rights
269 cprintf("* LISTRIGHTS ");
270 imap_strout(&Params[2]);
272 imap_strout(&Params[3]);
274 plain_imap_strout(""); /* FIXME ... do something here */
278 * If another folder is selected, go back to that room so we can resume
279 * our happy day without violent explosions.
281 if (IMAP->selected) {
282 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
285 cprintf("%s OK LISTRIGHTS completed\r\n", Params[0].Key);
291 * Implements the MYRIGHTS command.
293 void imap_myrights(int num_parms, ConstStr *Params) {
294 char roomname[ROOMNAMELEN];
295 char savedroom[ROOMNAMELEN];
301 if (num_parms != 3) {
302 cprintf("%s BAD usage error\r\n", Params[0].Key);
306 ret = imap_grabroom(roomname, Params[2].Key, 1);
308 cprintf("%s NO Invalid mailbox name or access denied\r\n", Params[0].Key);
313 * CtdlUserGoto() formally takes us to the desired room. (If another
314 * folder is selected, save its name so we can return there!!!!!)
316 if (IMAP->selected) {
317 strcpy(savedroom, CC->room.QRname);
319 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
321 CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
322 imap_acl_flags(rights, ra);
324 cprintf("* MYRIGHTS ");
325 imap_strout(&Params[2]);
326 cprintf(" %s\r\n", rights);
329 * If a different folder was previously selected, return there now.
331 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
332 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
335 cprintf("%s OK MYRIGHTS completed\r\n", Params[0].Key);