4 |
#include <ctype.h> |
#include <ctype.h> |
5 |
#include <errno.h> |
#include <errno.h> |
6 |
#include <string.h> |
#include <string.h> |
|
#include <fcntl.h> |
|
7 |
#include <sys/time.h> |
#include <sys/time.h> |
8 |
#include <sys/types.h> |
#include <sys/types.h> |
9 |
#include <regex.h> |
#include <regex.h> |
10 |
|
|
|
|
|
11 |
#include "config.h" |
#include "config.h" |
12 |
#include "imapfilter.h" |
#include "imapfilter.h" |
13 |
|
|
14 |
|
|
|
extern int sock; |
|
15 |
extern unsigned int options; |
extern unsigned int options; |
16 |
|
|
17 |
|
|
20 |
*/ |
*/ |
21 |
int receive_response(char *buf) |
int receive_response(char *buf) |
22 |
{ |
{ |
23 |
int flags; |
socket_read(buf); |
|
fd_set fds; |
|
|
struct timeval tv; |
|
|
|
|
|
memset(buf, 0, RESPONSE_BUF); |
|
|
|
|
|
tv.tv_sec = 20; |
|
|
tv.tv_usec = 0; |
|
|
|
|
|
flags = fcntl(sock, F_GETFL, 0); |
|
|
fcntl(sock, F_SETFL, flags | O_NONBLOCK); |
|
|
|
|
|
FD_ZERO(&fds); |
|
|
FD_SET(sock, &fds); |
|
24 |
|
|
|
if ((select(sock + 1, &fds, NULL, NULL, &tv) > 0) |
|
|
&& FD_ISSET(sock, &fds)) { |
|
|
if (read(sock, buf, RESPONSE_BUF - 1) != -1) { |
|
25 |
#ifdef DEBUG |
#ifdef DEBUG |
26 |
printf("\n%s\n", buf); |
printf("\n%s\n", buf); |
27 |
#endif |
#endif |
28 |
fcntl(sock, F_SETFL, flags); |
|
29 |
|
return analyze_response(buf); |
|
return analyze_response(buf); |
|
|
} |
|
|
} |
|
|
fcntl(sock, F_SETFL, flags); |
|
|
|
|
|
fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n", |
|
|
strerror(errno)); |
|
|
|
|
|
return ERROR_NETWORK; |
|
30 |
} |
} |
31 |
|
|
32 |
|
|
189 |
headers[i] = *(pos + 3 + i); |
headers[i] = *(pos + 3 + i); |
190 |
|
|
191 |
headers[i] = 0; |
headers[i] = 0; |
192 |
|
pos += i; |
193 |
|
|
194 |
if (*headers) { |
if (*headers) { |
195 |
if (options & OPTION_HEADERS) |
if (options & OPTION_HEADERS) |