* Backed out the variable-length string changes.
[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 seq, struct CtdlMessage *msg,
54                         int num_items, char **itemlist, int is_uid) {
55
56
57 }
58
59
60
61 /*
62  * imap_store() calls imap_do_store() to do its actual work, once it's
63  * validated and boiled down the request a bit.
64  */
65 void imap_do_store(int num_items, char **itemlist, int is_uid) {
66         int i;
67         struct CtdlMessage *msg;
68
69         if (IMAP->num_msgs > 0)
70          for (i = 0; i < IMAP->num_msgs; ++i)
71           if (IMAP->flags[i] && IMAP_FETCHED) {
72                 msg = CtdlFetchMessage(IMAP->msgids[i]);
73                 if (msg != NULL) {
74                         imap_do_store_msg(i+1, msg, num_items,
75                                         itemlist, is_uid);
76                         CtdlFreeMessage(msg);
77                 }
78                 else {
79                         lprintf(1, "IMAP STORE internal error\n");
80                 }
81         }
82 }
83
84
85 /*
86  * This function is called by the main command loop.
87  */
88 void imap_store(int num_parms, char *parms[]) {
89         char items[1024];
90         char *itemlist[256];
91         int num_items;
92         int i;
93
94         if (num_parms < 3) {
95                 cprintf("%s BAD invalid parameters\r\n", parms[0]);
96                 return;
97         }
98
99         for (i=1; i<num_parms; ++i) {
100                 if (imap_is_message_set(parms[i])) {
101                         imap_pick_range(parms[2], 0);
102                 }
103         }
104
105         strcpy(items, "");
106         for (i=2; i<num_parms; ++i) {
107                 strcat(items, parms[i]);
108                 if (i < (num_parms-1)) strcat(items, " ");
109         }
110
111         num_items = imap_extract_data_items(itemlist, items);
112         if (num_items < 1) {
113                 cprintf("%s BAD invalid data item list\r\n", parms[0]);
114                 return;
115         }
116
117         imap_do_store(num_items, itemlist, 0);
118         cprintf("%s OK STORE completed\r\n", parms[0]);
119 }
120
121 /*
122  * This function is called by the main command loop.
123  */
124 void imap_uidstore(int num_parms, char *parms[]) {
125         char items[1024];
126         char *itemlist[256];
127         int num_items;
128         int i;
129
130         if (num_parms < 4) {
131                 cprintf("%s BAD invalid parameters\r\n", parms[0]);
132                 return;
133         }
134
135         for (i=1; i<num_parms; ++i) {
136                 if (imap_is_message_set(parms[i])) {
137                         imap_pick_range(parms[2], 1);
138                 }
139         }
140
141         strcpy(items, "");
142         for (i=4; i<num_parms; ++i) {
143                 strcat(items, parms[i]);
144                 if (i < (num_parms-1)) strcat(items, " ");
145         }
146
147         num_items = imap_extract_data_items(itemlist, items);
148         if (num_items < 1) {
149                 cprintf("%s BAD invalid data item list\r\n", parms[0]);
150                 return;
151         }
152
153         imap_do_store(num_items, itemlist, 1);
154         cprintf("%s OK UID STORE completed\r\n", parms[0]);
155 }
156
157