]> 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 0ddd8d401ea553310776285422f834fdc8843f19..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"
 int imap_do_copy(char *destination_folder) {
        int i;
        char roomname[ROOMNAMELEN];
+       struct ctdlroom qrbuf;
+       long *selected_msgs = NULL;
+       int num_selected = 0;
+
+       if (IMAP->num_msgs < 1) {
+               return(0);
+       }
 
        i = imap_grabroom(roomname, destination_folder, 0);
        if (i != 0) return(i);
 
-       if (IMAP->num_msgs > 0) {
-               for (i = 0; i < IMAP->num_msgs; ++i) {
-                       if (IMAP->flags[i] & IMAP_SELECTED) {
-                               CtdlCopyMsgToRoom(
-                                       IMAP->msgids[i],
-                                       roomname
-                               );
+       /*
+        * Copy all the message pointers in one shot.
+        */
+       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) {
+                       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);
+       }
+
+       /* Enumerate lists of messages for which flags are toggled */
+       long *seen_yes = NULL;
+       int num_seen_yes = 0;
+       long *seen_no = NULL;
+       int num_seen_no = 0;
+       long *answ_yes = NULL;
+       int num_answ_yes = 0;
+       long *answ_no = NULL;
+       int num_answ_no = 0;
+
+       seen_yes = malloc(num_selected * sizeof(long));
+       seen_no = malloc(num_selected * sizeof(long));
+       answ_yes = malloc(num_selected * sizeof(long));
+       answ_no = malloc(num_selected * sizeof(long));
+
+       for (i = 0; i < IMAP->num_msgs; ++i) {
+               if (IMAP->flags[i] & IMAP_SELECTED) {
+                       if (IMAP->flags[i] & IMAP_SEEN) {
+                               seen_yes[num_seen_yes++] = IMAP->msgids[i];
+                       }
+                       if ((IMAP->flags[i] & IMAP_SEEN) == 0) {
+                               seen_no[num_seen_no++] = IMAP->msgids[i];
+                       }
+                       if (IMAP->flags[i] & IMAP_ANSWERED) {
+                               answ_yes[num_answ_yes++] = IMAP->msgids[i];
+                       }
+                       if ((IMAP->flags[i] & IMAP_ANSWERED) == 0) {
+                               answ_no[num_answ_no++] = IMAP->msgids[i];
                        }
                }
        }
 
+       /* Set the flags... */
+       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);
+       }
+
+       free(seen_yes);
+       free(seen_no);
+       free(answ_yes);
+       free(answ_no);
+
        return(0);
 }
 
 
+
 /*
  * This function is called by the main command loop.
  */
@@ -227,10 +291,12 @@ void imap_do_append_flags(long new_msgnum, char *new_message_flags) {
                extract_token(this_flag, flags, i, ' ', sizeof this_flag);
                if (this_flag[0] == '\\') strcpy(this_flag, &this_flag[1]);
                if (!strcasecmp(this_flag, "Seen")) {
-                       CtdlSetSeen(new_msgnum, 1, ctdlsetseen_seen);
+                       CtdlSetSeen(&new_msgnum, 1, 1, ctdlsetseen_seen,
+                               NULL, NULL);
                }
                if (!strcasecmp(this_flag, "Answered")) {
-                       CtdlSetSeen(new_msgnum, 1, ctdlsetseen_answered);
+                       CtdlSetSeen(&new_msgnum, 1, 1, ctdlsetseen_answered,
+                               NULL, NULL);
                }
        }
 }
@@ -243,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];
@@ -325,13 +391,13 @@ void imap_append(int num_parms, char *parms[]) {
        IMAP->transmitted_message[literal_length] = 0;  /* reterminate it */
 
        lprintf(CTDL_DEBUG, "Converting message format\n");
-        msg = convert_internet_message(IMAP->transmitted_message);
+       msg = convert_internet_message(IMAP->transmitted_message);
        IMAP->transmitted_message = NULL;
        IMAP->transmitted_length = 0;
 
        ret = imap_grabroom(roomname, parms[2], 0);
        if (ret != 0) {
-               cprintf("%s NO Invalid mailbox name or location, or access denied\r\n",
+               cprintf("%s NO Invalid mailbox name or access denied\r\n",
                        parms[0]);
                return;
        }
@@ -345,23 +411,23 @@ void imap_append(int num_parms, char *parms[]) {
        }
        usergoto(roomname, 0, 0, &msgs, &new);
 
-        /* If the user is locally authenticated, FORCE the From: header to
-         * show up as the real sender.  FIXME do we really want to do this?
+       /* If the user is locally authenticated, FORCE the From: header to
+        * show up as the real sender.  FIXME do we really want to do this?
         * Probably should make it site-definable or even room-definable.
         *
         * For now, we allow "forgeries" if the room is one of the user's
         * private mailboxes.
-         */
-        if (CC->logged_in) {
+        */
+       if (CC->logged_in) {
           if ( (CC->room.QRflags & QR_MAILBOX) == 0) {
-                if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
-                if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
-                if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
-                msg->cm_fields['A'] = strdup(CC->user.fullname);
-                msg->cm_fields['N'] = strdup(config.c_nodename);
-                msg->cm_fields['H'] = strdup(config.c_humannode);
+               if (msg->cm_fields['A'] != NULL) free(msg->cm_fields['A']);
+               if (msg->cm_fields['N'] != NULL) free(msg->cm_fields['N']);
+               if (msg->cm_fields['H'] != NULL) free(msg->cm_fields['H']);
+               msg->cm_fields['A'] = strdup(CC->user.fullname);
+               msg->cm_fields['N'] = strdup(config.c_nodename);
+               msg->cm_fields['H'] = strdup(config.c_humannode);
            }
-        }
+       }
 
        /* 
         * Can we post here?
@@ -376,7 +442,7 @@ void imap_append(int num_parms, char *parms[]) {
        else {
                /* Yes ... go ahead and post! */
                if (msg != NULL) {
-                       new_msgnum = CtdlSubmitMsg(msg, NULL, "");
+                       new_msgnum = CtdlSubmitMsg(msg, NULL, "");
                }
                if (new_msgnum >= 0L) {
                        cprintf("%s OK APPEND completed\r\n", parms[0]);