#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.
*/
safestrncpy(flags, new_message_flags, sizeof flags);
for (i=0; i<num_tokens(flags, ' '); ++i) {
- extract_token(this_flag, flags, i, ' ');
+ 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);
}
}
}
long literal_length;
long bytes_transferred;
long stripped_length = 0;
- struct CtdlMessage *msg;
+ struct CtdlMessage *msg = NULL;
long new_msgnum = (-1L);
int ret = 0;
- size_t blksize;
char roomname[ROOMNAMELEN];
char buf[SIZ];
char savedroom[ROOMNAMELEN];
bytes_transferred = 0;
- do {
- blksize = literal_length - bytes_transferred;
- if (blksize > SIZ) blksize = SIZ;
-
- flush_output();
- ret = client_read(&IMAP->transmitted_message[bytes_transferred],
- blksize);
- if (ret < 1) {
- bytes_transferred = literal_length; /* bail out */
- }
- else {
- bytes_transferred += blksize; /* keep going */
- }
- } while (bytes_transferred < literal_length);
-
+ ret = client_read(IMAP->transmitted_message, literal_length);
IMAP->transmitted_message[literal_length] = 0;
+
if (ret != 1) {
cprintf("%s NO Read failed.\r\n", parms[0]);
return;
client_getln(buf, sizeof buf);
/* Convert RFC822 newlines (CRLF) to Unix newlines (LF) */
+ lprintf(CTDL_DEBUG, "Converting CRLF to LF\n");
stripped_length = 0;
for (i=0; i<literal_length; ++i) {
if (strncmp(&IMAP->transmitted_message[i], "\r\n", 2)) {
- IMAP->transmitted_message[stripped_length++] = IMAP->transmitted_message[i];
+ IMAP->transmitted_message[stripped_length++] =
+ IMAP->transmitted_message[i];
}
}
literal_length = stripped_length;
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;
}
}
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?
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]);