]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_store.c
* Renamed "dynloader" to "serv_extensions" globally. We don't want people
[citadel.git] / citadel / imap_store.c
index dade924ba41f365b6eaa6a272bc494d44fb040ad..e3ce69b5bd6ddc5758bc8e910da9ee7c130f7057 100644 (file)
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/wait.h>
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
 #include "genstamp.h"
 
 
+
+
+
+
 /*
  * imap_do_store() calls imap_do_store_msg() to output the deta of an
  * individual message, once it has been successfully loaded from disk.
  */
-void imap_do_store_msg(int num, int num_items, char **itemlist) {
-       int i;
-       int flagbucket = 0;
-
-       /* at this point it should be down to "item (flags)" */
-       if (num_items < 2) return;
-
-       /* put together the flag bucket */
-       for (i=0; i<strlen(itemlist[1]); ++i) {
-               if (!strncasecmp(&itemlist[1][i], "\\Deleted", 8))
-                       flagbucket |= IMAP_DELETED;
+void imap_do_store_msg(int seq, char *oper, unsigned int bits_to_twiddle) {
+       
+       if (!strncasecmp(oper, "FLAGS", 5)) {
+               IMAP->flags[seq] &= IMAP_MASK_SYSTEM;
+               IMAP->flags[seq] |= bits_to_twiddle;
        }
-
-       /*
-        * Figure out what to do and do it.  Brazenly IGnore the ".SILENT"
-        * option, since it is not illegal to output the data anyway.
-        */
-       if (!strncasecmp(itemlist[0], "FLAGS", 5)) {
-               IMAP->flags[num] &= IMAP_INTERNAL_MASK;
-               IMAP->flags[num] |= flagbucket;
+       else if (!strncasecmp(oper, "+FLAGS", 6)) {
+               IMAP->flags[seq] |= bits_to_twiddle;
        }
-
-       if (!strncasecmp(itemlist[0], "+FLAGS", 6)) {
-               IMAP->flags[num] |= flagbucket;
+       else if (!strncasecmp(oper, "-FLAGS", 6)) {
+               IMAP->flags[seq] &= (~bits_to_twiddle);
        }
 
-       if (!strncasecmp(itemlist[0], "-FLAGS", 6)) {
-               IMAP->flags[num] &= ~flagbucket;
+       if (bits_to_twiddle & IMAP_SEEN) {
+               CtdlSetSeen(IMAP->msgids[seq],
+                               ((IMAP->flags[seq] & IMAP_SEEN) ? 1 : 0) );
        }
 
-       /*
-        * Tell the client what happen (someone set up us the bomb!)
-        */
-       cprintf("* %d FETCH ", num+1);  /* output sequence number */
-       imap_output_flags(num);
-       cprintf("\r\n");
+       cprintf("* %d FETCH (", seq+1);
+       imap_fetch_flags(seq);
+       cprintf(")\r\n");
 }
 
 
 
 /*
- * imap_store() calls imap_do_store() to do its actual work, once it's
- * validated and boiled down the request a bit.
+ * imap_store() calls imap_do_store() to perform the actual bit twiddling
+ * on flags.  We brazenly ignore the ".silent" protocol option because it's not
+ * harmful to send the data anyway.  Fix it yourself if you don't like that.
  */
-void imap_do_store(int num_items, char **itemlist, int is_uid) {
+void imap_do_store(int num_items, char **itemlist) {
        int i;
+       unsigned int bits_to_twiddle = 0;
+       char *oper;
+       char flag[SIZ];
 
+       if (num_items < 2) return;
+       oper = itemlist[0];
+
+       for (i=1; i<num_items; ++i) {
+               strcpy(flag, itemlist[i]);
+               if (flag[0]=='(') strcpy(flag, &flag[1]);
+               if (flag[strlen(flag)-1]==')') flag[strlen(flag)-1]=0;
+               striplt(flag);
+
+               if (!strcasecmp(flag, "\\Deleted")) {
+                 if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
+                       bits_to_twiddle |= IMAP_DELETED;
+                 }
+               }
+
+               if (!strcasecmp(flag, "\\Seen")) {
+                       bits_to_twiddle |= IMAP_SEEN;
+               }
+       }
+       
        if (IMAP->num_msgs > 0) {
                for (i = 0; i < IMAP->num_msgs; ++i) {
                        if (IMAP->flags[i] && IMAP_SELECTED) {
-                               imap_do_store_msg(i, num_items, itemlist);
+                               imap_do_store_msg(i, oper, bits_to_twiddle);
                        }
                }
        }
@@ -112,7 +135,7 @@ void imap_store(int num_parms, char *parms[]) {
        int num_items;
        int i;
 
-       if (num_parms < 4) {
+       if (num_parms < 3) {
                cprintf("%s BAD invalid parameters\r\n", parms[0]);
                return;
        }
@@ -121,8 +144,7 @@ void imap_store(int num_parms, char *parms[]) {
                imap_pick_range(parms[2], 0);
        }
        else {
-               cprintf("%s BAD No message set specified to STORE\r\n",
-                       parms[0]);
+               cprintf("%s BAD invalid parameters\r\n", parms[0]);
                return;
        }
 
@@ -138,7 +160,7 @@ void imap_store(int num_parms, char *parms[]) {
                return;
        }
 
-       imap_do_store(num_items, itemlist, 0);
+       imap_do_store(num_items, itemlist);
        cprintf("%s OK STORE completed\r\n", parms[0]);
 }
 
@@ -151,7 +173,7 @@ void imap_uidstore(int num_parms, char *parms[]) {
        int num_items;
        int i;
 
-       if (num_parms < 5) {
+       if (num_parms < 4) {
                cprintf("%s BAD invalid parameters\r\n", parms[0]);
                return;
        }
@@ -160,8 +182,7 @@ void imap_uidstore(int num_parms, char *parms[]) {
                imap_pick_range(parms[3], 1);
        }
        else {
-               cprintf("%s BAD No message set specified to STORE\r\n",
-                       parms[0]);
+               cprintf("%s BAD invalid parameters\r\n", parms[0]);
                return;
        }
 
@@ -177,7 +198,7 @@ void imap_uidstore(int num_parms, char *parms[]) {
                return;
        }
 
-       imap_do_store(num_items, itemlist, 1);
+       imap_do_store(num_items, itemlist);
        cprintf("%s OK UID STORE completed\r\n", parms[0]);
 }