3 |
#include <string.h> |
#include <string.h> |
4 |
#include <strings.h> |
#include <strings.h> |
5 |
#include <ctype.h> |
#include <ctype.h> |
6 |
#include <sys/types.h> /* IEEE Std 1003.1-2001 non-conformance. */ |
#include <sys/types.h> /* For POSIX.1-2001 non-conformant systems. */ |
7 |
#include <regex.h> |
#include <regex.h> |
8 |
#include <setjmp.h> |
#include <setjmp.h> |
9 |
|
|
12 |
#include "buffer.h" |
#include "buffer.h" |
13 |
|
|
14 |
|
|
15 |
extern conn_t connpri, connaux; |
extern connection_t connpri, connaux; |
16 |
|
extern options_t opts; |
17 |
extern jmp_buf acctloop; |
extern jmp_buf acctloop; |
18 |
|
|
19 |
buffer_t ibuf; /* Input buffer. */ |
buffer_t ibuf; /* Input buffer. */ |
20 |
|
|
21 |
|
|
22 |
void receive_response(conn_t * conn, char *buf); |
void receive_response(connection_t * conn, char *buf); |
23 |
void bye_response(char *buf); |
void response_bye(char *buf); |
24 |
int analyze_response(conn_t * conn, char *buf); |
int analyze_response(connection_t * conn, char *buf); |
25 |
|
|
26 |
|
|
27 |
/* |
/* |
28 |
* Read one packet of data that the server sent. |
* Read one packet of data that the server sent. |
29 |
*/ |
*/ |
30 |
void |
void |
31 |
receive_response(conn_t * conn, char *buf) |
receive_response(connection_t * conn, char *buf) |
32 |
{ |
{ |
33 |
|
|
34 |
if (socket_read(conn, buf) == ERROR_NETWORK) |
if (socket_read(conn, buf) == ERROR_NETWORK) |
35 |
longjmp(acctloop, -1); |
longjmp(acctloop, -1); |
36 |
|
|
37 |
#ifdef DEBUG |
debug("getting response (%s):\n\n%s\n", |
|
fprintf(stderr, "debug: getting response (%s):\n\n%s\n", |
|
38 |
(conn == &connpri ? "primary" : "auxiliary"), buf); |
(conn == &connpri ? "primary" : "auxiliary"), buf); |
|
#endif |
|
39 |
} |
} |
40 |
|
|
41 |
|
|
43 |
* Get server response to client's request. |
* Get server response to client's request. |
44 |
*/ |
*/ |
45 |
int |
int |
46 |
server_response(conn_t * conn, unsigned int tag) |
response_generic(connection_t * conn, unsigned int tag) |
47 |
{ |
{ |
48 |
reset_buffer(&ibuf); |
|
49 |
|
buffer_reset(&ibuf); |
50 |
|
|
51 |
do { |
do { |
52 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
53 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
54 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
55 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
56 |
|
|
57 |
return analyze_response(conn, ibuf.data); |
return analyze_response(conn, ibuf.data); |
62 |
* Check if server sent a BYE response (connection is closed immediately). |
* Check if server sent a BYE response (connection is closed immediately). |
63 |
*/ |
*/ |
64 |
void |
void |
65 |
bye_response(char *buf) |
response_bye(char *buf) |
66 |
{ |
{ |
67 |
|
|
68 |
if (strcasestr(buf, "* BYE")) |
if (strcasestr(buf, "* BYE")) |
69 |
longjmp(acctloop, -1); |
longjmp(acctloop, -1); |
70 |
} |
} |
74 |
* Process the greeting that server sends during connection. |
* Process the greeting that server sends during connection. |
75 |
*/ |
*/ |
76 |
int |
int |
77 |
greeting_response(conn_t * conn) |
response_greeting(connection_t * conn) |
78 |
{ |
{ |
79 |
reset_buffer(&ibuf); |
|
80 |
|
buffer_reset(&ibuf); |
81 |
|
|
82 |
receive_response(conn, ibuf.data); |
receive_response(conn, ibuf.data); |
83 |
|
|
84 |
verbose("%s: %s", (conn == &connpri ? "S" : "s"), ibuf); |
verbose("%s: %s", (conn == &connpri ? "S" : "s"), ibuf); |
85 |
|
|
86 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
87 |
|
|
88 |
if (strcasestr(ibuf.data, "* PREAUTH")) |
if (strcasestr(ibuf.data, "* PREAUTH")) |
89 |
return RESPONSE_PREAUTH; |
return RESPONSE_PREAUTH; |
96 |
* Process the data that server sent due to IMAP LOGOUT client request. |
* Process the data that server sent due to IMAP LOGOUT client request. |
97 |
*/ |
*/ |
98 |
int |
int |
99 |
logout_response(conn_t * conn, unsigned int tag) |
response_logout(connection_t * conn, unsigned int tag) |
100 |
{ |
{ |
101 |
reset_buffer(&ibuf); |
|
102 |
|
buffer_reset(&ibuf); |
103 |
|
|
104 |
do { |
do { |
105 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
106 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
107 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
108 |
|
|
114 |
* Process the data that server sent due to IMAP CAPABILITY client request. |
* Process the data that server sent due to IMAP CAPABILITY client request. |
115 |
*/ |
*/ |
116 |
int |
int |
117 |
capability_response(conn_t * conn, unsigned int tag) |
response_capability(connection_t * conn, unsigned int tag) |
118 |
{ |
{ |
119 |
reset_buffer(&ibuf); |
|
120 |
|
buffer_reset(&ibuf); |
121 |
|
|
122 |
do { |
do { |
123 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
124 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
125 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
126 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
127 |
|
|
128 |
if (!strcasestr(ibuf.data, "IMAP4rev1")) { |
if (opts.force_protocol == PROTOCOL_NONE) { |
129 |
error("server does not support IMAP4rev1 protocol\n"); |
if (strcasestr(ibuf.data, "IMAP4rev1")) |
130 |
return -2; |
conn->proto = PROTOCOL_IMAP4REV1; |
131 |
} |
else if (strcasestr(ibuf.data, "IMAP4")) |
132 |
|
conn->proto = PROTOCOL_IMAP4; |
133 |
|
else { |
134 |
|
error("server supports neither the IMAP4rev1 nor the " |
135 |
|
"IMAP4 protocol\n"); |
136 |
|
return -2; |
137 |
|
} |
138 |
|
} else |
139 |
|
conn->proto = opts.force_protocol; |
140 |
|
|
141 |
if (strcasestr(ibuf.data, "NAMESPACE")) |
if (strcasestr(ibuf.data, "NAMESPACE")) |
142 |
conn->caps |= CAPABILITY_NAMESPACE; |
conn->caps |= CAPABILITY_NAMESPACE; |
143 |
#ifdef CRAM_MD5 |
#ifdef CRAM_MD5 |
144 |
if (strcasestr(ibuf.data, "AUTH=CRAM-MD5")) |
if (strcasestr(ibuf.data, "AUTH=CRAM-MD5")) |
145 |
conn->caps |= CAPABILITY_AUTH_CRAM_MD5; |
conn->caps |= CAPABILITY_CRAMMD5; |
146 |
#endif |
#endif |
147 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
148 |
if (strcasestr(ibuf.data, "STARTTLS")) |
if (strcasestr(ibuf.data, "STARTTLS")) |
157 |
* Process the data that server sent due to IMAP AUTHENTICATE client request. |
* Process the data that server sent due to IMAP AUTHENTICATE client request. |
158 |
*/ |
*/ |
159 |
int |
int |
160 |
authenticate_response(conn_t * conn, unsigned int tag, unsigned char **cont) |
response_authenticate(connection_t * conn, unsigned int tag, unsigned char **cont) |
161 |
{ |
{ |
162 |
int i; |
int i; |
163 |
char *c; |
char *c; |
164 |
|
|
165 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
166 |
|
|
167 |
do { |
do { |
168 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
169 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
170 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
171 |
} while (strlen(ibuf.data) == RESPONSE_BUF && |
} while (strlen(ibuf.data) == RESPONSE_BUF && |
172 |
!strcasestr(ibuf.data, ultostr(tag, 16))); |
!strcasestr(ibuf.data, ultostr(tag, 16))); |
173 |
|
|
188 |
* Process the data that server sent due to IMAP NAMESPACE client request. |
* Process the data that server sent due to IMAP NAMESPACE client request. |
189 |
*/ |
*/ |
190 |
int |
int |
191 |
namespace_response(conn_t * conn, unsigned int tag) |
response_namespace(connection_t * conn, unsigned int tag) |
192 |
{ |
{ |
193 |
char *c, *d; |
char *c, *d; |
194 |
|
|
195 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
196 |
|
|
197 |
do { |
do { |
198 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
199 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
200 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
201 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
202 |
|
|
203 |
if ((c = strcasestr(ibuf.data, "* NAMESPACE"))) { |
if ((c = strcasestr(ibuf.data, "* NAMESPACE"))) { |
206 |
c = strchr(c, '"') + 1; |
c = strchr(c, '"') + 1; |
207 |
d = strchr(c, '"') + 1; |
d = strchr(c, '"') + 1; |
208 |
|
|
209 |
strncat(conn->nsp.prefix, c, d - c - 1); |
strncat(conn->ns.prefix, c, d - c - 1); |
210 |
conn->nsp.delim = *(strchr(d, '"') + 1); |
conn->ns.delim = *(strchr(d, '"') + 1); |
211 |
} |
} |
212 |
} |
} |
213 |
#ifdef DEBUG |
debug("namespace (%s): '%s' '%c'\n", |
214 |
fprintf(stderr, "debug: namespace (%s): '%s' '%c'\n", |
(conn == &connpri ? "primary" : "auxiliary"), conn->ns.prefix, |
215 |
(conn == &connpri ? "primary" : "auxiliary"), conn->nsp.prefix, |
conn->ns.delim); |
|
conn->nsp.delim); |
|
|
#endif |
|
216 |
return analyze_response(conn, ibuf.data); |
return analyze_response(conn, ibuf.data); |
217 |
} |
} |
218 |
|
|
221 |
* Process the data that server sent due to IMAP STATUS client request. |
* Process the data that server sent due to IMAP STATUS client request. |
222 |
*/ |
*/ |
223 |
int |
int |
224 |
status_response(conn_t * conn, unsigned int tag, char *mbox) |
response_status(connection_t * conn, unsigned int tag, char *mbox) |
225 |
{ |
{ |
226 |
int r; |
int r; |
227 |
unsigned int exist, recent, unseen; |
unsigned int exists, recent, unseen; |
228 |
char *c; |
char *c; |
229 |
|
|
230 |
exist = recent = unseen = 0; |
exists = recent = unseen = 0; |
231 |
|
|
232 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
233 |
|
|
234 |
do { |
do { |
235 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
236 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
237 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
238 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
239 |
|
|
240 |
r = analyze_response(conn, ibuf.data); |
r = analyze_response(conn, ibuf.data); |
244 |
|
|
245 |
if ((c = strcasestr(ibuf.data, "MESSAGES"))) { |
if ((c = strcasestr(ibuf.data, "MESSAGES"))) { |
246 |
c += 9; |
c += 9; |
247 |
exist = strtoul(c, NULL, 10); |
exists = strtoul(c, NULL, 10); |
248 |
|
} |
249 |
|
if (exists == 0) { |
250 |
|
info("No messages in mailbox \"%s\".\n", mbox); |
251 |
|
return -2; |
252 |
} |
} |
253 |
if ((c = strcasestr(ibuf.data, "RECENT"))) { |
if ((c = strcasestr(ibuf.data, "RECENT"))) { |
254 |
c += 7; |
c += 7; |
258 |
c += 7; |
c += 7; |
259 |
unseen = strtoul(c, NULL, 10); |
unseen = strtoul(c, NULL, 10); |
260 |
} |
} |
261 |
if (exist == 0) { |
info("%d message%s, %d recent, %d unseen, in mailbox \"%s\".\n", |
262 |
|
exists, plural(exists), recent, unseen, mbox); |
263 |
|
|
264 |
|
return r; |
265 |
|
} |
266 |
|
|
267 |
|
|
268 |
|
/* |
269 |
|
* Process the data that server sent due to IMAP EXAMINE client request. |
270 |
|
*/ |
271 |
|
int |
272 |
|
response_examine(connection_t * conn, unsigned int tag, char *mbox) |
273 |
|
{ |
274 |
|
int r; |
275 |
|
unsigned int exists, recent, unseen; |
276 |
|
char *c; |
277 |
|
|
278 |
|
exists = recent = unseen = 0; |
279 |
|
|
280 |
|
buffer_reset(&ibuf); |
281 |
|
|
282 |
|
do { |
283 |
|
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
284 |
|
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
285 |
|
response_bye(ibuf.data); |
286 |
|
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
287 |
|
|
288 |
|
r = analyze_response(conn, ibuf.data); |
289 |
|
|
290 |
|
if (r == RESPONSE_NO) |
291 |
|
return -2; |
292 |
|
|
293 |
|
if ((c = strcasestr(ibuf.data, "EXISTS"))) { |
294 |
|
while (--c >= ibuf.data && *c != '*'); |
295 |
|
c++; |
296 |
|
exists = strtoul(c, NULL, 10); |
297 |
|
} |
298 |
|
if (exists == 0) { |
299 |
info("No messages in mailbox \"%s\".\n", mbox); |
info("No messages in mailbox \"%s\".\n", mbox); |
300 |
return -2; |
return -2; |
301 |
} |
} |
302 |
info("%d message%s, %d recent, %d unseen, in mailbox \"%s\".\n", exist, |
if ((c = strcasestr(ibuf.data, "RECENT"))) { |
303 |
plural(exist), recent, unseen, mbox); |
while (--c >= ibuf.data && *c != '*'); |
304 |
|
c++; |
305 |
|
recent = strtoul(c, NULL, 10); |
306 |
|
} |
307 |
|
if ((c = strcasestr(ibuf.data, "UNSEEN"))) { |
308 |
|
c += 7; |
309 |
|
unseen = strtoul(c, NULL, 10); |
310 |
|
info("%d message%s, %d recent, %d unseen, in mailbox \"%s\".\n", |
311 |
|
exists, plural(exists), recent, unseen, mbox); |
312 |
|
} else |
313 |
|
info("%d message%s, %d recent, in mailbox \"%s\".\n", exists, |
314 |
|
plural(exists), recent, mbox); |
315 |
|
|
316 |
return r; |
return r; |
317 |
} |
} |
321 |
* Process the data that server sent due to IMAP SELECT client request. |
* Process the data that server sent due to IMAP SELECT client request. |
322 |
*/ |
*/ |
323 |
int |
int |
324 |
select_response(conn_t * conn, unsigned int tag) |
response_select(connection_t * conn, unsigned int tag) |
325 |
{ |
{ |
326 |
reset_buffer(&ibuf); |
|
327 |
|
buffer_reset(&ibuf); |
328 |
|
|
329 |
do { |
do { |
330 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
331 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
332 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
333 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
334 |
|
|
335 |
if (strcasestr(ibuf.data, "[READ-ONLY]")) |
if (strcasestr(ibuf.data, "[READ-ONLY]")) |
343 |
* Process the data that server sent due to IMAP SEARCH client request. |
* Process the data that server sent due to IMAP SEARCH client request. |
344 |
*/ |
*/ |
345 |
int |
int |
346 |
search_response(conn_t * conn, unsigned int tag, char **mesgs) |
response_search(connection_t * conn, unsigned int tag, char **mesgs) |
347 |
{ |
{ |
348 |
char *c, *m; |
char *c, *m; |
349 |
unsigned int blen; |
unsigned int blen; |
350 |
|
|
351 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
352 |
|
|
353 |
do { |
do { |
354 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
355 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
356 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
357 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
358 |
|
|
359 |
if ((c = strcasestr(ibuf.data, "* SEARCH "))) { |
if ((c = strcasestr(ibuf.data, "* SEARCH "))) { |
376 |
* Process the data that server sent due to IMAP FETCH client request. |
* Process the data that server sent due to IMAP FETCH client request. |
377 |
*/ |
*/ |
378 |
int |
int |
379 |
fetch_response(conn_t * conn, unsigned int tag, int reset, char *fetch) |
response_fetch(connection_t * conn, unsigned int tag, int reset, char *fetch) |
380 |
{ |
{ |
381 |
unsigned int i; |
unsigned int i; |
382 |
static unsigned int s; |
static unsigned int s; |
388 |
} |
} |
389 |
i = 0; |
i = 0; |
390 |
|
|
391 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
392 |
|
|
393 |
do { |
do { |
394 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
395 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
396 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
397 |
} while (strlen(ibuf.data) < RESPONSE_BUF && |
} while (strlen(ibuf.data) < RESPONSE_BUF && |
398 |
!strcasestr(ibuf.data, ultostr(tag, 16))); |
!strcasestr(ibuf.data, ultostr(tag, 16))); |
399 |
|
|
424 |
* Process the data that server sent due to IMAP FETCH FAST client request. |
* Process the data that server sent due to IMAP FETCH FAST client request. |
425 |
*/ |
*/ |
426 |
int |
int |
427 |
fetchfast_response(conn_t * conn, char **flags, char **date, |
response_fetchfast(connection_t * conn, char **flags, char **date, |
428 |
unsigned int *size, unsigned int tag) |
unsigned int *size, unsigned int tag) |
429 |
{ |
{ |
430 |
char *c, *m; |
char *c, *m; |
432 |
|
|
433 |
*size = 0; |
*size = 0; |
434 |
|
|
435 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
436 |
|
|
437 |
do { |
do { |
438 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
439 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
440 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
441 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
442 |
|
|
443 |
if ((c = strcasestr(ibuf.data, "FETCH (FLAGS ("))) { |
if ((c = strcasestr(ibuf.data, "FETCH (FLAGS ("))) { |
485 |
* Process the data that server sent due to IMAP APPEND client request. |
* Process the data that server sent due to IMAP APPEND client request. |
486 |
*/ |
*/ |
487 |
int |
int |
488 |
append_response(conn_t * conn, unsigned int tag) |
response_append(connection_t * conn, unsigned int tag) |
489 |
{ |
{ |
490 |
int r; |
int r; |
491 |
|
|
492 |
r = RESPONSE_OK; |
r = RESPONSE_OK; |
493 |
|
|
494 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
495 |
|
|
496 |
do { |
do { |
497 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
498 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
499 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
500 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
501 |
|
|
502 |
if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO && |
if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO && |
511 |
* Process the data that server sent due to IMAP COPY client request. |
* Process the data that server sent due to IMAP COPY client request. |
512 |
*/ |
*/ |
513 |
int |
int |
514 |
copy_response(conn_t * conn, unsigned int tag) |
response_copy(connection_t * conn, unsigned int tag) |
515 |
{ |
{ |
516 |
int r; |
int r; |
517 |
|
|
518 |
r = RESPONSE_OK; |
r = RESPONSE_OK; |
519 |
|
|
520 |
reset_buffer(&ibuf); |
buffer_reset(&ibuf); |
521 |
|
|
522 |
do { |
do { |
523 |
check_buffer(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
buffer_check(&ibuf, strlen(ibuf.data) + RESPONSE_BUF); |
524 |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
receive_response(conn, ibuf.data + strlen(ibuf.data)); |
525 |
bye_response(ibuf.data); |
response_bye(ibuf.data); |
526 |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
} while (!strcasestr(ibuf.data, ultostr(tag, 16))); |
527 |
|
|
528 |
if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO && |
if ((r = analyze_response(conn, ibuf.data)) == RESPONSE_NO && |
538 |
* delivered or there was some kind of error. |
* delivered or there was some kind of error. |
539 |
*/ |
*/ |
540 |
int |
int |
541 |
analyze_response(conn_t * conn, char *buf) |
analyze_response(connection_t * conn, char *buf) |
542 |
{ |
{ |
543 |
int r; |
int r; |
544 |
regex_t creg; |
regex_t creg; |