More removal of $Id$ tags
[citadel.git] / citadel / modules / imap / imap_metadata.c
index 4dde983f9792799d650984badac55d8006417b9d..5ffa1f5b08d9ce4b6b9b85a15b82febfe3481641 100644 (file)
@@ -1,10 +1,23 @@
 /*
- * $Id$
- *
  * IMAP METADATA extension
  *
  * This is an implementation of the Bynari variant of the METADATA extension.
  *
+ * Copyright (c) 2007-2009 by the citadel.org team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "room_ops.h"
 #include "user_ops.h"
-#include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
-#include "serv_imap.h"
 #include "imap_tools.h"
+#include "serv_imap.h"
 #include "imap_fetch.h"
 #include "imap_misc.h"
 #include "genstamp.h"
 
-
+#include "ctdl_module.h"
 
 /*
  * Implements the SETMETADATA command.
@@ -62,7 +73,7 @@
  * Attempting to set anything else calls a stub which fools the client into
  * thinking that there is no remaining space available to store annotations.
  */
-void imap_setmetadata(int num_parms, char *parms[]) {
+void imap_setmetadata(int num_parms, ConstStr *Params) {
        char roomname[ROOMNAMELEN];
        char savedroom[ROOMNAMELEN];
        int msgs, new;
@@ -70,29 +81,29 @@ void imap_setmetadata(int num_parms, char *parms[]) {
        int setting_user_value = 0;
        char set_value[32];
        int set_view = VIEW_BBS;
-       struct visit vbuf;
+       visit vbuf;
 
        if (num_parms != 6) {
-               cprintf("%s BAD usage error\r\n", parms[0]);
+               cprintf("%s BAD usage error\r\n", Params[0].Key);
                return;
        }
 
        /*
         * Don't allow other types of metadata to be set
         */
-       if (strcasecmp(parms[3], "/vendor/kolab/folder-type")) {
-               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
+       if (strcasecmp(Params[3].Key, "/vendor/kolab/folder-type")) {
+               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", Params[0].Key);
                return;
        }
 
-       if (!strcasecmp(parms[4], "(value.shared")) {
+       if (!strcasecmp(Params[4].Key, "(value.shared")) {
                setting_user_value = 0;                         /* global view */
        }
-       else if (!strcasecmp(parms[4], "(value.priv")) {
+       else if (!strcasecmp(Params[4].Key, "(value.priv")) {
                setting_user_value = 1;                         /* per-user view */
        }
        else {
-               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
+               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", Params[0].Key);
                return;
        }
 
@@ -100,7 +111,7 @@ void imap_setmetadata(int num_parms, char *parms[]) {
         * Extract the folder type without any parentheses.  Then learn
         * the Citadel view type based on the supplied folder type.
         */
-       extract_token(set_value, parms[5], 0, ')', sizeof set_value);
+       extract_token(set_value, Params[5].Key, 0, ')', sizeof set_value);
        if (!strncasecmp(set_value, "mail", 4)) {
                set_view = VIEW_MAILBOX;
        }
@@ -123,21 +134,21 @@ void imap_setmetadata(int num_parms, char *parms[]) {
                set_view = VIEW_MAILBOX;
        }
 
-       ret = imap_grabroom(roomname, parms[2], 0);
+       ret = imap_grabroom(roomname, Params[2].Key, 1);
        if (ret != 0) {
                cprintf("%s NO Invalid mailbox name or access denied\r\n",
-                       parms[0]);
+                       Params[0].Key);
                return;
        }
 
        /*
-        * usergoto() formally takes us to the desired room.  (If another
+        * CtdlUserGoto() formally takes us to the desired room.  (If another
         * folder is selected, save its name so we can return there!!!!!)
         */
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       usergoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
 
        /*
         * Always set the per-user view to the requested one.
@@ -150,7 +161,7 @@ void imap_setmetadata(int num_parms, char *parms[]) {
 
        if (setting_user_value)
        {
-               cprintf("%s OK SETANNOTATION complete\r\n", parms[0]);
+               cprintf("%s OK SETANNOTATION complete\r\n", Params[0].Key);
        }
 
        /* If this is a "value.shared" set operation, we are allowed to perform it
@@ -162,22 +173,22 @@ void imap_setmetadata(int num_parms, char *parms[]) {
                        )
                ||      (msgs == 0)             /* hack: if room is empty, assume we just created it */
        ) {
-               lgetroom(&CC->room, CC->room.QRname);
+               CtdlGetRoomLock(&CC->room, CC->room.QRname);
                CC->room.QRdefaultview = set_view;
-               lputroom(&CC->room);
-               cprintf("%s OK SETANNOTATION complete\r\n", parms[0]);
+               CtdlPutRoomLock(&CC->room);
+               cprintf("%s OK SETANNOTATION complete\r\n", Params[0].Key);
        }
 
        /* If we got to this point, we don't have permission to set the default view. */
        else {
-               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", parms[0]);
+               cprintf("%s NO [METADATA TOOMANY] SETMETADATA failed\r\n", Params[0].Key);
        }
 
        /*
         * If a different folder was previously selected, return there now.
         */
        if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
-               usergoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
        }
        return;
 }
@@ -189,35 +200,35 @@ void imap_setmetadata(int num_parms, char *parms[]) {
  * Regardless of what the client asked for, we are going to supply them with
  * the folder type.  It's the only metadata we have anyway.
  */
-void imap_getmetadata(int num_parms, char *parms[]) {
+void imap_getmetadata(int num_parms, ConstStr *Params) {
        char roomname[ROOMNAMELEN];
        char savedroom[ROOMNAMELEN];
        int msgs, new;
        int ret;
 
        if (num_parms > 5) {
-               cprintf("%s BAD usage error\r\n", parms[0]);
+               cprintf("%s BAD usage error\r\n", Params[0].Key);
                return;
        }
 
-       ret = imap_grabroom(roomname, parms[2], 0);
+       ret = imap_grabroom(roomname, Params[2].Key, 1);
        if (ret != 0) {
                cprintf("%s NO Invalid mailbox name or access denied\r\n",
-                       parms[0]);
+                       Params[0].Key);
                return;
        }
 
        /*
-        * usergoto() formally takes us to the desired room.  (If another
+        * CtdlUserGoto() formally takes us to the desired room.  (If another
         * folder is selected, save its name so we can return there!!!!!)
         */
        if (IMAP->selected) {
                strcpy(savedroom, CC->room.QRname);
        }
-       usergoto(roomname, 0, 0, &msgs, &new);
+       CtdlUserGoto(roomname, 0, 0, &msgs, &new);
 
        cprintf("* METADATA ");
-       imap_strout(parms[2]);
+       imap_strout(&Params[2]);
        cprintf(" \"/vendor/kolab/folder-type\" (\"value.shared\" \"");
 
        /* If it's one of our hard-coded default rooms, we know what to do... */
@@ -228,6 +239,9 @@ void imap_getmetadata(int num_parms, char *parms[]) {
        else if (!strcasecmp(&CC->room.QRname[11], SENTITEMS)) {
                cprintf("mail.sentitems");
        }
+       else if (!strcasecmp(&CC->room.QRname[11], USERDRAFTROOM)) {
+               cprintf("mail.drafts");
+       }
        else if (!strcasecmp(&CC->room.QRname[11], USERCALENDARROOM)) {
                cprintf("event.default");
        }
@@ -277,10 +291,10 @@ void imap_getmetadata(int num_parms, char *parms[]) {
         * If a different folder was previously selected, return there now.
         */
        if ( (IMAP->selected) && (strcasecmp(roomname, savedroom)) ) {
-               usergoto(savedroom, 0, 0, &msgs, &new);
+               CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
        }
 
-       cprintf("%s OK GETMETADATA complete\r\n", parms[0]);
+       cprintf("%s OK GETMETADATA complete\r\n", Params[0].Key);
        return;
 }