]> code.citadel.org Git - citadel.git/blob - citadel/imap_store.c
* imap
[citadel.git] / citadel / imap_store.c
1 /*
2  * $Id$
3  *
4  * Implements the STORE command in IMAP.
5  *
6  */
7
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18 #include <sys/time.h>
19 #include <sys/wait.h>
20 #include <ctype.h>
21 #include <string.h>
22 #include <limits.h>
23 #include "citadel.h"
24 #include "server.h"
25 #include <time.h>
26 #include "sysdep_decls.h"
27 #include "citserver.h"
28 #include "support.h"
29 #include "config.h"
30 #include "dynloader.h"
31 #include "room_ops.h"
32 #include "user_ops.h"
33 #include "policy.h"
34 #include "database.h"
35 #include "msgbase.h"
36 #include "tools.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"
42 #include "genstamp.h"
43
44
45
46
47
48
49 /*
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.
52  */
53 void imap_do_store_msg(int num, int num_items, char **itemlist) {
54         int i;
55
56         cprintf("* <%d> ", num);
57         for (i=0; i<num_items; ++i) cprintf("<%s> ", itemlist[i]);
58         cprintf("\r\n");
59 }
60
61
62
63 /*
64  * imap_store() calls imap_do_store() to do its actual work, once it's
65  * validated and boiled down the request a bit.
66  */
67 void imap_do_store(int num_items, char **itemlist, int is_uid) {
68         int i;
69
70         if (IMAP->num_msgs > 0) {
71                 for (i = 0; i < IMAP->num_msgs; ++i) {
72                         if (IMAP->flags[i] && IMAP_SELECTED) {
73                                 imap_do_store_msg(i, num_items, itemlist);
74                         }
75                 else {
76                         lprintf(1, "IMAP STORE internal error\n");
77                         }
78                 }
79         }
80 }
81
82
83 /*
84  * This function is called by the main command loop.
85  */
86 void imap_store(int num_parms, char *parms[]) {
87         char items[1024];
88         char *itemlist[256];
89         int num_items;
90         int i;
91
92         if (num_parms < 4) {
93                 cprintf("%s BAD invalid parameters\r\n", parms[0]);
94                 return;
95         }
96
97         if (imap_is_message_set(parms[2])) {
98                 imap_pick_range(parms[2], 0);
99         }
100         else {
101                 cprintf("%s BAD No message set specified to STORE\r\n",
102                         parms[0]);
103                 return;
104         }
105
106         strcpy(items, "");
107         for (i=3; i<num_parms; ++i) {
108                 strcat(items, parms[i]);
109                 if (i < (num_parms-1)) strcat(items, " ");
110         }
111
112         num_items = imap_extract_data_items(itemlist, items);
113         if (num_items < 1) {
114                 cprintf("%s BAD invalid data item list\r\n", parms[0]);
115                 return;
116         }
117
118         imap_do_store(num_items, itemlist, 0);
119         cprintf("%s OK STORE completed\r\n", parms[0]);
120 }
121
122 /*
123  * This function is called by the main command loop.
124  */
125 void imap_uidstore(int num_parms, char *parms[]) {
126         char items[1024];
127         char *itemlist[256];
128         int num_items;
129         int i;
130
131         if (num_parms < 5) {
132                 cprintf("%s BAD invalid parameters\r\n", parms[0]);
133                 return;
134         }
135
136         if (imap_is_message_set(parms[2])) {
137                 imap_pick_range(parms[2], 0);
138         }
139         else {
140                 cprintf("%s BAD No message set specified to STORE\r\n",
141                         parms[0]);
142                 return;
143         }
144
145         strcpy(items, "");
146         for (i=4; i<num_parms; ++i) {
147                 strcat(items, parms[i]);
148                 if (i < (num_parms-1)) strcat(items, " ");
149         }
150
151         num_items = imap_extract_data_items(itemlist, items);
152         if (num_items < 1) {
153                 cprintf("%s BAD invalid data item list\r\n", parms[0]);
154                 return;
155         }
156
157         imap_do_store(num_items, itemlist, 1);
158         cprintf("%s OK UID STORE completed\r\n", parms[0]);
159 }
160
161