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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (show annotations)
Fri Mar 7 14:03:50 2003 UTC (21 years ago) by lefcha
Branch: MAIN
Changes since 1.30: +2 -2 lines
File MIME type: text/plain
Function imap_examine() is not needed for now.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26