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 bits_to_twiddle |= IMAP_DELETED;
98 if (IMAP->num_msgs > 0) {
99 for (i = 0; i < IMAP->num_msgs; ++i) {
100 if (IMAP->flags[i] && IMAP_SELECTED) {
101 imap_do_store_msg(i, oper, bits_to_twiddle);
109 * This function is called by the main command loop.
111 void imap_store(int num_parms, char *parms[]) {
118 cprintf("%s BAD invalid parameters\r\n", parms[0]);
122 if (imap_is_message_set(parms[2])) {
123 imap_pick_range(parms[2], 0);
126 cprintf("%s BAD invalid parameters\r\n", parms[0]);
131 for (i=3; i<num_parms; ++i) {
132 strcat(items, parms[i]);
133 if (i < (num_parms-1)) strcat(items, " ");
136 num_items = imap_extract_data_items(itemlist, items);
138 cprintf("%s BAD invalid data item list\r\n", parms[0]);
142 imap_do_store(num_items, itemlist);
143 cprintf("%s OK STORE completed\r\n", parms[0]);
147 * This function is called by the main command loop.
149 void imap_uidstore(int num_parms, char *parms[]) {
156 cprintf("%s BAD invalid parameters\r\n", parms[0]);
160 if (imap_is_message_set(parms[3])) {
161 imap_pick_range(parms[3], 1);
164 cprintf("%s BAD invalid parameters\r\n", parms[0]);
169 for (i=4; i<num_parms; ++i) {
170 strcat(items, parms[i]);
171 if (i < (num_parms-1)) strcat(items, " ");
174 num_items = imap_extract_data_items(itemlist, items);
176 cprintf("%s BAD invalid data item list\r\n", parms[0]);
180 imap_do_store(num_items, itemlist);
181 cprintf("%s OK UID STORE completed\r\n", parms[0]);