-/*
- * 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"
#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];
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<num_sahosts; ++sa) {
extract_token(buf, sahosts, sa, '|', sizeof buf);
syslog(LOG_INFO, "Connecting to SpamAssassin at <%s>\n", buf);
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;
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;
CM_PrependToField(msg, eMesageText, buf, headerlen);
- } else {
+ }
+ else {
syslog(LOG_DEBUG, "reject spam code used");
if (!strncasecmp(buf, "Spam: True", 10)) {
is_spam = 1;
}
bail: close(sock);
- FreeStrBuf(&CCC->SBuf.Buf);
- FreeStrBuf(&CCC->sMigrateBuf);
+ FreeStrBuf(&CC->SBuf.Buf);
+ FreeStrBuf(&CC->sMigrateBuf);
return(is_spam);
}
CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN);
}
- /* return our module name for the log */
+ // return our module name for the log
return "spam";
}