but it needs lots more testing.
char roomname[ROOMNAMELEN];
struct ctdlroom qrbuf;
struct timeval tv1, tv2, tv3;
+ long *selected_msgs = NULL;
int num_selected = 0;
if (IMAP->num_msgs < 1) {
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);
/*
- * Back end API function for moves and deletes
+ * Back end API function for moves and deletes (multiple messages)
*/
-int CtdlCopyMsgToRoom(long msgnum, char *dest) {
+int CtdlCopyMsgsToRoom(long *msgnums, int num_msgs, char *dest) {
int err;
- err = CtdlSaveMsgPointerInRoom(dest, msgnum, 1, NULL);
+ err = CtdlSaveMsgPointersInRoom(dest, msgnums, num_msgs, 1, NULL);
if (err != 0) return(err);
return(0);
}
+/*
+ * Back end API function for moves and deletes (single message)
+ */
+int CtdlCopyMsgToRoom(long msgnum, char *dest) {
+ return CtdlCopyMsgsToRoom(&msgnum, 1, dest);
+}
+
+
/*
* move or copy a message to another room
void serialize_message(struct ser_ret *, struct CtdlMessage *);
int is_valid_message(struct CtdlMessage *);
void ReplicationChecks(struct CtdlMessage *);
+int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs,
+ int do_repl_check, struct CtdlMessage *supplied_msg);
int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int do_repl_check, struct CtdlMessage *msg);
char *CtdlReadMessageBody(char *terminator, size_t maxlen, char *exist, int crlf);
char *CtdlGetSysConfig(char *sysconfname);
int do_proto, /* do Citadel protocol responses? */
int crlf /* 0=LF, 1=CRLF */
);
+int CtdlCopyMsgsToRoom(long *msgnum, int num_msgs, char *dest);
int CtdlCopyMsgToRoom(long msgnum, char *dest);
int CtdlDoIHavePermissionToDeleteMessagesFromThisRoom(void);
int CtdlDoIHavePermissionToPostInThisRoom(char *errmsgbuf, size_t n);