4 * Functions which implement RFC2086/RFC4314 (IMAP ACL extension)
17 #include <sys/types.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
40 #include "serv_extensions.h"
47 #include "internet_addressing.h"
48 #include "serv_imap.h"
49 #include "imap_tools.h"
50 #include "imap_fetch.h"
51 #include "imap_misc.h"
57 * Implements the SETACL command.
59 void imap_setacl(int num_parms, char *parms[]) {
61 cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
67 * Implements the DELETEACL command.
69 void imap_deleteacl(int num_parms, char *parms[]) {
71 cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
77 * Given the bits returned by CtdlRoomAccess(), populate a string buffer
78 * with IMAP ACL format flags. This code is common to GETACL and MYRIGHTS.
80 void imap_acl_flags(char *rights, int ra)
84 /* l - lookup (mailbox is visible to LIST/LSUB commands, SUBSCRIBE mailbox)
85 * r - read (SELECT the mailbox, perform STATUS)
86 * s - keep seen/unseen information across sessions (set or clear \SEEN flag
87 * via STORE, also set \SEEN during APPEND/COPY/ FETCH BODY[...])
88 * e - perform EXPUNGE and expunge as a part of CLOSE
90 if ( (ra & UA_KNOWN) /* known rooms */
91 || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED)) /* zapped rooms */
98 /* Only output the remaining flags if the room is known */
100 /* w - write (set or clear arbitrary flags; not supported in Citadel) */
102 /* i - insert (perform APPEND, COPY into mailbox) */
103 /* p - post (send mail to submission address for mailbox - not enforced) */
104 if (ra & UA_POSTALLOWED) {
109 /* k - create mailboxes in this hierarchy */
111 /* t - delete messages (set/clear \Deleted flag) */
113 /* a - administer (perform SETACL/DELETEACL/GETACL/LISTRIGHTS) */
114 /* x - delete mailbox (DELETE mailbox, old mailbox name in RENAME) */
115 if (ra & UA_ADMINALLOWED) {
124 * Implements the GETACL command.
126 void imap_getacl(int num_parms, char *parms[]) {
127 char roomname[ROOMNAMELEN];
128 char savedroom[ROOMNAMELEN];
131 struct ctdluser temp;
132 struct cdbdata *cdbus;
136 if (num_parms != 3) {
137 cprintf("%s BAD usage error\r\n", parms[0]);
141 ret = imap_grabroom(roomname, parms[2], 0);
143 cprintf("%s NO Invalid mailbox name or access denied\r\n",
149 * usergoto() formally takes us to the desired room. (If another
150 * folder is selected, save its name so we can return there!!!!!)
152 if (IMAP->selected) {
153 strcpy(savedroom, CC->room.QRname);
155 usergoto(roomname, 0, 0, &msgs, &new);
159 imap_strout(parms[2]);
162 * Traverse the userlist
164 cdb_rewind(CDB_USERS);
165 while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
166 memset(&temp, 0, sizeof temp);
167 memcpy(&temp, cdbus->ptr, sizeof temp);
170 CtdlRoomAccess(&CC->room, &temp, &ra, NULL);
171 if (strlen(temp.fullname) > 0) {
172 imap_acl_flags(rights, ra);
173 if (strlen(rights) > 0) {
175 imap_strout(temp.fullname);
176 cprintf(" %s", rights);
184 * If another folder is selected, go back to that room so we can resume
185 * our happy day without violent explosions.
187 if (IMAP->selected) {
188 usergoto(savedroom, 0, 0, &msgs, &new);
191 cprintf("%s OK GETACL completed\r\n", parms[0]);
196 * Implements the LISTRIGHTS command.
198 void imap_listrights(int num_parms, char *parms[]) {
200 cprintf("%s BAD not yet implemented FIXME\r\n", parms[0]);
206 * Implements the MYRIGHTS command.
208 void imap_myrights(int num_parms, char *parms[]) {
209 char roomname[ROOMNAMELEN];
210 char savedroom[ROOMNAMELEN];
216 if (num_parms != 3) {
217 cprintf("%s BAD usage error\r\n", parms[0]);
221 ret = imap_grabroom(roomname, parms[2], 0);
223 cprintf("%s NO Invalid mailbox name or access denied\r\n",
229 * usergoto() formally takes us to the desired room. (If another
230 * folder is selected, save its name so we can return there!!!!!)
232 if (IMAP->selected) {
233 strcpy(savedroom, CC->room.QRname);
235 usergoto(roomname, 0, 0, &msgs, &new);
237 cprintf("* MYRIGHTS ");
238 imap_strout(parms[2]);
241 CtdlRoomAccess(&CC->room, &CC->user, &ra, NULL);
242 imap_acl_flags(rights, ra);
248 * If another folder is selected, go back to that room so we can resume
249 * our happy day without violent explosions.
251 if (IMAP->selected) {
252 usergoto(savedroom, 0, 0, &msgs, &new);
255 cprintf("%s OK MYRIGHTS completed\r\n", parms[0]);