/[imapfilter]/imapfilter/imap.c
ViewVC logotype

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.24 - (show annotations)
Tue Jun 18 21:13:50 2002 UTC (21 years, 9 months ago) by lefcha
Branch: MAIN
Changes since 1.23: +90 -37 lines
File MIME type: text/plain
Added SUBSCRIBE, LIST, APPEND and the socket where each command is send.

1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <errno.h>
6
7 #include "config.h"
8 #include "imapfilter.h"
9 #include "data.h"
10
11
12 extern int sockpri;
13
14 static unsigned int tag = 0xF00000; /* Every IMAP command is prefixed
15 with a unique [:alnum:] string. */
16
17 /*
18 * Send to server data; a command.
19 */
20 unsigned int send_command(int *sock, char *cmd)
21 {
22 #ifdef DEBUG
23 printf("debug: sending command: %s", cmd);
24 #endif
25
26 socket_write(sock, cmd);
27
28 return tag++;
29 }
30
31
32 #ifdef DEBUG
33 /*
34 * IMAP NOOP: does nothing always succeeds.
35 */
36 int imap_noop(int *sock)
37 {
38 char cmd[SMALL_CMD];
39
40 verbose("Client request: NOOP\n");
41
42 snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);
43
44 return send_command(sock, cmd);
45 }
46 #endif
47
48
49 /*
50 * IMAP CAPABILITY: requests listing of capabilities that the server supports.
51 */
52 int imap_capability(int *sock)
53 {
54 char cmd[SMALL_CMD];
55
56 verbose("Client request: CAPABILITY\n");
57
58 snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);
59
60 return send_command(sock, cmd);
61 }
62
63
64 /*
65 * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by
66 * the server for mailboxes (RFC 2342).
67 */
68 int imap_namespace(int *sock)
69 {
70 char cmd[SMALL_CMD];
71
72 verbose("Client request: NAMESPACE\n");
73
74 snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);
75
76 return send_command(sock, cmd);
77 }
78
79
80 /*
81 * IMAP LOGOUT: informs server that client is done.
82 */
83 int imap_logout(int *sock)
84 {
85 char cmd[SMALL_CMD];
86
87 verbose("Client request: LOGOUT\n");
88
89 snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);
90
91 return send_command(sock, cmd);
92 }
93
94
95 /*
96 * IMAP LOGIN: identifies client to server.
97 */
98 int imap_login(int *sock, char *user, char *pass)
99 {
100 int r;
101 char *cmd;
102
103 cmd = (char *) smalloc(MEDIUM_CMD);
104
105 verbose("Client request: LOGIN\n");
106
107 snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
108 pass);
109
110 r = send_command(sock, cmd);
111
112 sfree(cmd);
113
114 return r;
115 }
116
117
118 /*
119 * IMAP LIST: returns a subset of names from the complete set of names
120 * available to the client.
121 *
122 int imap_list(int *sock, char *refer, char *mbox)
123 {
124 int r;
125 char cmd[BIG_CMD];
126
127 verbose("Client request: LIST\n");
128
129 snprintf(cmd, MEDIUM_CMD, "%X LIST \"%s\" \"%s\"\r\n", tag, refer,
130 mbox);
131
132 r = send_command(sock, cmd);
133
134 return r;
135 }*/
136
137
138 /*
139 * IMAP SUBSCRIBE: adds the specified mailbox name to the server's
140 * set of "active" or "subscribed" mailboxes.
141 */
142 int imap_subscribe(int *sock, char *mbox)
143 {
144 char cmd[MEDIUM_CMD];
145
146 verbose("Client request: SUBSCRIBE\n");
147
148 snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);
149
150 return send_command(sock, cmd);
151 }
152
153
154 /*
155 * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
156 */
157 int imap_examine(int *sock, char *mbox)
158 {
159 char cmd[MEDIUM_CMD];
160
161 verbose("Client request: EXAMINE %s\n", mbox);
162
163 snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
164
165 return send_command(sock, cmd);
166 }
167
168
169 /*
170 * IMAP SELECT: access a mailbox in READ-WRITE mode.
171 */
172 int imap_select(int *sock, char *mbox)
173 {
174 char cmd[SMALL_CMD];
175
176 verbose("Client request: SELECT\n");
177
178 snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
179
180 return send_command(sock, cmd);
181 }
182
183
184 /*
185 * IMAP STATUS: requests status of the indicated mailbox.
186 */
187 int imap_status(int *sock, char *mbox, char *items)
188 {
189 char cmd[MEDIUM_CMD];
190
191 verbose("Client request: STATUS\n");
192
193 snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
194
195 return send_command(sock, cmd);
196 }
197
198
199 /*
200 * IMAP CREATE: create mailbox.
201 */
202 int imap_create(int *sock, char *mbox)
203 {
204 char cmd[MEDIUM_CMD];
205
206 verbose("Client request: CREATE\n");
207
208 snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);
209
210 return send_command(sock, cmd);
211 }
212
213
214 /*
215 * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
216 */
217 int imap_search(int *sock, char *search)
218 {
219 char cmd[BIG_CMD];
220
221 verbose("Client request: SEARCH\n");
222
223 snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
224
225 return send_command(sock, cmd);
226 }
227
228
229 /*
230 * IMAP FETCH: retrieves data associated with a message.
231 */
232 int imap_fetch(int *sock, char *mesg, char *items)
233 {
234 char cmd[MEDIUM_CMD];
235
236 verbose("Client request: FETCH\n");
237
238 snprintf(cmd, MEDIUM_CMD,
239 "%X FETCH %s %s\r\n", tag, mesg, items);
240
241 return send_command(sock, cmd);
242 }
243
244
245 /*
246 * IMAP STORE: alters data associated with a message.
247 */
248 int imap_store(int *sock, char *mesg, char *flags)
249 {
250 char cmd[MEDIUM_CMD];
251
252 verbose("Client request: STORE\n");
253
254 snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,
255 flags);
256
257 return send_command(sock, cmd);
258 }
259
260
261 /*
262 * IMAP COPY: copy messages to mailbox.
263 */
264 int imap_copy(int *sock, char *mesg, char *mbox)
265 {
266 char cmd[MEDIUM_CMD];
267
268 verbose("Client request: COPY\n");
269
270 snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
271
272 return send_command(sock, cmd);
273 }
274
275
276 /*
277 * IMAP APPEND: append message to the end of a mailbox.
278 */
279 int imap_append(int *sock, char *mbox, unsigned int size)
280 {
281 char cmd[MEDIUM_CMD];
282
283 verbose("Client request: APPEND\n");
284
285 snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);
286
287 return send_command(sock, cmd);
288 }
289
290
291
292 /*
293 * IMAP CLOSE: delete messages and return to authenticated state.
294 */
295 int imap_close(int *sock)
296 {
297 char cmd[SMALL_CMD];
298
299 verbose("Client request: CLOSE\n");
300
301 snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
302
303 return send_command(sock, cmd);
304 }
305
306
307 /*
308 * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
309 *
310 int imap_expunge(int *sock)
311 {
312 char cmd[SMALL_CMD];
313
314 verbose("Client request: EXPUNGE\n");
315
316 snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
317
318 return send_command(sock, cmd);
319 }*/

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26