#include <ctype.h>
#include <string.h>
#include <limits.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "sysdep_decls.h"
#include "policy.h"
#include "database.h"
#include "msgbase.h"
-#include "tools.h"
#include "internet_addressing.h"
#include "serv_imap.h"
#include "imap_tools.h"
#include "imap_fetch.h"
#include "imap_misc.h"
#include "genstamp.h"
-
+#include "ctdl_module.h"
}
+/*
+ * Output the [COPYUID xxx yyy] response code required by RFC2359
+ * to tell the client the UID's of the messages that were copied (if any).
+ * We are assuming that the IMAP_SELECTED flag is still set on any relevant
+ * messages in our source room. Since the Citadel system uses UID's that
+ * are both globally unique and persistent across a room-to-room copy, we
+ * can get this done quite easily.
+ */
+void imap_output_copyuid_response(void) {
+ int i;
+ int num_output = 0;
+
+ for (i = 0; i < IMAP->num_msgs; ++i) {
+ if (IMAP->flags[i] & IMAP_SELECTED) {
+ ++num_output;
+ if (num_output == 1) {
+ cprintf("[COPYUID ");
+ }
+ else if (num_output > 1) {
+ cprintf(",");
+ }
+ cprintf("%ld", IMAP->msgids[i]);
+ }
+ }
+ if (num_output > 0) {
+ cprintf("] ");
+ }
+}
+
/*
* This function is called by the main command loop.
ret = imap_do_copy(parms[3]);
if (!ret) {
- cprintf("%s OK COPY completed\r\n", parms[0]);
+ cprintf("%s OK ", parms[0]);
+ imap_output_copyuid_response();
+ cprintf("COPY completed\r\n");
}
else {
cprintf("%s NO COPY failed (error %d)\r\n", parms[0], ret);
}
if (imap_do_copy(parms[4]) == 0) {
- cprintf("%s OK UID COPY completed\r\n", parms[0]);
+ cprintf("%s OK ", parms[0]);
+ imap_output_copyuid_response();
+ cprintf("UID COPY completed\r\n");
}
else {
cprintf("%s NO UID COPY failed\r\n", parms[0]);
int msgs, new;
int i;
char new_message_flags[SIZ];
+ struct citimap *Imap;
if (num_parms < 4) {
cprintf("%s BAD usage error\r\n", parms[0]);
return;
}
+ Imap = IMAP;
imap_free_transmitted_message(); /* just in case. */
- IMAP->transmitted_message = malloc(literal_length + 1);
- if (IMAP->transmitted_message == NULL) {
+ Imap->transmitted_message = malloc(literal_length + 1);
+ if (Imap->transmitted_message == NULL) {
cprintf("%s NO Cannot allocate memory.\r\n", parms[0]);
return;
}
- IMAP->transmitted_length = literal_length;
+ Imap->transmitted_length = literal_length;
cprintf("+ Transmit message now.\r\n");
bytes_transferred = 0;
- ret = client_read(IMAP->transmitted_message, literal_length);
- IMAP->transmitted_message[literal_length] = 0;
+ 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]);
client_getln(buf, sizeof buf);
/* Convert RFC822 newlines (CRLF) to Unix newlines (LF) */
- lprintf(CTDL_DEBUG, "Converting CRLF to LF\n");
+ CtdlLogPrintf(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];
+ if (strncmp(&Imap->transmitted_message[i], "\r\n", 2)) {
+ Imap->transmitted_message[stripped_length++] =
+ Imap->transmitted_message[i];
}
}
literal_length = stripped_length;
- IMAP->transmitted_message[literal_length] = 0; /* reterminate it */
+ Imap->transmitted_message[literal_length] = 0; /* reterminate it */
- lprintf(CTDL_DEBUG, "Converting message format\n");
- msg = convert_internet_message(IMAP->transmitted_message);
- IMAP->transmitted_message = NULL;
- IMAP->transmitted_length = 0;
+ CtdlLogPrintf(CTDL_DEBUG, "Converting message format\n");
+ 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) {
* usergoto() formally takes us to the desired room. (If another
* folder is selected, save its name so we can return there!!!!!)
*/
- if (IMAP->selected) {
+ if (Imap->selected) {
strcpy(savedroom, CC->room.QRname);
}
usergoto(roomname, 0, 0, &msgs, &new);
* private mailboxes.
*/
if (CC->logged_in) {
- if ( (CC->room.QRflags & QR_MAILBOX) == 0) {
+ if ( ((CC->room.QRflags & QR_MAILBOX) == 0) && (config.c_imap_keep_from == 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']);
/*
* Can we post here?
*/
- ret = CtdlDoIHavePermissionToPostInThisRoom(buf, sizeof buf);
+ ret = CtdlDoIHavePermissionToPostInThisRoom(buf, sizeof buf, NULL, POST_LOGGED_IN);
if (ret) {
/* Nope ... print an error message */
* If another folder is selected, go back to that room so we can resume
* our happy day without violent explosions.
*/
- if (IMAP->selected) {
+ if (Imap->selected) {
usergoto(savedroom, 0, 0, &msgs, &new);
}