4 * IMAP METADATA extension
6 * This is a partial implementation of draft-daboo-imap-annotatemore-11
7 * intended to help a specific connector product work with Citadel.
20 #include <sys/types.h>
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
39 #include "sysdep_decls.h"
40 #include "citserver.h"
43 #include "serv_extensions.h"
50 #include "internet_addressing.h"
51 #include "serv_imap.h"
52 #include "imap_tools.h"
53 #include "imap_fetch.h"
54 #include "imap_misc.h"
60 * Implements the SETMETADATA command.
62 * Again, the only thing we're interested in setting here is the folder type.
64 * Attempting to set anything else calls a stub which fools the client into
65 * thinking that there is no remaining space available to store annotations.
67 void imap_setmetadata(int num_parms, char *parms[]) {
68 char roomname[ROOMNAMELEN];
69 char savedroom[ROOMNAMELEN];
72 int setting_user_value = 0;
76 cprintf("%s BAD usage error\r\n", parms[0]);
81 * Don't allow other types of metadata to be set
83 if (strcasecmp(parms[3], "/vendor/kolab/folder-type")) {
84 cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
88 if (!strcasecmp(parms[4], "(value.shared")) {
89 setting_user_value = 0; /* global view */
91 else if (!strcasecmp(parms[4], "(value.priv")) {
92 setting_user_value = 1; /* per-user view */
95 cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
100 * Extract the folder type without any parentheses.
102 extract_token(set_value, parms[5], 0, ')', sizeof set_value);
104 ret = imap_grabroom(roomname, parms[2], 0);
106 cprintf("%s NO Invalid mailbox name or access denied\r\n",
112 * usergoto() formally takes us to the desired room. (If another
113 * folder is selected, save its name so we can return there!!!!!)
115 if (IMAP->selected) {
116 strcpy(savedroom, CC->room.QRname);
118 usergoto(roomname, 0, 0, &msgs, &new);
121 * FIXME ... NOW DO SOMETHING
125 * on success: cprintf("%s OK SETANNOTATION complete\r\n", parms[0]);
128 cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
131 * If a different folder was previously selected, return there now.
133 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
134 usergoto(savedroom, 0, 0, &msgs, &new);
141 * Implements the GETMETADATA command.
143 * Regardless of what the client asked for, we are going to supply them with
144 * the folder type. It's the only metadata we have anyway.
146 void imap_getmetadata(int num_parms, char *parms[]) {
147 char roomname[ROOMNAMELEN];
148 char savedroom[ROOMNAMELEN];
153 cprintf("%s BAD usage error\r\n", parms[0]);
157 ret = imap_grabroom(roomname, parms[2], 0);
159 cprintf("%s NO Invalid mailbox name or access denied\r\n",
165 * usergoto() formally takes us to the desired room. (If another
166 * folder is selected, save its name so we can return there!!!!!)
168 if (IMAP->selected) {
169 strcpy(savedroom, CC->room.QRname);
171 usergoto(roomname, 0, 0, &msgs, &new);
173 cprintf("* METADATA ");
174 imap_strout(parms[2]);
175 cprintf(" \"/vendor/kolab/folder-type\" (\"value.shared\" \"");
177 /* If it's one of our hard-coded default rooms, we know what to do... */
179 if (!strcasecmp(&CC->room.QRname[11], MAILROOM)) {
180 cprintf("mail.inbox");
182 else if (!strcasecmp(&CC->room.QRname[11], SENTITEMS)) {
183 cprintf("mail.sentitems");
185 else if (!strcasecmp(&CC->room.QRname[11], USERCALENDARROOM)) {
186 cprintf("event.default");
188 else if (!strcasecmp(&CC->room.QRname[11], USERCONTACTSROOM)) {
189 cprintf("contact.default");
191 else if (!strcasecmp(&CC->room.QRname[11], USERNOTESROOM)) {
192 cprintf("note.default");
194 else if (!strcasecmp(&CC->room.QRname[11], USERTASKSROOM)) {
195 cprintf("task.default");
198 /* Otherwise, use the view for this room to determine the type of data.
199 * We are going with the default view rather than the user's view, because
200 * the default view almost always defines the actual contents, while the
201 * user's view might only make changes to presentation. It also saves us
202 * an extra database access because we don't need to load the visit record.
205 else if (CC->room.QRdefaultview == VIEW_CALENDAR) {
208 else if (CC->room.QRdefaultview == VIEW_ADDRESSBOOK) {
211 else if (CC->room.QRdefaultview == VIEW_TASKS) {
214 else if (CC->room.QRdefaultview == VIEW_NOTES) {
217 else if (CC->room.QRdefaultview == VIEW_JOURNAL) {
221 /* If none of the above conditions were met, consider it an ordinary mailbox. */
226 /* "mail.outbox" and "junkemail" are not implemented. */
231 * If a different folder was previously selected, return there now.
233 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
234 usergoto(savedroom, 0, 0, &msgs, &new);
237 cprintf("%s OK GETMETADATA complete\r\n", parms[0]);