X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtpclient.c;h=8e87ce4c2f4da626569a4842c602db51aaf7af51;hb=51b18018ff923284d76a36cbd421d62abf6afcf4;hp=1b7595df0a7b9648db883e3df810af39cf700dcb;hpb=c71df26b9d35c07eb9c1322a7e83caa86337ad82;p=citadel.git diff --git a/citadel/modules/smtp/serv_smtpclient.c b/citadel/modules/smtp/serv_smtpclient.c index 1b7595df0..8e87ce4c2 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-2021 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 @@ -67,8 +56,7 @@ int smtpq_alloc = 0; // current allocation size for smtpq /* * Initialize the SMTP outbound queue */ -void smtp_init_spoolout(void) -{ +void smtp_init_spoolout(void) { struct ctdlroom qrbuf; /* @@ -93,8 +81,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; char recipient[SIZ]; @@ -141,7 +128,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; @@ -151,8 +138,7 @@ int smtp_aftersave(struct CtdlMessage *msg, recptypes * recps) /* * Callback for smtp_attempt_delivery() to supply libcurl with upload data. */ -static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp) -{ +static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp) { struct smtpmsgsrc *s = (struct smtpmsgsrc *) userp; int sendbytes = 0; const char *send_this = NULL; @@ -181,8 +167,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; if (!userptr) @@ -202,8 +187,7 @@ int ctdl_libcurl_smtp_debug_callback(CURL *handle, curl_infotype type, char *dat /* * 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) -{ +void trim_response(long response_code, char *response) { if ((response_code < 100) || (response_code > 999) || (IsEmptyStr(response))) { return; } @@ -224,8 +208,8 @@ void trim_response(long response_code, char *response) 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)); + if (respstart == NULL) { // If we have a response code but no response text, + strcpy(response, smtpstatus(response_code)); // use one of our canned messages. return; } strcpy(response, respstart); @@ -241,8 +225,7 @@ void trim_response(long response_code, char *response) * Attempt a delivery to one recipient. * Returns a three-digit SMTP status code. */ -int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *response) -{ +int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *response) { struct smtpmsgsrc s; char *fromaddr = NULL; CURL *curl; @@ -317,7 +300,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res 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 + syslog(LOG_DEBUG, "smtpclient: trying MX %d of %d <%s>", i+1, num_mx, smtp_url); // send the message res = curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); syslog(LOG_DEBUG, @@ -348,8 +331,7 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res /* * Process one outbound message. */ -void smtp_process_one_msg(long qmsgnum) -{ +void smtp_process_one_msg(long qmsgnum) { struct CtdlMessage *msg = NULL; char *instr = NULL; int i; @@ -360,7 +342,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; @@ -417,7 +399,7 @@ void smtp_process_one_msg(long qmsgnum) } if (should_try_now) { - syslog(LOG_DEBUG, "smtpclient: %ld attempting delivery now", qmsgnum); + syslog(LOG_DEBUG, "smtpclient: attempting delivery of message <%ld> now", qmsgnum); StrBuf *NewInstr = NewStrBuf(); StrBufAppendPrintf(NewInstr, "Content-type: " SPOOLMIME "\n\n"); StrBufAppendPrintf(NewInstr, "msgid|%ld\n", msgid); @@ -499,7 +481,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, ""); } @@ -518,8 +500,7 @@ void smtp_process_one_msg(long qmsgnum) /* * Callback for smtp_do_queue() */ -void smtp_add_msg(long msgnum, void *userdata) -{ +void smtp_add_msg(long msgnum, void *userdata) { if (smtpq == NULL) { smtpq_count = 0; @@ -539,8 +520,7 @@ void smtp_add_msg(long msgnum, void *userdata) /* * Run through the queue sending out messages. */ -void smtp_do_queue(void) -{ +void smtp_do_queue(void) { int i = 0; /* @@ -581,7 +561,7 @@ CTDL_MODULE_INIT(smtpclient) { if (!threading) { CtdlRegisterMessageHook(smtp_aftersave, EVT_AFTERSAVE); - CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 50); + CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 51); smtp_init_spoolout(); }