Experimental changes to the default theme. Gradient
[citadel.git] / citadel / imap_store.c
index 0c40e430d6c915f7897295a2d726d23986ef1e5b..7e163787b227a2880ff548426e23721fdaf61edc 100644 (file)
@@ -37,7 +37,6 @@
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "serv_extensions.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
  * We also implement the ".SILENT" protocol option here.  :(
  */
 void imap_do_store_msg(int seq, char *oper, unsigned int bits_to_twiddle) {
-       int silent = 0;
+
 
        if (!strncasecmp(oper, "FLAGS", 5)) {
                IMAP->flags[seq] &= IMAP_MASK_SYSTEM;
                IMAP->flags[seq] |= bits_to_twiddle;
-               silent = strncasecmp(&oper[5], ".SILENT", 7);
        }
        else if (!strncasecmp(oper, "+FLAGS", 6)) {
                IMAP->flags[seq] |= bits_to_twiddle;
-               silent = strncasecmp(&oper[6], ".SILENT", 7);
        }
        else if (!strncasecmp(oper, "-FLAGS", 6)) {
                IMAP->flags[seq] &= (~bits_to_twiddle);
-               silent = strncasecmp(&oper[6], ".SILENT", 7);
-       }
-
-       if (bits_to_twiddle & IMAP_SEEN) {
-               CtdlSetSeen(IMAP->msgids[seq],
-                       ((IMAP->flags[seq] & IMAP_SEEN) ? 1 : 0),
-                       ctdlsetseen_seen,
-                       NULL, NULL
-               );
-       }
-       if (bits_to_twiddle & IMAP_ANSWERED) {
-               CtdlSetSeen(IMAP->msgids[seq],
-                       ((IMAP->flags[seq] & IMAP_ANSWERED) ? 1 : 0),
-                       ctdlsetseen_answered,
-                       NULL, NULL
-               );
-       }
-
-       /* 'silent' is actually the value returned from a strncasecmp() so
-        * we want that option only if its value is zero.  Seems backwards
-        * but that's the way it's supposed to be.
-        */
-       if (silent) {
-               cprintf("* %d FETCH (", seq+1);
-               imap_fetch_flags(seq);
-               cprintf(")\r\n");
        }
 }
 
@@ -118,13 +89,33 @@ void imap_do_store(int num_items, char **itemlist) {
        char flag[32];
        char whichflags[256];
        char num_flags;
+       int silent = 0;
+       long *ss_msglist;
+       int num_ss = 0;
+       int last_item_twiddled = (-1);
 
        if (num_items < 2) return;
        oper = itemlist[0];
+       if (bmstrcasestr(oper, ".SILENT")) {
+               silent = 1;
+       }
 
+       /*
+        * ss_msglist is an array of message numbers to manipulate.  We
+        * are going to supply this array to CtdlSetSeen() later.
+        */
+       ss_msglist = malloc(IMAP->num_msgs * sizeof(long));
+       if (ss_msglist == NULL) return;
+
+       /*
+        * Ok, go ahead and parse the flags.
+        */
        for (i=1; i<num_items; ++i) {
                strcpy(whichflags, itemlist[i]);
-               if (whichflags[0]=='(') safestrncpy(whichflags, &whichflags[1], sizeof whichflags);
+               if (whichflags[0]=='(') {
+                       safestrncpy(whichflags, &whichflags[1], 
+                               sizeof whichflags);
+               }
                if (whichflags[strlen(whichflags)-1]==')') {
                        whichflags[strlen(whichflags)-1]=0;
                }
@@ -158,19 +149,53 @@ void imap_do_store(int num_items, char **itemlist) {
        if (IMAP->num_msgs > 0) {
                for (i = 0; i < IMAP->num_msgs; ++i) {
                        if (IMAP->flags[i] & IMAP_SELECTED) {
+                               last_item_twiddled = i;
+
+                               ss_msglist[num_ss++] = IMAP->msgids[i];
                                imap_do_store_msg(i, oper, bits_to_twiddle);
+
+                               if (!silent) {
+                                       cprintf("* %d FETCH (", i+1);
+                                       imap_fetch_flags(i);
+                                       cprintf(")\r\n");
+                               }
+
                        }
                }
        }
 
-#ifdef INSTANT_EXPUNGE
        /*
-        * The following two commands implement "instant expunge"
-        * which is experimental.
+        * Now manipulate the database -- all in one shot.
         */
-       imap_do_expunge();
-       imap_rescan_msgids();
-#endif /* INSTANT_EXPUNGE */
+       if ( (last_item_twiddled >= 0) && (num_ss > 0) ) {
+
+               if (bits_to_twiddle & IMAP_SEEN) {
+                       CtdlSetSeen(ss_msglist, num_ss,
+                               ((IMAP->flags[last_item_twiddled] & IMAP_SEEN) ? 1 : 0),
+                               ctdlsetseen_seen,
+                               NULL, NULL
+                       );
+               }
+
+               if (bits_to_twiddle & IMAP_ANSWERED) {
+                       CtdlSetSeen(ss_msglist, num_ss,
+                               ((IMAP->flags[last_item_twiddled] & IMAP_ANSWERED) ? 1 : 0),
+                               ctdlsetseen_answered,
+                               NULL, NULL
+                       );
+               }
+
+       }
+
+       free(ss_msglist);
+
+       /*
+        * The following two commands implement "instant expunge" if enabled.
+        */
+       if (config.c_instant_expunge) {
+               imap_do_expunge();
+               imap_rescan_msgids();
+       }
 
 }