X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtpclient.c;h=937367943e446fd65e3ea607ac899371132e983f;hb=44c9169c5f2c048cc9a7a35d562b6518e340fc8f;hp=48c761dc4e84883b76b9e80e0548c97ea08d9daa;hpb=684e3a06c4d2ab35e39760f328a0d354ad330622;p=citadel.git diff --git a/citadel/modules/smtp/serv_smtpclient.c b/citadel/modules/smtp/serv_smtpclient.c index 48c761dc4..937367943 100644 --- a/citadel/modules/smtp/serv_smtpclient.c +++ b/citadel/modules/smtp/serv_smtpclient.c @@ -79,7 +79,7 @@ void smtp_init_spoolout(void) { /* * Make sure it's set to be a "system room" so it doesn't show up - * in the nown rooms list for Aides. + * in the nown rooms list for administrators. */ if (CtdlGetRoomLock(&qrbuf, SMTP_SPOOLOUT_ROOM) == 0) { qrbuf.QRflags2 |= QR2_SYSTEM; @@ -198,6 +198,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from) char node[1024]; char name[1024]; char try_this_mx[256]; + char smtp_url[512]; int i; syslog(LOG_DEBUG, "smtpclient: smtp_attempt_delivery(%ld, %s)", msgid, recp); @@ -236,22 +237,27 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from) curl_easy_setopt(curl, CURLOPT_READDATA, &s); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); // tell libcurl we are uploading curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L); // Time out after 20 seconds + if (CtdlGetConfigInt("c_smtpclient_try_starttls") != 0) { + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); // Attempt STARTTLS if offered + } curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - - strcpy(try_this_mx, "smtp://"); - extract_token(&try_this_mx[7], mxes, i, '|', (sizeof try_this_mx - 7)); - if ( - (!strncasecmp(try_this_mx, HKEY("smtp://smtp://"))) // This can happen if the administrator - || (!strncasecmp(try_this_mx, HKEY("smtp://smtps://"))) // puts a full smtp[s] URI as the smart-host - ) { - strcpy(try_this_mx, &try_this_mx[7]); - } - - - curl_easy_setopt(curl, CURLOPT_URL, try_this_mx); - - syslog(LOG_DEBUG, "smtpclient: trying %s", try_this_mx); // send the message + // curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer); + + // Construct an SMTP URL in the form of: + // smtp[s]://target_host/source_host + // This looks weird but libcurl uses that last part to set our name for EHLO or HELO. + // We check for "smtp://" and "smtps://" because the admin may have put those prefixes in a smart-host entry. + // If there is no prefix we add "smtp://" + extract_token(try_this_mx, mxes, i, '|', (sizeof try_this_mx - 7)); + snprintf(smtp_url, sizeof smtp_url, + "%s%s/%s", + (((!strncasecmp(try_this_mx, HKEY("smtp://"))) || (!strncasecmp(try_this_mx, HKEY("smtps://")))) ? "" : "smtp://"), + try_this_mx, + CtdlGetConfigStr("c_fqdn") + ); + curl_easy_setopt(curl, CURLOPT_URL, smtp_url); + syslog(LOG_DEBUG, "smtpclient: trying %s", smtp_url); // send the message res = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); syslog(LOG_DEBUG, "smtpclient: libcurl returned %d (%s) , SMTP response %ld", @@ -262,8 +268,10 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from) response_code = 421; } - curl_slist_free_all(recipients); - curl_easy_cleanup(curl); + curl_slist_free_all(recipients); + recipients = NULL; // this gets reused; avoid double-free + curl_easy_cleanup(curl); + curl = NULL; // this gets reused; avoid double-free } } @@ -287,11 +295,9 @@ void smtp_process_one_msg(long qmsgnum) long deletes[2]; int delete_this_queue = 0; - syslog(LOG_DEBUG, "smtpclient: smtp_process_one_msg(%ld)", qmsgnum); - msg = CtdlFetchMessage(qmsgnum, 1, 1); if (msg == NULL) { - syslog(LOG_WARNING, "smtpclient: queue message %ld does not exist", qmsgnum); + syslog(LOG_WARNING, "smtpclient: %ld does not exist", qmsgnum); return; } @@ -317,16 +323,6 @@ void smtp_process_one_msg(long qmsgnum) char *bounceto = NULL; char *envelope_from = NULL; - // Example queue instructions - // - // msgid|3978 - // submitted|1489343934 - // bounceto|IGnatius T Foobar@dev - // attempted|1489344257 - // remote|unreachable@example.com|4|Timeout while connecting example.com [93.184.216.34]:25 - // remote|unreachable@example.org|4|Timeout while connecting example.org [93.184.216.34]:25 - // remote|unreachable@example.gov|0|1) A-lookup example.gov - Domain name not found; 2) AAAA-lookup example.gov - Domain name not found; - char cfgline[SIZ]; for (i=0; i