#include <pwd.h>
#include <errno.h>
#include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
#include <sys/wait.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include "citadel.h"
#include "server.h"
-#include <time.h>
#include "sysdep_decls.h"
#include "citserver.h"
#include "support.h"
#include "config.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
#include "room_ops.h"
#include "user_ops.h"
#include "policy.h"
* imap_do_store() calls imap_do_store_msg() to output the deta of an
* individual message, once it has been successfully loaded from disk.
*/
-void imap_do_store_msg(int seq, struct CtdlMessage *msg,
- int num_items, char **itemlist, int is_uid) {
+void imap_do_store_msg(int seq, char *oper, unsigned int bits_to_twiddle) {
+
+ if (!strncasecmp(oper, "FLAGS", 5)) {
+ IMAP->flags[seq] &= IMAP_MASK_SYSTEM;
+ IMAP->flags[seq] |= bits_to_twiddle;
+ }
+ else if (!strncasecmp(oper, "+FLAGS", 6)) {
+ IMAP->flags[seq] |= bits_to_twiddle;
+ }
+ else if (!strncasecmp(oper, "-FLAGS", 6)) {
+ IMAP->flags[seq] &= (~bits_to_twiddle);
+ }
+ if (bits_to_twiddle & IMAP_SEEN) {
+ CtdlSetSeen(IMAP->msgids[seq],
+ ((IMAP->flags[seq] & IMAP_SEEN) ? 1 : 0) );
+ }
+ cprintf("* %d FETCH (", seq+1);
+ imap_fetch_flags(seq);
+ cprintf(")\r\n");
}
/*
- * imap_store() calls imap_do_store() to do its actual work, once it's
- * validated and boiled down the request a bit.
+ * imap_store() calls imap_do_store() to perform the actual bit twiddling
+ * on flags. We brazenly ignore the ".silent" protocol option because it's not
+ * harmful to send the data anyway. Fix it yourself if you don't like that.
*/
-void imap_do_store(int num_items, char **itemlist, int is_uid) {
+void imap_do_store(int num_items, char **itemlist) {
int i;
- struct CtdlMessage *msg;
-
- if (IMAP->num_msgs > 0)
- for (i = 0; i < IMAP->num_msgs; ++i)
- if (IMAP->flags[i] && IMAP_FETCHED) {
- msg = CtdlFetchMessage(IMAP->msgids[i]);
- if (msg != NULL) {
- imap_do_store_msg(i+1, msg, num_items,
- itemlist, is_uid);
- CtdlFreeMessage(msg);
+ unsigned int bits_to_twiddle = 0;
+ char *oper;
+ char flag[SIZ];
+
+ if (num_items < 2) return;
+ oper = itemlist[0];
+
+ for (i=1; i<num_items; ++i) {
+ strcpy(flag, itemlist[i]);
+ if (flag[0]=='(') strcpy(flag, &flag[1]);
+ if (flag[strlen(flag)-1]==')') flag[strlen(flag)-1]=0;
+ striplt(flag);
+
+ if (!strcasecmp(flag, "\\Deleted")) {
+ if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
+ bits_to_twiddle |= IMAP_DELETED;
+ }
+ }
+
+ if (!strcasecmp(flag, "\\Seen")) {
+ bits_to_twiddle |= IMAP_SEEN;
}
- else {
- lprintf(1, "IMAP STORE internal error\n");
+ }
+
+ if (IMAP->num_msgs > 0) {
+ for (i = 0; i < IMAP->num_msgs; ++i) {
+ if (IMAP->flags[i] && IMAP_SELECTED) {
+ imap_do_store_msg(i, oper, bits_to_twiddle);
+ }
}
}
}
return;
}
- for (i=1; i<num_parms; ++i) {
- if (imap_is_message_set(parms[i])) {
- imap_pick_range(parms[2], 0);
- }
+ if (imap_is_message_set(parms[2])) {
+ imap_pick_range(parms[2], 0);
+ }
+ else {
+ cprintf("%s BAD invalid parameters\r\n", parms[0]);
+ return;
}
strcpy(items, "");
- for (i=2; i<num_parms; ++i) {
+ for (i=3; i<num_parms; ++i) {
strcat(items, parms[i]);
if (i < (num_parms-1)) strcat(items, " ");
}
return;
}
- imap_do_store(num_items, itemlist, 0);
+ imap_do_store(num_items, itemlist);
cprintf("%s OK STORE completed\r\n", parms[0]);
}
return;
}
- for (i=1; i<num_parms; ++i) {
- if (imap_is_message_set(parms[i])) {
- imap_pick_range(parms[2], 1);
- }
+ if (imap_is_message_set(parms[3])) {
+ imap_pick_range(parms[3], 1);
+ }
+ else {
+ cprintf("%s BAD invalid parameters\r\n", parms[0]);
+ return;
}
strcpy(items, "");
return;
}
- imap_do_store(num_items, itemlist, 1);
+ imap_do_store(num_items, itemlist);
cprintf("%s OK UID STORE completed\r\n", parms[0]);
}