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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations)
Sat Dec 8 14:39:43 2001 UTC (22 years, 3 months ago) by lefcha
Branch: MAIN
Changes since 1.20: +17 -1 lines
File MIME type: text/plain
Namespace support.

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 static unsigned int tag = 0xF00000; /* Every IMAP command is prefixed
13 with a unique [:alnum:] string. */
14
15 /*
16 * Send to server data; a command.
17 */
18 unsigned int send_command(char *cmd)
19 {
20 #ifdef DEBUG
21 printf("debug: sending command: %s", cmd);
22 #endif
23
24 socket_write(cmd);
25
26 return tag++;
27 }
28
29
30 #ifdef DEBUG
31 /*
32 * IMAP NOOP: does nothing always succeeds.
33 */
34 int imap_noop(void)
35 {
36 char cmd[SMALL_CMD];
37
38 verbose("Client request: NOOP\n");
39
40 snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);
41
42 return send_command(cmd);
43 }
44 #endif
45
46
47 /*
48 * IMAP CAPABILITY: requests listing of capabilities that the server supports.
49 */
50 int imap_capability(void)
51 {
52 char cmd[SMALL_CMD];
53
54 verbose("Client request: CAPABILITY\n");
55
56 snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);
57
58 return send_command(cmd);
59 }
60
61
62 /*
63 * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by
64 * the server for mailboxes (RFC 2342).
65 */
66 int imap_namespace(void)
67 {
68 char cmd[SMALL_CMD];
69
70 verbose("Client request: NAMESPACE\n");
71
72 snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);
73
74 return send_command(cmd);
75 }
76
77
78 /*
79 * IMAP LOGOUT: informs server that client is done.
80 */
81 int imap_logout(void)
82 {
83 char cmd[SMALL_CMD];
84
85 verbose("Client request: LOGOUT\n");
86
87 snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);
88
89 return send_command(cmd);
90 }
91
92
93 /*
94 * IMAP LOGIN: identifies client to server.
95 */
96 int imap_login(char *user, char *pass)
97 {
98 char cmd[MEDIUM_CMD];
99
100 verbose("Client request: LOGIN\n");
101
102 snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
103 pass);
104
105 return send_command(cmd);
106 }
107
108
109 /*
110 * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
111 *
112 int imap_examine(char *mbox)
113 {
114 char cmd[MEDIUM_CMD];
115
116 verbose("Client request: EXAMINE %s\n", mbox);
117
118 snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
119
120 return send_command(cmd);
121 }*/
122
123
124 /*
125 * IMAP SELECT: access a mailbox in READ-WRITE mode.
126 */
127 int imap_select(char *mbox)
128 {
129 char cmd[SMALL_CMD];
130
131 verbose("Client request: SELECT\n");
132
133 snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
134
135 return send_command(cmd);
136 }
137
138
139 /*
140 * IMAP STATUS: requests status of the indicated mailbox.
141 */
142 int imap_status(char *mbox, char *items)
143 {
144 char cmd[MEDIUM_CMD];
145
146 verbose("Client request: STATUS\n");
147
148 snprintf(cmd, MEDIUM_CMD, "%X STATUS %s (%s)\r\n", tag, mbox, items);
149
150 return send_command(cmd);
151 }
152
153
154 /*
155 * IMAP CREATE: create mailbox.
156 */
157 int imap_create(char *mbox)
158 {
159 char cmd[MEDIUM_CMD];
160
161 verbose("Client request: CREATE\n");
162
163 snprintf(cmd, MEDIUM_CMD, "%X CREATE %s\r\n", tag, mbox);
164
165 return send_command(cmd);
166 }
167
168
169 /*
170 * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
171 */
172 int imap_search(char *search)
173 {
174 char cmd[BIG_CMD];
175
176 verbose("Client request: SEARCH\n");
177
178 snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
179
180 return send_command(cmd);
181 }
182
183
184 /*
185 * IMAP FETCH: retrieves data associated with a message.
186 */
187 int imap_fetch(char *mesg, char *headers, int peek)
188 {
189 char cmd[MEDIUM_CMD];
190
191 verbose("Client request: FETCH\n");
192
193 snprintf(cmd, MEDIUM_CMD,
194 "%X FETCH %s BODY%s[HEADER.FIELDS (%s)]\r\n", tag, mesg,
195 (peek ? ".PEEK" : ""), headers);
196
197 return send_command(cmd);
198 }
199
200
201 /*
202 * IMAP STORE: alters data associated with a message.
203 */
204 int imap_store(char *mesg, char *flags)
205 {
206 char cmd[MEDIUM_CMD];
207
208 verbose("Client request: STORE\n");
209
210 snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,
211 flags);
212
213 return send_command(cmd);
214 }
215
216
217 /*
218 * IMAP COPY: copy messages to mailbox.
219 */
220 int imap_copy(char *mesg, char *mbox)
221 {
222 char cmd[MEDIUM_CMD];
223
224 verbose("Client request: COPY\n");
225
226 snprintf(cmd, SMALL_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
227
228 return send_command(cmd);
229 }
230
231
232 /*
233 * IMAP CLOSE: delete messages and return to authenticated state.
234 */
235 int imap_close(void)
236 {
237 char cmd[SMALL_CMD];
238
239 verbose("Client request: CLOSE\n");
240
241 snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
242
243 return send_command(cmd);
244 }
245
246
247 /*
248 * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
249 *
250 int imap_expunge(void)
251 {
252 char cmd[SMALL_CMD];
253
254 verbose("Client request: EXPUNGE\n");
255
256 snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
257
258 return send_command(cmd);
259 }*/

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26