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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20.2.2 - (show annotations)
Mon Jan 21 15:44:52 2002 UTC (22 years, 2 months ago) by lefcha
Branch: release-0_7-patches
Changes since 1.20.2.1: +2 -2 lines
File MIME type: text/plain
Spaces inside mailbox names.

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 /*
80 * IMAP LOGOUT: informs server that client is done.
81 */
82 int imap_logout(void)
83 {
84 char cmd[SMALL_CMD];
85
86 verbose("Client request: LOGOUT\n");
87
88 snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);
89
90 return send_command(cmd);
91 }
92
93
94 /*
95 * IMAP LOGIN: identifies client to server.
96 */
97 int imap_login(char *user, char *pass)
98 {
99 char cmd[MEDIUM_CMD];
100
101 verbose("Client request: LOGIN\n");
102
103 snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
104 pass);
105
106 return send_command(cmd);
107 }
108
109
110 /*
111 * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
112 *
113 int imap_examine(char *mbox)
114 {
115 char cmd[MEDIUM_CMD];
116
117 verbose("Client request: EXAMINE %s\n", mbox);
118
119 snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
120
121 return send_command(cmd);
122 }*/
123
124
125 /*
126 * IMAP SELECT: access a mailbox in READ-WRITE mode.
127 */
128 int imap_select(char *mbox)
129 {
130 char cmd[SMALL_CMD];
131
132 verbose("Client request: SELECT\n");
133
134 snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
135
136 return send_command(cmd);
137 }
138
139
140 /*
141 * IMAP STATUS: requests status of the indicated mailbox.
142 */
143 int imap_status(char *mbox, char *items)
144 {
145 char cmd[MEDIUM_CMD];
146
147 verbose("Client request: STATUS\n");
148
149 snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
150
151 return send_command(cmd);
152 }
153
154
155 /*
156 * IMAP CREATE: create mailbox.
157 */
158 int imap_create(char *mbox)
159 {
160 char cmd[MEDIUM_CMD];
161
162 verbose("Client request: CREATE\n");
163
164 snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);
165
166 return send_command(cmd);
167 }
168
169
170 /*
171 * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
172 */
173 int imap_search(char *search)
174 {
175 char cmd[BIG_CMD];
176
177 verbose("Client request: SEARCH\n");
178
179 snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
180
181 return send_command(cmd);
182 }
183
184
185 /*
186 * IMAP FETCH: retrieves data associated with a message.
187 */
188 int imap_fetch(char *mesg, char *headers, int peek)
189 {
190 char cmd[MEDIUM_CMD];
191
192 verbose("Client request: FETCH\n");
193
194 snprintf(cmd, MEDIUM_CMD,
195 "%X FETCH %s BODY%s[HEADER.FIELDS (%s)]\r\n", tag, mesg,
196 (peek ? ".PEEK" : ""), headers);
197
198 return send_command(cmd);
199 }
200
201
202 /*
203 * IMAP STORE: alters data associated with a message.
204 */
205 int imap_store(char *mesg, char *flags)
206 {
207 char cmd[MEDIUM_CMD];
208
209 verbose("Client request: STORE\n");
210
211 snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag,
212 mesg, flags);
213
214 return send_command(cmd);
215 }
216
217
218 /*
219 * IMAP COPY: copy messages to mailbox.
220 */
221 int imap_copy(char *mesg, char *mbox)
222 {
223 char cmd[MEDIUM_CMD];
224
225 verbose("Client request: COPY\n");
226
227 snprintf(cmd, SMALL_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
228
229 return send_command(cmd);
230 }
231
232
233 /*
234 * IMAP CLOSE: delete messages and return to authenticated state.
235 */
236 int imap_close(void)
237 {
238 char cmd[SMALL_CMD];
239
240 verbose("Client request: CLOSE\n");
241
242 snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
243
244 return send_command(cmd);
245 }
246
247
248 /*
249 * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
250 *
251 int imap_expunge(void)
252 {
253 char cmd[SMALL_CMD];
254
255 verbose("Client request: EXPUNGE\n");
256
257 snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
258
259 return send_command(cmd);
260 }*/

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26