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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (show annotations)
Fri Feb 21 18:55:15 2003 UTC (21 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.28: +0 -1 lines
File MIME type: text/plain
Remove unused variable.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26