From 86e4b759e84c17ef8e035af2695c081660aa80d5 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 9 Mar 2017 10:15:16 -0500 Subject: [PATCH] Try pop3s first, then pop3 --- citadel/modules/pop3client/serv_pop3client.c | 47 ++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index 2aacd5c67..658644d57 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -70,9 +70,50 @@ static int doing_pop3client = 0; */ void pop3client_one_mailbox(struct ctdlroom *qrbuf, const char *host, const char *user, const char *pass, int keep, long interval) { - syslog(LOG_DEBUG, "\033[33mpop3client: room=<%s> host=<%s> user=<%s> pass=<%s> keep=<%d> interval=<%ld>\033[0m", - qrbuf->QRname, host, user, pass, keep, interval - ); + syslog(LOG_DEBUG, "\033[33mpop3client: room=<%s> host=<%s> user=<%s> pass=<%s> keep=<%d> interval=<%ld>\033[0m", + qrbuf->QRname, host, user, pass, keep, interval + ); + + char url[SIZ]; + CURL *curl; + CURLcode res = CURLE_OK; + int is_pop3s = 0; + + curl = curl_easy_init(); + if (!curl) { + return; + } + + curl_easy_setopt(curl, CURLOPT_USERNAME, user); + curl_easy_setopt(curl, CURLOPT_PASSWORD, pass); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15); + curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "UIDL"); + + /* Try POP3S (SSL encrypted) first */ + snprintf(url, sizeof url, "pop3s://%s", host); + curl_easy_setopt(curl, CURLOPT_URL, url); + res = curl_easy_perform(curl); + if (res == CURLE_OK) { + is_pop3s = 1; + } else { + syslog(LOG_DEBUG, "POP3S client failed: %s , trying POP3 next", curl_easy_strerror(res)); + snprintf(url, sizeof url, "pop3://%s", host); // try unencrypted next + curl_easy_setopt(curl, CURLOPT_URL, url); + res = curl_easy_perform(curl); + } + + if (res != CURLE_OK) { + syslog(LOG_DEBUG, "pop3 client failed: %s", curl_easy_strerror(res)); + curl_easy_cleanup(curl); + return; + } + + // FIXME finish this + + curl_easy_cleanup(curl); + return; } -- 2.30.2