X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtpclient.c;h=e528015eb4202fa72e6f2bd50bcd071137bc6ec5;hb=882ff5a53c3b4e440520a073cf07dc60b2671876;hp=b8081fa2c396369514685f9f3c280fa80a9dc9e7;hpb=78a4a16e111b8d56d72ff2714995282ddb8728e0;p=citadel.git diff --git a/citadel/modules/smtp/serv_smtpclient.c b/citadel/modules/smtp/serv_smtpclient.c index b8081fa2c..e528015eb 100644 --- a/citadel/modules/smtp/serv_smtpclient.c +++ b/citadel/modules/smtp/serv_smtpclient.c @@ -3,7 +3,7 @@ * * This is the new, exciting, clever version that makes libcurl do all the work :) * - * Copyright (c) 1997-2018 by the citadel.org team + * Copyright (c) 1997-2020 by the citadel.org team * * This program is open source software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published @@ -20,18 +20,7 @@ #include #include #include - -#if TIME_WITH_SYS_TIME -#include -#include -#else -#if HAVE_SYS_TIME_H -#include -#else #include -#endif -#endif - #include #include #include @@ -58,7 +47,6 @@ struct smtpmsgsrc { // Data passed in and out of libcurl for message upload int bytes_sent; }; -struct CitContext smtp_client_CC; static int doing_smtpclient = 0; long *smtpq = NULL; // array of msgnums containing queue instructions int smtpq_count = 0; // number of queue messages in smtpq @@ -94,7 +82,7 @@ void smtp_init_spoolout(void) * not happen because the delivery instructions message does not * contain a recipient. */ -int smtp_aftersave(struct CtdlMessage *msg, recptypes * recps) +int smtp_aftersave(struct CtdlMessage *msg, struct recptypes *recps) { if ((recps != NULL) && (recps->num_internet > 0)) { struct CtdlMessage *imsg = NULL; @@ -142,7 +130,7 @@ int smtp_aftersave(struct CtdlMessage *msg, recptypes * recps) CM_SetField(imsg, eAuthor, HKEY("Citadel")); CM_SetField(imsg, eJournal, HKEY("do not journal")); CM_SetAsFieldSB(imsg, eMesageText, &SpoolMsg); - CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR); + CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM); CM_Free(imsg); } return 0; @@ -182,7 +170,7 @@ static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp) * by the remote server. This is an ugly way to extract it, by capturing debug data from * the library and filtering on the lines we want. */ -int ctdl_libcurl_smtp_debug_callback(CURL * handle, curl_infotype type, char *data, size_t size, void *userptr) +int ctdl_libcurl_smtp_debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) { if (type != CURLINFO_HEADER_IN) return 0; @@ -200,6 +188,44 @@ int ctdl_libcurl_smtp_debug_callback(CURL * handle, curl_infotype type, char *da } +/* + * Go through the debug output of an SMTP transaction, and boil it down to just the final success or error response message. + */ +void trim_response(long response_code, char *response) +{ + if ((response_code < 100) || (response_code > 999) || (IsEmptyStr(response))) { + return; + } + + char *t = malloc(strlen(response)); + if (!t) { + return; + } + t[0] = 0; + + char *p; + for (p = response; *p != 0; ++p) { + if ( (*p != '\n') && (!isprint(*p)) ) { // expunge any nonprintables except for newlines + *p = ' '; + } + } + + char response_code_str[4]; + snprintf(response_code_str, sizeof response_code_str, "%ld", response_code); + char *respstart = strstr(response, response_code_str); + if (respstart == NULL) { + strcpy(response, smtpstatus(response_code)); + return; + } + strcpy(response, respstart); + + p = strstr(response, "\n"); + if (p != NULL) { + *p = 0; + } +} + + /* * Attempt a delivery to one recipient. * Returns a three-digit SMTP status code. @@ -297,23 +323,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res curl = NULL; // this gets reused; avoid double-free /* Trim the error message buffer down to just the actual message */ - char response_code_str[4]; - snprintf(response_code_str, sizeof response_code_str, "%ld", response_code); - char *respstart = strstr(response, response_code_str); - if (respstart == NULL) { - strcpy(response, smtpstatus(response_code)); - } else { - strcpy(response, respstart); - char *p; - for (p = response; *p != 0; ++p) { - if (*p == '\n') - *p = ' '; - if (*p == '\r') - *p = ' '; - if (!isprint(*p)) - *p = ' '; - } - } + trim_response(response_code, response); } } @@ -339,7 +349,7 @@ void smtp_process_one_msg(long qmsgnum) int delete_this_queue = 0; char server_response[SIZ]; - msg = CtdlFetchMessage(qmsgnum, 1, 1); + msg = CtdlFetchMessage(qmsgnum, 1); if (msg == NULL) { syslog(LOG_WARNING, "smtpclient: %ld does not exist", qmsgnum); return; @@ -478,7 +488,7 @@ void smtp_process_one_msg(long qmsgnum) // replace the old queue entry with the new one syslog(LOG_DEBUG, "smtpclient: %ld rewriting", qmsgnum); msg = convert_internet_message_buf(&NewInstr); // This function will free NewInstr for us - CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, 0); + CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM); CM_Free(msg); CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &qmsgnum, 1, ""); } @@ -533,7 +543,6 @@ void smtp_do_queue(void) doing_smtpclient = 1; syslog(LOG_DEBUG, "smtpclient: start queue run"); - pthread_setspecific(MyConKey, (void *) &smtp_client_CC); if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) { syslog(LOG_WARNING, "Cannot find room <%s>", SMTP_SPOOLOUT_ROOM); @@ -560,7 +569,6 @@ void smtp_do_queue(void) CTDL_MODULE_INIT(smtpclient) { if (!threading) { - CtdlFillSystemContext(&smtp_client_CC, "SMTP_Send"); CtdlRegisterMessageHook(smtp_aftersave, EVT_AFTERSAVE); CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 50); smtp_init_spoolout();