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 if (bits_to_twiddle & IMAP_SEEN) {
67 CtdlSetSeen(IMAP->msgids[seq],
68 ((IMAP->flags[seq] & IMAP_SEEN) ? 1 : 0) );
71 cprintf("* %d FETCH (", seq+1);
72 imap_fetch_flags(seq);
79 * imap_store() calls imap_do_store() to perform the actual bit twiddling
80 * on flags. We brazenly ignore the ".silent" protocol option because it's not
81 * harmful to send the data anyway. Fix it yourself if you don't like that.
83 void imap_do_store(int num_items, char **itemlist) {
85 unsigned int bits_to_twiddle = 0;
89 if (num_items < 2) return;
92 for (i=1; i<num_items; ++i) {
93 strcpy(flag, itemlist[i]);
94 if (flag[0]=='(') strcpy(flag, &flag[1]);
95 if (flag[strlen(flag)-1]==')') flag[strlen(flag)-1]=0;
98 if (!strcasecmp(flag, "\\Deleted")) {
99 if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
100 bits_to_twiddle |= IMAP_DELETED;
104 if (!strcasecmp(flag, "\\Seen")) {
105 bits_to_twiddle |= IMAP_SEEN;
109 if (IMAP->num_msgs > 0) {
110 for (i = 0; i < IMAP->num_msgs; ++i) {
111 if (IMAP->flags[i] && IMAP_SELECTED) {
112 imap_do_store_msg(i, oper, bits_to_twiddle);
120 * This function is called by the main command loop.
122 void imap_store(int num_parms, char *parms[]) {
129 cprintf("%s BAD invalid parameters\r\n", parms[0]);
133 if (imap_is_message_set(parms[2])) {
134 imap_pick_range(parms[2], 0);
137 cprintf("%s BAD invalid parameters\r\n", parms[0]);
142 for (i=3; i<num_parms; ++i) {
143 strcat(items, parms[i]);
144 if (i < (num_parms-1)) strcat(items, " ");
147 num_items = imap_extract_data_items(itemlist, items);
149 cprintf("%s BAD invalid data item list\r\n", parms[0]);
153 imap_do_store(num_items, itemlist);
154 cprintf("%s OK STORE completed\r\n", parms[0]);
158 * This function is called by the main command loop.
160 void imap_uidstore(int num_parms, char *parms[]) {
167 cprintf("%s BAD invalid parameters\r\n", parms[0]);
171 if (imap_is_message_set(parms[3])) {
172 imap_pick_range(parms[3], 1);
175 cprintf("%s BAD invalid parameters\r\n", parms[0]);
180 for (i=4; i<num_parms; ++i) {
181 strcat(items, parms[i]);
182 if (i < (num_parms-1)) strcat(items, " ");
185 num_items = imap_extract_data_items(itemlist, items);
187 cprintf("%s BAD invalid data item list\r\n", parms[0]);
191 imap_do_store(num_items, itemlist);
192 cprintf("%s OK UID STORE completed\r\n", parms[0]);