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

Contents of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (show annotations)
Sat Nov 10 15:34:20 2001 UTC (22 years, 5 months ago) by lefcha
Branch: MAIN
CVS Tags: release-0_7
Branch point for: release-0_7-patches
Changes since 1.19: +0 -2 lines
File MIME type: text/plain
Indent 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 * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
155 */
156 int imap_search(char *search)
157 {
158 char cmd[BIG_CMD];
159
160 verbose("Client request: SEARCH\n");
161
162 snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
163
164 return send_command(cmd);
165 }
166
167
168 /*
169 * IMAP FETCH: retrieves data associated with a message.
170 */
171 int imap_fetch(char *mesg, char *headers, int peek)
172 {
173 char cmd[MEDIUM_CMD];
174
175 verbose("Client request: FETCH\n");
176
177 snprintf(cmd, MEDIUM_CMD,
178 "%X FETCH %s BODY%s[HEADER.FIELDS (%s)]\r\n", tag, mesg,
179 (peek ? ".PEEK" : ""), headers);
180
181 return send_command(cmd);
182 }
183
184
185 /*
186 * IMAP STORE: alters data associated with a message.
187 */
188 int imap_store(char *mesg, char *flags)
189 {
190 char cmd[MEDIUM_CMD];
191
192 verbose("Client request: STORE\n");
193
194 snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,
195 flags);
196
197 return send_command(cmd);
198 }
199
200
201 /*
202 * IMAP COPY: copy messages to mailbox.
203 */
204 int imap_copy(char *mesg, char *mbox)
205 {
206 char cmd[MEDIUM_CMD];
207
208 verbose("Client request: COPY\n");
209
210 snprintf(cmd, SMALL_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
211
212 return send_command(cmd);
213 }
214
215
216 /*
217 * IMAP CLOSE: delete messages and return to authenticated state.
218 */
219 int imap_close(void)
220 {
221 char cmd[SMALL_CMD];
222
223 verbose("Client request: CLOSE\n");
224
225 snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
226
227 return send_command(cmd);
228 }
229
230
231 /*
232 * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
233 *
234 int imap_expunge(void)
235 {
236 char cmd[SMALL_CMD];
237
238 verbose("Client request: EXPUNGE\n");
239
240 snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
241
242 return send_command(cmd);
243 }*/

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26