* Reference count adjustments are now deferred by queuing
[citadel.git] / citadel / serv_imap.c
index 64e2ed8601e544d4615820d6bbc0535fc2b6220e..9c17ccae7aac8e3d98c231a46fe120d4e6454de0 100644 (file)
@@ -2,7 +2,7 @@
  * $Id$ 
  *
  * IMAP server for the Citadel system
- * Copyright (C) 2000-2005 by Art Cancro and others.
+ * Copyright (C) 2000-2006 by Art Cancro and others.
  * This code is released under the terms of the GNU General Public License.
  *
  * WARNING: the IMAP protocol is badly designed.  No implementation of it
@@ -705,26 +705,33 @@ void imap_select(int num_parms, char *parms[])
 
 
 /*
- * does the real work for expunge
+ * Does the real work for expunge.
  */
 int imap_do_expunge(void)
 {
        int i;
        int num_expunged = 0;
+       long *delmsgs = NULL;
+       int num_delmsgs = 0;
 
        lprintf(CTDL_DEBUG, "imap_do_expunge() called\n");
        if (IMAP->selected == 0) {
                return (0);
        }
 
-       if (IMAP->num_msgs > 0)
+       if (IMAP->num_msgs > 0) {
+               delmsgs = malloc(IMAP->num_msgs * sizeof(long));
                for (i = 0; i < IMAP->num_msgs; ++i) {
                        if (IMAP->flags[i] & IMAP_DELETED) {
-                               CtdlDeleteMessages(CC->room.QRname,
-                                                  IMAP->msgids[i], "", 1);
-                               ++num_expunged;
+                               delmsgs[num_delmsgs++] = IMAP->msgids[i];
                        }
                }
+               if (num_delmsgs > 0) {
+                       CtdlDeleteMessages(CC->room.QRname, delmsgs, num_delmsgs, "");
+               }
+               num_expunged += num_delmsgs;
+               free(delmsgs);
+       }
 
        if (num_expunged > 0) {
                imap_rescan_msgids();
@@ -1367,8 +1374,7 @@ void imap_rename(int num_parms, char *parms[])
                                           irl->irl_newfloor);
                        if (r != crr_ok) {
                                /* FIXME handle error returns better */
-                               lprintf(CTDL_ERR, "CtdlRenameRoom() error %d\n",
-                                       r);
+                               lprintf(CTDL_ERR, "CtdlRenameRoom() error %d\n", r);
                        }
                        irlp = irl;
                        irl = irl->next;
@@ -1390,7 +1396,9 @@ void imap_command_loop(void)
        char cmdbuf[SIZ];
        char *parms[SIZ];
        int num_parms;
+       struct timeval tv1, tv2;
 
+       gettimeofday(&tv1, NULL);
        CC->lastcmd = time(NULL);
        memset(cmdbuf, 0, sizeof cmdbuf);       /* Clear it, just in case */
        flush_output();
@@ -1607,6 +1615,12 @@ void imap_command_loop(void)
 
        /* If the client transmitted a message we can free it now */
        imap_free_transmitted_message();
+
+       gettimeofday(&tv2, NULL);
+       lprintf(CTDL_DEBUG, "IMAP %s took %ld microseconds\n",
+               parms[1],
+               (tv2.tv_usec + (tv2.tv_sec * 1000000)) - (tv1.tv_usec + (tv1.tv_sec * 1000000))
+       );
 }