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"
46 * imap_do_store() calls imap_do_store_msg() to output the deta of an
47 * individual message, once it has been successfully loaded from disk.
49 void imap_do_store_msg(int num, int num_items, char **itemlist) {
53 /* at this point it should be down to "item (flags)" */
54 if (num_items < 2) return;
56 /* put together the flag bucket */
57 for (i=0; i<strlen(itemlist[1]); ++i) {
58 if (!strncasecmp(&itemlist[1][i], "\\Deleted", 8))
59 flagbucket |= IMAP_DELETED;
63 * Figure out what to do and do it. Brazenly IGnore the ".SILENT"
64 * option, since it is not illegal to output the data anyway.
66 if (!strncasecmp(itemlist[0], "FLAGS", 5)) {
67 IMAP->flags[num] &= IMAP_INTERNAL_MASK;
68 IMAP->flags[num] |= flagbucket;
71 if (!strncasecmp(itemlist[0], "+FLAGS", 6)) {
72 IMAP->flags[num] |= flagbucket;
75 if (!strncasecmp(itemlist[0], "-FLAGS", 6)) {
76 IMAP->flags[num] &= ~flagbucket;
80 * Tell the client what happen (someone set up us the bomb!)
82 cprintf("* %d FETCH ", num+1); /* output sequence number */
83 imap_output_flags(num);
90 * imap_store() calls imap_do_store() to do its actual work, once it's
91 * validated and boiled down the request a bit.
93 void imap_do_store(int num_items, char **itemlist, int is_uid) {
96 if (IMAP->num_msgs > 0) {
97 for (i = 0; i < IMAP->num_msgs; ++i) {
98 if (IMAP->flags[i] && IMAP_SELECTED) {
99 imap_do_store_msg(i, num_items, itemlist);
107 * This function is called by the main command loop.
109 void imap_store(int num_parms, char *parms[]) {
116 cprintf("%s BAD invalid parameters\r\n", parms[0]);
120 if (imap_is_message_set(parms[2])) {
121 imap_pick_range(parms[2], 0);
124 cprintf("%s BAD No message set specified to STORE\r\n",
130 for (i=3; i<num_parms; ++i) {
131 strcat(items, parms[i]);
132 if (i < (num_parms-1)) strcat(items, " ");
135 num_items = imap_extract_data_items(itemlist, items);
137 cprintf("%s BAD invalid data item list\r\n", parms[0]);
141 imap_do_store(num_items, itemlist, 0);
142 cprintf("%s OK STORE completed\r\n", parms[0]);
146 * This function is called by the main command loop.
148 void imap_uidstore(int num_parms, char *parms[]) {
155 cprintf("%s BAD invalid parameters\r\n", parms[0]);
159 if (imap_is_message_set(parms[3])) {
160 imap_pick_range(parms[3], 1);
163 cprintf("%s BAD No message set specified to STORE\r\n",
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, 1);
181 cprintf("%s OK UID STORE completed\r\n", parms[0]);