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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.25 - (show annotations)
Sat Jul 13 14:11:08 2002 UTC (21 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.24: +14 -13 lines
File MIME type: text/plain
Added variable to enable direct expunge of marked deleted mail.

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
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 LOGIN: identifies client to server.
98 */
99 int imap_login(int *sock, char *user, char *pass)
100 {
101 int r;
102 char *cmd;
103
104 cmd = (char *)smalloc(MEDIUM_CMD);
105
106 verbose("Client request: LOGIN\n");
107
108 snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
109 pass);
110
111 r = send_command(sock, cmd);
112
113 sfree(cmd);
114
115 return r;
116 }
117
118
119 /*
120 * IMAP LIST: returns a subset of names from the complete set of names
121 * available to the client.
122 *
123 int imap_list(int *sock, char *refer, char *mbox)
124 {
125 int r;
126 char cmd[BIG_CMD];
127
128 verbose("Client request: LIST\n");
129
130 snprintf(cmd, MEDIUM_CMD, "%X LIST \"%s\" \"%s\"\r\n", tag, refer,
131 mbox);
132
133 r = send_command(sock, cmd);
134
135 return r;
136 }*/
137
138
139 /*
140 * IMAP SUBSCRIBE: adds the specified mailbox name to the server's
141 * set of "active" or "subscribed" mailboxes.
142 */
143 int imap_subscribe(int *sock, char *mbox)
144 {
145 char cmd[MEDIUM_CMD];
146
147 verbose("Client request: SUBSCRIBE\n");
148
149 snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);
150
151 return send_command(sock, cmd);
152 }
153
154
155 /*
156 * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
157 */
158 int imap_examine(int *sock, char *mbox)
159 {
160 char cmd[MEDIUM_CMD];
161
162 verbose("Client request: EXAMINE %s\n", mbox);
163
164 snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
165
166 return send_command(sock, cmd);
167 }
168
169
170 /*
171 * IMAP SELECT: access a mailbox in READ-WRITE mode.
172 */
173 int imap_select(int *sock, char *mbox)
174 {
175 char cmd[SMALL_CMD];
176
177 verbose("Client request: SELECT\n");
178
179 snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
180
181 return send_command(sock, cmd);
182 }
183
184
185 /*
186 * IMAP STATUS: requests status of the indicated mailbox.
187 */
188 int imap_status(int *sock, char *mbox, char *items)
189 {
190 char cmd[MEDIUM_CMD];
191
192 verbose("Client request: STATUS\n");
193
194 snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
195
196 return send_command(sock, cmd);
197 }
198
199
200 /*
201 * IMAP CREATE: create mailbox.
202 */
203 int imap_create(int *sock, char *mbox)
204 {
205 char cmd[MEDIUM_CMD];
206
207 verbose("Client request: CREATE\n");
208
209 snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);
210
211 return send_command(sock, cmd);
212 }
213
214
215 /*
216 * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
217 */
218 int imap_search(int *sock, char *search)
219 {
220 char cmd[BIG_CMD];
221
222 verbose("Client request: SEARCH\n");
223
224 snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
225
226 return send_command(sock, cmd);
227 }
228
229
230 /*
231 * IMAP FETCH: retrieves data associated with a message.
232 */
233 int imap_fetch(int *sock, char *mesg, char *items)
234 {
235 char cmd[MEDIUM_CMD];
236
237 verbose("Client request: FETCH\n");
238
239 snprintf(cmd, MEDIUM_CMD,
240 "%X FETCH %s %s\r\n", tag, mesg, items);
241
242 return send_command(sock, cmd);
243 }
244
245
246 /*
247 * IMAP STORE: alters data associated with a message.
248 */
249 int imap_store(int *sock, char *mesg, char *flags)
250 {
251 char cmd[MEDIUM_CMD];
252
253 verbose("Client request: STORE\n");
254
255 snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,
256 flags);
257
258 return send_command(sock, cmd);
259 }
260
261
262 /*
263 * IMAP COPY: copy messages to mailbox.
264 */
265 int imap_copy(int *sock, char *mesg, char *mbox)
266 {
267 char cmd[MEDIUM_CMD];
268
269 verbose("Client request: COPY\n");
270
271 snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
272
273 return send_command(sock, cmd);
274 }
275
276
277 /*
278 * IMAP APPEND: append message to the end of a mailbox.
279 */
280 int imap_append(int *sock, char *mbox, unsigned int size)
281 {
282 char cmd[MEDIUM_CMD];
283
284 verbose("Client request: APPEND\n");
285
286 snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);
287
288 return send_command(sock, cmd);
289 }
290
291
292
293 /*
294 * IMAP CLOSE: delete messages and return to authenticated state.
295 */
296 int imap_close(int *sock)
297 {
298 char cmd[SMALL_CMD];
299
300 verbose("Client request: CLOSE\n");
301
302 snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
303
304 return send_command(sock, cmd);
305 }
306
307
308 /*
309 * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
310 */
311 int imap_expunge(int *sock)
312 {
313 char cmd[SMALL_CMD];
314
315 verbose("Client request: EXPUNGE\n");
316
317 snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
318
319 return send_command(sock, cmd);
320 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26