2 * IMAP METADATA extension
4 * This is an implementation of the Bynari variant of the METADATA extension.
6 * Copyright (c) 2007-2017 by the citadel.org team
8 * This program is open source software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "../../sysdep.h"
32 #include <sys/types.h>
38 #include <libcitadel.h>
39 #include "../../citadel_defs.h"
40 #include "../../server.h"
41 #include "../../sysdep_decls.h"
42 #include "../../citserver.h"
43 #include "../../support.h"
44 #include "../../config.h"
45 #include "../../user_ops.h"
46 #include "../../database.h"
47 #include "../../msgbase.h"
48 #include "../../internet_addressing.h"
49 #include "serv_imap.h"
50 #include "imap_tools.h"
51 #include "imap_fetch.h"
52 #include "imap_misc.h"
53 #include "../../genstamp.h"
54 #include "../../ctdl_module.h"
57 * Implements the SETMETADATA command.
59 * Again, the only thing we're interested in setting here is the folder type.
61 * Attempting to set anything else calls a stub which fools the client into
62 * thinking that there is no remaining space available to store annotations.
64 void imap_setmetadata(int num_parms, ConstStr *Params) {
65 char roomname[ROOMNAMELEN];
66 char savedroom[ROOMNAMELEN];
69 int setting_user_value = 0;
71 int set_view = VIEW_BBS;
75 IReply("BAD usage error");
80 * Don't allow other types of metadata to be set
82 if (strcasecmp(Params[3].Key, "/vendor/kolab/folder-type")) {
83 IReply("NO [METADATA TOOMANY] SETMETADATA failed");
87 if (!strcasecmp(Params[4].Key, "(value.shared")) {
88 setting_user_value = 0; /* global view */
90 else if (!strcasecmp(Params[4].Key, "(value.priv")) {
91 setting_user_value = 1; /* per-user view */
94 IReply("NO [METADATA TOOMANY] SETMETADATA failed");
99 * Extract the folder type without any parentheses. Then learn
100 * the Citadel view type based on the supplied folder type.
102 extract_token(set_value, Params[5].Key, 0, ')', sizeof set_value);
103 if (!strncasecmp(set_value, "mail", 4)) {
104 set_view = VIEW_MAILBOX;
106 else if (!strncasecmp(set_value, "event", 5)) {
107 set_view = VIEW_CALENDAR;
109 else if (!strncasecmp(set_value, "contact", 7)) {
110 set_view = VIEW_ADDRESSBOOK;
112 else if (!strncasecmp(set_value, "journal", 7)) {
113 set_view = VIEW_JOURNAL;
115 else if (!strncasecmp(set_value, "note", 4)) {
116 set_view = VIEW_NOTES;
118 else if (!strncasecmp(set_value, "task", 4)) {
119 set_view = VIEW_TASKS;
122 set_view = VIEW_MAILBOX;
125 ret = imap_grabroom(roomname, Params[2].Key, 1);
127 IReply("NO Invalid mailbox name or access denied");
132 * CtdlUserGoto() formally takes us to the desired room. (If another
133 * folder is selected, save its name so we can return there!!!!!)
135 if (IMAP->selected) {
136 strcpy(savedroom, CC->room.QRname);
138 CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
141 * Always set the per-user view to the requested one.
143 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
144 vbuf.v_view = set_view;
145 CtdlSetRelationship(&vbuf, &CC->user, &CC->room);
147 /* If this is a "value.priv" set operation, we're done. */
149 if (setting_user_value)
151 IReply("OK SETANNOTATION complete");
154 /* If this is a "value.shared" set operation, we are allowed to perform it
155 * under certain conditions.
157 else if ( (is_room_aide()) /* aide or room aide */
158 || ( (CC->room.QRflags & QR_MAILBOX)
159 && (CC->user.usernum == atol(CC->room.QRname)) /* mailbox owner */
161 || (msgs == 0) /* hack: if room is empty, assume we just created it */
163 CtdlGetRoomLock(&CC->room, CC->room.QRname);
164 CC->room.QRdefaultview = set_view;
165 CtdlPutRoomLock(&CC->room);
166 IReply("OK SETANNOTATION complete");
169 /* If we got to this point, we don't have permission to set the default view. */
171 IReply("NO [METADATA TOOMANY] SETMETADATA failed");
175 * If a different folder was previously selected, return there now.
177 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
178 CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
185 * Implements the GETMETADATA command.
187 * Regardless of what the client asked for, we are going to supply them with
188 * the folder type. It's the only metadata we have anyway.
190 void imap_getmetadata(int num_parms, ConstStr *Params) {
191 char roomname[ROOMNAMELEN];
192 char savedroom[ROOMNAMELEN];
197 /* this doesn't work if you have rooms/floors with spaces.
198 we need this for the bynari connector.
200 IReply("BAD usage error");
204 ret = imap_grabroom(roomname, Params[2].Key, 1);
206 IReply("NO Invalid mailbox name or access denied");
211 * CtdlUserGoto() formally takes us to the desired room. (If another
212 * folder is selected, save its name so we can return there!!!!!)
214 if (IMAP->selected) {
215 strcpy(savedroom, CC->room.QRname);
217 CtdlUserGoto(roomname, 0, 0, &msgs, &new, NULL, NULL);
219 IAPuts("* METADATA ");
221 IAPuts(" \"/vendor/kolab/folder-type\" (\"value.shared\" \"");
223 /* If it's one of our hard-coded default rooms, we know what to do... */
225 if (CC->room.QRname[10] == '.')
227 if (!strcasecmp(&CC->room.QRname[11], MAILROOM)) {
229 IAPuts("mail.inbox");
231 else if (!strcasecmp(&CC->room.QRname[11], SENTITEMS)) {
233 IAPuts("mail.sentitems");
235 else if (!strcasecmp(&CC->room.QRname[11], USERDRAFTROOM)) {
237 IAPuts("mail.drafts");
239 else if (!strcasecmp(&CC->room.QRname[11], USERCALENDARROOM)) {
241 IAPuts("event.default");
243 else if (!strcasecmp(&CC->room.QRname[11], USERCONTACTSROOM)) {
245 IAPuts("contact.default");
247 else if (!strcasecmp(&CC->room.QRname[11], USERNOTESROOM)) {
249 IAPuts("note.default");
251 else if (!strcasecmp(&CC->room.QRname[11], USERTASKSROOM)) {
253 IAPuts("task.default");
257 /* Otherwise, use the view for this room to determine the type of data.
258 * We are going with the default view rather than the user's view, because
259 * the default view almost always defines the actual contents, while the
260 * user's view might only make changes to presentation. It also saves us
261 * an extra database access because we don't need to load the visit record.
265 if (CC->room.QRdefaultview == VIEW_CALENDAR) {
268 else if (CC->room.QRdefaultview == VIEW_ADDRESSBOOK) {
271 else if (CC->room.QRdefaultview == VIEW_TASKS) {
274 else if (CC->room.QRdefaultview == VIEW_NOTES) {
277 else if (CC->room.QRdefaultview == VIEW_JOURNAL) {
281 /* If none of the above conditions were met, consider it an ordinary mailbox. */
287 /* "mail.outbox" and "junkemail" are not implemented. */
292 * If a different folder was previously selected, return there now.
294 if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
295 CtdlUserGoto(savedroom, 0, 0, &msgs, &new, NULL, NULL);
298 IReply("OK GETMETADATA complete");