From ba193b9c4767b3d1a1cafd4483d29fb5f5748ff5 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 15 Dec 2022 13:42:07 -0500 Subject: [PATCH] modernize serv_spam.c --- citadel/server/modules/spam/serv_spam.c | 70 +++++++++---------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/citadel/server/modules/spam/serv_spam.c b/citadel/server/modules/spam/serv_spam.c index 0a576a37b..76a422d85 100644 --- a/citadel/server/modules/spam/serv_spam.c +++ b/citadel/server/modules/spam/serv_spam.c @@ -1,19 +1,9 @@ -/* - * This module allows Citadel to use SpamAssassin to filter incoming messages - * arriving via SMTP. For more information on SpamAssassin, visit - * http://www.spamassassin.org (the SpamAssassin project is not in any way - * affiliated with the Citadel project). - * - * Copyright (c) 1998-2022 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 version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ +// This module allows Citadel to use an external SpamAssassin service to filter incoming messages arriving via SMTP. +// +// Copyright (c) 1998-2022 by the citadel.org team +// +// This program is open source software. Use, duplication, or disclosure +// is subject to the terms of the GNU General Public License, version 3. #define SPAMASSASSIN_PORT "783" @@ -44,15 +34,10 @@ #include "../../internet_addressing.h" #include "../../domain.h" #include "../../clientsocket.h" - - #include "../../ctdl_module.h" - -/* - * Connect to the SpamAssassin server and scan a message. - */ +// Connect to the SpamAssassin server and scan a message. int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { int sock = (-1); char sahosts[SIZ]; @@ -61,18 +46,16 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { int is_spam = 0; int sa; StrBuf *msgtext; - CitContext *CCC=CC; - /* For users who have authenticated to this server we never want to - * apply spam filtering, because presumably they're trustworthy. - */ + // For users who have authenticated to this server we never want to + // apply spam filtering, because presumably they're trustworthy. if (CC->logged_in) return(0); - /* See if we have any SpamAssassin hosts configured */ + // See if we have any SpamAssassin hosts configured num_sahosts = get_hosts(sahosts, "spamassassin"); if (num_sahosts < 1) return(0); - /* Try them one by one until we get a working one */ + // Try them one by one until we get a working one for (sa=0; sa\n", buf); @@ -80,24 +63,22 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { if (sock >= 0) syslog(LOG_DEBUG, "Connected!\n"); } + // If the service isn't running, just pass the mail through. Potentially throwing away mails isn't good. if (sock < 0) { - /* If the service isn't running, just pass the mail - * through. Potentially throwing away mails isn't good. - */ return(0); } - CCC->SBuf.Buf = NewStrBuf(); - CCC->sMigrateBuf = NewStrBuf(); - CCC->SBuf.ReadWritePointer = NULL; + CC->SBuf.Buf = NewStrBuf(); + CC->sMigrateBuf = NewStrBuf(); + CC->SBuf.ReadWritePointer = NULL; - /* Command */ + // Command syslog(LOG_DEBUG, "Transmitting command\n"); sprintf(buf, "CHECK SPAMC/1.2\r\n\r\n"); sock_write(&sock, buf, strlen(buf)); - /* Message */ - CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ); + // Message + CC->redirect_buffer = NewStrBufPlain(NULL, SIZ); CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, 0); msgtext = CC->redirect_buffer; CC->redirect_buffer = NULL; @@ -105,13 +86,11 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { sock_write(&sock, SKEY(msgtext)); FreeStrBuf(&msgtext); - /* Close one end of the socket connection; this tells SpamAssassin - * that we're done. - */ + // Close one end of the socket connection; this tells SpamAssassin that we're done. if (sock != -1) sock_shutdown(sock, SHUT_WR); - /* Response */ + // Response syslog(LOG_DEBUG, "Awaiting response\n"); if (sock_getln(&sock, buf, sizeof buf) < 0) { goto bail; @@ -152,7 +131,8 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { CM_PrependToField(msg, eMesageText, buf, headerlen); - } else { + } + else { syslog(LOG_DEBUG, "reject spam code used"); if (!strncasecmp(buf, "Spam: True", 10)) { is_spam = 1; @@ -164,8 +144,8 @@ int spam_assassin(struct CtdlMessage *msg, struct recptypes *recp) { } bail: close(sock); - FreeStrBuf(&CCC->SBuf.Buf); - FreeStrBuf(&CCC->sMigrateBuf); + FreeStrBuf(&CC->SBuf.Buf); + FreeStrBuf(&CC->sMigrateBuf); return(is_spam); } @@ -176,6 +156,6 @@ char *ctdl_module_init_spam(void) { CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN); } - /* return our module name for the log */ + // return our module name for the log return "spam"; } -- 2.39.2