]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_misc.c
Experimental changes to the default theme. Gradient
[citadel.git] / citadel / imap_misc.c
index f6759da7bf978ee2edb9a0c6b26d9096113bfb6b..350f9ad108d32c9cb3a23a16e5f6d18bf70b7f72 100644 (file)
@@ -36,7 +36,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"
@@ -63,7 +62,7 @@ int imap_do_copy(char *destination_folder) {
        int i;
        char roomname[ROOMNAMELEN];
        struct ctdlroom qrbuf;
-       struct timeval tv1, tv2, tv3;
+       long *selected_msgs = NULL;
        int num_selected = 0;
 
        if (IMAP->num_msgs < 1) {
@@ -74,27 +73,22 @@ int imap_do_copy(char *destination_folder) {
        if (i != 0) return(i);
 
        /*
-        * Optimization note ... ajc 2005oct09
-        * 
-        * As we can see below, we're going to end up making lots of
-        * repeated calls to CtdlCopyMsgToRoom() if the user selects
-        * multiple messages and then does a copy or move operation.
-        *
-        * The plan (documented in this comment so I don't forget what I was
-        * going to do) is to refactor CtdlCopyMsgToRoom() so that it accepts
-        * a list of message ID's instead of a single one.  Then we can alter
-        * the code which appears below, to copy all the message pointers in
-        * one shot.
-        * 
+        * Copy all the message pointers in one shot.
         */
-       gettimeofday(&tv1, NULL);
+       selected_msgs = malloc(sizeof(long) * IMAP->num_msgs);
+       if (selected_msgs == NULL) return(-1);
+
        for (i = 0; i < IMAP->num_msgs; ++i) {
                if (IMAP->flags[i] & IMAP_SELECTED) {
-                       ++num_selected;
-                       CtdlCopyMsgToRoom(IMAP->msgids[i], roomname);
+                       selected_msgs[num_selected++] = IMAP->msgids[i];
                }
        }
 
+       if (num_selected > 0) {
+               CtdlCopyMsgsToRoom(selected_msgs, num_selected, roomname);
+       }
+       free(selected_msgs);
+
        /* Don't bother wasting any more time if there were no messages. */
        if (num_selected == 0) {
                return(0);
@@ -133,21 +127,12 @@ int imap_do_copy(char *destination_folder) {
        }
 
        /* Set the flags... */
-       gettimeofday(&tv2, NULL);
        i = getroom(&qrbuf, roomname);
        if (i == 0) {
-               CtdlSetSeen(seen_yes, num_seen_yes, 1,
-                       ctdlsetseen_seen, NULL, &qrbuf
-               );
-               CtdlSetSeen(seen_no, num_seen_no, 0,
-                       ctdlsetseen_seen, NULL, &qrbuf
-               );
-               CtdlSetSeen(answ_yes, num_answ_yes, 1,
-                       ctdlsetseen_answered, NULL, &qrbuf
-               );
-               CtdlSetSeen(answ_no, num_answ_no, 0,
-                       ctdlsetseen_answered, NULL, &qrbuf
-               );
+               CtdlSetSeen(seen_yes, num_seen_yes, 1, ctdlsetseen_seen, NULL, &qrbuf);
+               CtdlSetSeen(seen_no, num_seen_no, 0, ctdlsetseen_seen, NULL, &qrbuf);
+               CtdlSetSeen(answ_yes, num_answ_yes, 1, ctdlsetseen_answered, NULL, &qrbuf);
+               CtdlSetSeen(answ_no, num_answ_no, 0, ctdlsetseen_answered, NULL, &qrbuf);
        }
 
        free(seen_yes);
@@ -155,15 +140,6 @@ int imap_do_copy(char *destination_folder) {
        free(answ_yes);
        free(answ_no);
 
-       gettimeofday(&tv3, NULL);
-       lprintf(CTDL_DEBUG, "Copying the pointers took %ld microseconds\n",
-               (tv2.tv_usec + (tv2.tv_sec * 1000000))
-               - (tv1.tv_usec + (tv1.tv_sec * 1000000))
-       );
-       lprintf(CTDL_DEBUG, "Setting the flags took %ld microseconds\n",
-               (tv3.tv_usec + (tv3.tv_sec * 1000000))
-               - (tv2.tv_usec + (tv2.tv_sec * 1000000))
-       );
        return(0);
 }
 
@@ -333,7 +309,7 @@ void imap_append(int num_parms, char *parms[]) {
        long literal_length;
        long bytes_transferred;
        long stripped_length = 0;
-       struct CtdlMessage *msg;
+       struct CtdlMessage *msg = NULL;
        long new_msgnum = (-1L);
        int ret = 0;
        char roomname[ROOMNAMELEN];