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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations)
Fri Nov 9 15:52:52 2001 UTC (22 years, 4 months ago) by lefcha
Branch: MAIN
Changes since 1.17: +1 -1 lines
File MIME type: text/plain
Just indented to K&R style.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26