aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imapp/camel-imapp-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/imapp/camel-imapp-store.c')
-rw-r--r--camel/providers/imapp/camel-imapp-store.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/camel/providers/imapp/camel-imapp-store.c b/camel/providers/imapp/camel-imapp-store.c
index 3c0dac5456..00ba0d00ce 100644
--- a/camel/providers/imapp/camel-imapp-store.c
+++ b/camel/providers/imapp/camel-imapp-store.c
@@ -190,29 +190,32 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls)
CamelIMAPPStore *store = CAMEL_IMAPP_STORE (service);
CamelStream * volatile tcp_stream = NULL;
CamelIMAPPStream * volatile imap_stream = NULL;
- struct hostent *h = NULL;
- int ret, port;
+ int ret;
CamelException *ex;
ex = camel_exception_new();
CAMEL_TRY {
+ char *serv;
+ struct addrinfo *ai, hints = { 0 };
+
/* parent class connect initialization */
CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex);
if (ex->id)
camel_exception_throw_ex(ex);
- h = camel_service_gethost(service, ex);
- if (ex->id)
- camel_exception_throw_ex(ex);
-
- port = service->url->port ? service->url->port : IMAP_PORT;
-
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "imap";
+
#ifdef HAVE_SSL
if (camel_url_get_param (service->url, "use_ssl")) {
if (try_starttls)
tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
else {
- port = service->url->port ? service->url->port : 995;
+ if (service->url->port == 0)
+ serv = "imaps";
tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
}
} else {
@@ -221,16 +224,21 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls)
#else
tcp_stream = camel_tcp_stream_raw_new ();
#endif /* HAVE_SSL */
-
- ret = camel_tcp_stream_connect (CAMEL_TCP_STREAM (tcp_stream), h, port);
- camel_free_host (h);
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ex->id)
+ camel_exception_throw_ex(ex);
+
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
if (ret == -1) {
if (errno == EINTR)
camel_exception_throw(CAMEL_EXCEPTION_USER_CANCEL, _("Connection cancelled"));
else
camel_exception_throw(CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s (port %d): %s"),
- service->url->host, port, strerror(errno));
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv, strerror(errno));
}
imap_stream = (CamelIMAPPStream *)camel_imapp_stream_new(tcp_stream);