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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (show annotations)
Tue Jan 29 21:23:41 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.22: +10 -3 lines
File MIME type: text/plain
Added secure memory allocation subsystem.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26