Removed debug output.
[gnucomo.git] / src / gcm_input / spamdetect.cpp
1 /**************************************************************************
2 **  (c) Copyright 2007, Andromeda Technology & Automation
3 ** This is free software; you can redistribute it and/or modify it under the
4 ** terms of the GNU General Public License, see the file COPYING.
5 ***************************************************************************
6 ** MODULE INFORMATION *
7 ***********************
8 **      FILE NAME      : spamdetect.cpp
9 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
10 **      VERSION NUMBER : $Revision: 1.2 $
11 **
12 **  DESCRIPTION      :  
13 **
14 **  EXPORTED OBJECTS : 
15 **  LOCAL    OBJECTS : 
16 **  MODULES  USED    :
17 ***************************************************************************
18 **  ADMINISTRATIVE INFORMATION *
19 ********************************
20 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
21 **      CREATION DATE   : Nov 14, 2007
22 **      LAST UPDATE     : Nov Nov 14, 2007
23 **      MODIFICATIONS   : 
24 **************************************************************************/
25
26 /*****************************
27    $Log: spamdetect.cpp,v $
28    Revision 1.2  2007-11-21 15:14:26  arjen
29    Removed debug output.
30
31    Revision 1.1  2007/11/14 16:20:05  arjen
32    New program: spamdetect.
33    Expirimental utility to log manually reported spam and have
34    Gnucomo detect the spammer's IP address.
35
36 *****************************/
37
38 static const char *RCSID = "$Id: spamdetect.cpp,v 1.2 2007-11-21 15:14:26 arjen Exp $";
39
40 #include <fstream>
41 #include <AXE/String.h>
42
43 #include <syslog.h>
44 #include <getopt.h>
45
46 int main(int argc, char *argv[])
47 {
48    const char *usage = "Usage: spamdetect\n";
49
50    String line;
51    String header;
52    int    state = 0;
53
54    regex fwd_header("---- Original Message -----");
55    regex received("^Received:");
56    regex from("^From:");
57    regex returnpath("^Return-Path:");
58
59    openlog("gnucomo", 0, LOG_MAIL);
60
61
62    while (std::cin >> line)
63    {
64       switch (state)
65       {
66       case 0:
67          if (line == fwd_header)
68          {
69             state = 1;
70          }
71          break;
72
73       case 1:
74          //  Inside the forwarded header
75          if (line == received || line == from || line == returnpath)
76          {
77             header = line;
78             state = 2;
79          }
80          break;
81       case 2:
82          if (line == regex("^[^ ]+: "))
83          {
84             syslog(LOG_WARNING, "%s", (char *)header);
85             header = "";
86             state = 1;
87             if (line == received || line == from || line == returnpath)
88             {
89                header = line;
90                state = 2;
91             }
92          }
93          else if (line == String(""))
94          {
95             state = 3;
96          }
97          else
98          {
99             header += " ";
100             header += line;
101          }
102       }
103    }
104
105    closelog();
106 }
107