4 * Implements the STORE command in IMAP.
17 #include <sys/types.h>
26 #include "sysdep_decls.h"
27 #include "citserver.h"
30 #include "dynloader.h"
37 #include "internet_addressing.h"
38 #include "serv_imap.h"
39 #include "imap_tools.h"
40 #include "imap_fetch.h"
41 #include "imap_store.h"
50 * imap_do_store() calls imap_do_store_msg() to output the deta of an
51 * individual message, once it has been successfully loaded from disk.
53 void imap_do_store_msg(int seq, char *oper, unsigned int bits_to_twiddle) {
55 if (!strncasecmp(oper, "FLAGS", 5)) {
56 IMAP->flags[seq] &= IMAP_MASK_SYSTEM;
57 IMAP->flags[seq] |= bits_to_twiddle;
59 else if (!strncasecmp(oper, "+FLAGS", 6)) {
60 IMAP->flags[seq] |= bits_to_twiddle;
62 else if (!strncasecmp(oper, "-FLAGS", 6)) {
63 IMAP->flags[seq] &= (~bits_to_twiddle);
66 cprintf("* %d FETCH (", seq+1);
67 imap_fetch_flags(seq);
74 * imap_store() calls imap_do_store() to perform the actual bit twiddling
75 * on flags. We brazenly ignore the ".silent" protocol option because it's not
76 * harmful to send the data anyway. Fix it yourself if you don't like that.
78 void imap_do_store(int num_items, char **itemlist) {
80 unsigned int bits_to_twiddle = 0;
84 if (num_items < 2) return;
87 for (i=1; i<num_items; ++i) {
88 strcpy(flag, itemlist[i]);
89 if (flag[0]=='(') strcpy(flag, &flag[1]);
90 if (flag[strlen(flag)-1]==')') flag[strlen(flag)-1]=0;
93 if (!strcasecmp(flag, "\\Deleted")) {
94 if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
95 bits_to_twiddle |= IMAP_DELETED;
100 if (IMAP->num_msgs > 0) {
101 for (i = 0; i < IMAP->num_msgs; ++i) {
102 if (IMAP->flags[i] && IMAP_SELECTED) {
103 imap_do_store_msg(i, oper, bits_to_twiddle);
111 * This function is called by the main command loop.
113 void imap_store(int num_parms, char *parms[]) {
120 cprintf("%s BAD invalid parameters\r\n", parms[0]);
124 if (imap_is_message_set(parms[2])) {
125 imap_pick_range(parms[2], 0);
128 cprintf("%s BAD invalid parameters\r\n", parms[0]);
133 for (i=3; i<num_parms; ++i) {
134 strcat(items, parms[i]);
135 if (i < (num_parms-1)) strcat(items, " ");
138 num_items = imap_extract_data_items(itemlist, items);
140 cprintf("%s BAD invalid data item list\r\n", parms[0]);
144 imap_do_store(num_items, itemlist);
145 cprintf("%s OK STORE completed\r\n", parms[0]);
149 * This function is called by the main command loop.
151 void imap_uidstore(int num_parms, char *parms[]) {
158 cprintf("%s BAD invalid parameters\r\n", parms[0]);
162 if (imap_is_message_set(parms[3])) {
163 imap_pick_range(parms[3], 1);
166 cprintf("%s BAD invalid parameters\r\n", parms[0]);
171 for (i=4; i<num_parms; ++i) {
172 strcat(items, parms[i]);
173 if (i < (num_parms-1)) strcat(items, " ");
176 num_items = imap_extract_data_items(itemlist, items);
178 cprintf("%s BAD invalid data item list\r\n", parms[0]);
182 imap_do_store(num_items, itemlist);
183 cprintf("%s OK UID STORE completed\r\n", parms[0]);