--- /dev/null
+/**************************************************************************
+** (c) Copyright 2007, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+** FILE NAME : spamdetect.cpp
+** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
+** VERSION NUMBER : $Revision: 1.2 $
+**
+** DESCRIPTION :
+**
+** EXPORTED OBJECTS :
+** LOCAL OBJECTS :
+** MODULES USED :
+***************************************************************************
+** ADMINISTRATIVE INFORMATION *
+********************************
+** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+** CREATION DATE : Nov 14, 2007
+** LAST UPDATE : Nov Nov 14, 2007
+** MODIFICATIONS :
+**************************************************************************/
+
+/*****************************
+ $Log: spamdetect.cpp,v $
+ Revision 1.2 2007-11-21 15:14:26 arjen
+ Removed debug output.
+
+ Revision 1.1 2007/11/14 16:20:05 arjen
+ New program: spamdetect.
+ Expirimental utility to log manually reported spam and have
+ Gnucomo detect the spammer's IP address.
+
+*****************************/
+
+static const char *RCSID = "$Id: spamdetect.cpp,v 1.2 2007-11-21 15:14:26 arjen Exp $";
+
+#include <fstream>
+#include <String.h>
+
+#include <syslog.h>
+#include <getopt.h>
+
+int main(int argc, char *argv[])
+{
+ const char *usage = "Usage: spamdetect\n";
+
+ String line;
+ String header;
+ int state = 0;
+
+ // From here, the original spam starts. Something like
+ // -------- Forwarded Message -------- or -------- Original Message --------
+
+ regex fwd_header("---- .+ Message -----");
+ regex received("^Received:");
+ regex from("^From:");
+ regex subject("^Subject:");
+ regex returnpath("^Return-Path:");
+
+ openlog("gnucomo", 0, LOG_MAIL);
+
+
+ while (std::cin >> line)
+ {
+ //std::cout << "[" << state << "] checking " << line << "\n"; // DEBUG
+ switch (state)
+ {
+ case 0:
+ if (line == fwd_header)
+ {
+ state = 1;
+ }
+ break;
+
+ case 1:
+ // Inside the forwarded header
+ if (line == received || line == from || line == returnpath || line == subject)
+ {
+ header = line;
+ state = 2;
+ }
+ break;
+ case 2:
+ if (line == regex("^[^ ]+: "))
+ {
+ //std::cout << "Header: " << header << "\n"; // DEBUG
+ syslog(LOG_WARNING, "%s", (char *)header);
+
+ header = line;
+ }
+ else if (line == String(""))
+ {
+ state = 3;
+ }
+ else
+ {
+ header += " ";
+ header += line;
+ }
+ }
+ }
+
+ closelog();
+}
+