int mailpop3_socket_connect(mailpop3 * f, const char * server, uint16_t port) { int s; mailstream * stream; #if HAVE_CFNETWORK if (mailstream_cfstream_enabled) { return mailpop3_cfsocket_connect(f, server, port); } #endif if (port == 0) { port = mail_get_service_port(SERVICE_NAME_POP3, SERVICE_TYPE_TCP); if (port == 0) port = DEFAULT_POP3_PORT; } /* Connection */ s = mail_tcp_connect_timeout(server, port, f->pop3_timeout); if (s == -1) return MAILPOP3_ERROR_CONNECTION_REFUSED; stream = mailstream_socket_open_timeout(s, f->pop3_timeout); if (stream == NULL) { #ifdef WIN32 closesocket(s); #else close(s); #endif return MAILPOP3_ERROR_MEMORY; } return mailpop3_connect(f, stream); }
int mailpop3_ssl_connect_with_callback(mailpop3 * f, const char * server, uint16_t port, void (* callback)(struct mailstream_ssl_context * ssl_context, void * data), void * data) { int s; mailstream * stream; #if HAVE_CFNETWORK if (mailstream_cfstream_enabled) { if (callback == NULL) { return mailpop3_cfssl_connect(f, server, port); } } #endif if (port == 0) { port = mail_get_service_port(SERVICE_NAME_POP3S, SERVICE_TYPE_TCP); if (port == 0) port = DEFAULT_POP3S_PORT; } /* Connection */ s = mail_tcp_connect_timeout(server, port, f->pop3_timeout); if (s == -1) return MAILPOP3_ERROR_CONNECTION_REFUSED; stream = mailstream_ssl_open_with_callback_timeout(s, f->pop3_timeout, callback, data); if (stream == NULL) { #ifdef WIN32 closesocket(s); #else close(s); #endif return MAILPOP3_ERROR_SSL; } return mailpop3_connect(f, stream); }