62 |
|
|
63 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
64 |
if (protocol != SSL_DISABLED) { |
if (protocol != SSL_DISABLED) { |
65 |
ssl_init(protocol); |
if (!ssl_init(protocol)) { |
66 |
info("Connected to %s using %s.\n", serv, SSL_get_cipher(ssl)); |
info("Connected to %s using %s.\n", serv, SSL_get_cipher(ssl)); |
67 |
} else { |
return 0; |
68 |
|
} |
69 |
|
} else |
70 |
ssl = NULL; |
ssl = NULL; |
71 |
#endif |
#endif |
|
info("Connected to %s.\n", serv); |
|
|
#ifdef SSL_TLS |
|
|
} |
|
|
#endif |
|
|
|
|
72 |
|
|
73 |
|
info("Connected to %s.\n", serv); |
74 |
|
|
75 |
return 0; |
return 0; |
76 |
} |
} |
77 |
|
|
180 |
fd_set fds; |
fd_set fds; |
181 |
struct timeval tv; |
struct timeval tv; |
182 |
|
|
183 |
r = s = 0; |
r = 0; |
184 |
|
s = 1; |
185 |
|
|
186 |
memset(buf, 0, RESPONSE_BUF); |
memset(buf, 0, RESPONSE_BUF); |
187 |
|
|
188 |
tv.tv_sec = 30; |
tv.tv_sec = 60; |
189 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
190 |
|
|
191 |
flags = fcntl(sock, F_GETFL, 0); |
flags = fcntl(sock, F_GETFL, 0); |
196 |
|
|
197 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
198 |
if (ssl) { |
if (ssl) { |
199 |
if (SSL_pending(ssl) || ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0 |
if (SSL_pending(ssl) |
200 |
&& FD_ISSET(sock, &fds))) |
|| ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0 |
201 |
|
&& FD_ISSET(sock, &fds))) |
202 |
r = SSL_read(ssl, buf, RESPONSE_BUF - 1); |
r = SSL_read(ssl, buf, RESPONSE_BUF - 1); |
203 |
} else |
} else |
204 |
#endif |
#endif |
208 |
|
|
209 |
fcntl(sock, F_SETFL, flags); |
fcntl(sock, F_SETFL, flags); |
210 |
|
|
211 |
if (s <= 0) |
if (s == -1) |
212 |
fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n", |
fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n", |
213 |
strerror(errno)); |
strerror(errno)); |
214 |
|
else if (!s) |
215 |
|
fatal(ERROR_NETWORK, |
216 |
|
"imapfilter: timeout period expired while waiting data\n"); |
217 |
|
|
218 |
#ifdef SSL_TLS |
#ifdef SSL_TLS |
219 |
if (ssl) { |
if (ssl) { |
220 |
if (r <= 0) |
if (r < 0) |
221 |
fatal(ERROR_NETWORK, "imapfilter: reading data; %s", |
fatal(ERROR_NETWORK, "imapfilter: reading data; %s", |
222 |
ERR_error_string(r, NULL)); |
ERR_error_string(r, NULL)); |
223 |
} else |
} else |