4 * Implements the STORE command in IMAP.
17 #include <sys/types.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
36 #include "sysdep_decls.h"
37 #include "citserver.h"
40 #include "serv_extensions.h"
47 #include "internet_addressing.h"
48 #include "serv_imap.h"
49 #include "imap_tools.h"
50 #include "imap_fetch.h"
51 #include "imap_store.h"
60 * imap_do_store() calls imap_do_store_msg() to output the deta of an
61 * individual message, once it has been successfully loaded from disk.
63 void imap_do_store_msg(int seq, char *oper, unsigned int bits_to_twiddle) {
65 if (!strncasecmp(oper, "FLAGS", 5)) {
66 IMAP->flags[seq] &= IMAP_MASK_SYSTEM;
67 IMAP->flags[seq] |= bits_to_twiddle;
69 else if (!strncasecmp(oper, "+FLAGS", 6)) {
70 IMAP->flags[seq] |= bits_to_twiddle;
72 else if (!strncasecmp(oper, "-FLAGS", 6)) {
73 IMAP->flags[seq] &= (~bits_to_twiddle);
76 if (bits_to_twiddle & IMAP_SEEN) {
77 CtdlSetSeen(IMAP->msgids[seq],
78 ((IMAP->flags[seq] & IMAP_SEEN) ? 1 : 0) );
81 cprintf("* %d FETCH (", seq+1);
82 imap_fetch_flags(seq);
89 * imap_store() calls imap_do_store() to perform the actual bit twiddling
90 * on flags. We brazenly ignore the ".silent" protocol option because it's not
91 * harmful to send the data anyway. Fix it yourself if you don't like that.
93 void imap_do_store(int num_items, char **itemlist) {
95 unsigned int bits_to_twiddle = 0;
99 if (num_items < 2) return;
102 for (i=1; i<num_items; ++i) {
103 strcpy(flag, itemlist[i]);
104 if (flag[0]=='(') strcpy(flag, &flag[1]);
105 if (flag[strlen(flag)-1]==')') flag[strlen(flag)-1]=0;
108 if (!strcasecmp(flag, "\\Deleted")) {
109 if (CtdlDoIHavePermissionToDeleteMessagesFromThisRoom()) {
110 bits_to_twiddle |= IMAP_DELETED;
114 if (!strcasecmp(flag, "\\Seen")) {
115 bits_to_twiddle |= IMAP_SEEN;
119 if (IMAP->num_msgs > 0) {
120 for (i = 0; i < IMAP->num_msgs; ++i) {
121 if (IMAP->flags[i] && IMAP_SELECTED) {
122 imap_do_store_msg(i, oper, bits_to_twiddle);
130 * This function is called by the main command loop.
132 void imap_store(int num_parms, char *parms[]) {
139 cprintf("%s BAD invalid parameters\r\n", parms[0]);
143 if (imap_is_message_set(parms[2])) {
144 imap_pick_range(parms[2], 0);
147 cprintf("%s BAD invalid parameters\r\n", parms[0]);
152 for (i=3; i<num_parms; ++i) {
153 strcat(items, parms[i]);
154 if (i < (num_parms-1)) strcat(items, " ");
157 num_items = imap_extract_data_items(itemlist, items);
159 cprintf("%s BAD invalid data item list\r\n", parms[0]);
163 imap_do_store(num_items, itemlist);
164 cprintf("%s OK STORE completed\r\n", parms[0]);
168 * This function is called by the main command loop.
170 void imap_uidstore(int num_parms, char *parms[]) {
177 cprintf("%s BAD invalid parameters\r\n", parms[0]);
181 if (imap_is_message_set(parms[3])) {
182 imap_pick_range(parms[3], 1);
185 cprintf("%s BAD invalid parameters\r\n", parms[0]);
190 for (i=4; i<num_parms; ++i) {
191 strcat(items, parms[i]);
192 if (i < (num_parms-1)) strcat(items, " ");
195 num_items = imap_extract_data_items(itemlist, items);
197 cprintf("%s BAD invalid data item list\r\n", parms[0]);
201 imap_do_store(num_items, itemlist);
202 cprintf("%s OK UID STORE completed\r\n", parms[0]);