]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - spamass-milter.h
c11b631669c6dc01e5f82b20205df07af64564e9
[deb_pkgs/spamass-milter.git] / spamass-milter.h
1 //-*-c++-*-
2 //
3 //  $Id: spamass-milter.h,v 1.22 2004/09/21 20:51:06 dnelson Exp $
4 //
5 //  Main include file for SpamAss-Milter
6 //
7 //  Copyright (c) 2002 Georg C. F. Greve <greve@gnu.org>,
8 //   all rights maintained by FSF Europe e.V., 
9 //   Villa Vogelsang, Antonienallee 1, 45279 Essen, Germany
10 //
11 //   This program is free software; you can redistribute it and/or modify
12 //   it under the terms of the GNU General Public License as published by
13 //   the Free Software Foundation; either version 2 of the License, or
14 //   (at your option) any later version.
15 //  
16 //   This program is distributed in the hope that it will be useful,
17 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 //   GNU General Public License for more details.
20 //  
21 //   You should have received a copy of the GNU General Public License
22 //   along with this program; if not, write to the Free Software
23 //   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 //
25 //   Contact:
26 //            Michael Brown <michaelb@opentext.com>
27 //
28 #ifndef _SPAMASS_MILTER_H
29 #define _SPAMASS_MILTER_H
30
31 #ifdef HAVE_CDEFS_H
32 #include <sys/cdefs.h>
33 #endif
34 #if !defined(__printflike)
35 #define __printflike(a,b)
36 #endif
37
38 #include <list>
39
40 using namespace std;
41
42 string retrieve_field(const string&, const string&);
43
44 sfsistat mlfi_connect(SMFICTX*, char*, _SOCK_ADDR*);
45 sfsistat mlfi_helo(SMFICTX*, char*);
46 sfsistat mlfi_envrcpt(SMFICTX*, char**);
47 sfsistat mlfi_envfrom(SMFICTX*, char**);
48 sfsistat mlfi_header(SMFICTX*, char*, char*);
49 sfsistat mlfi_eoh(SMFICTX*);
50 sfsistat mlfi_body(SMFICTX*, u_char *, size_t);
51 sfsistat mlfi_eom(SMFICTX*);
52 sfsistat mlfi_close(SMFICTX*);
53 sfsistat mlfi_abort(SMFICTX*);
54 sfsistat mlfi_abort(SMFICTX*);
55
56 extern struct smfiDesc smfilter;
57
58 /* struct describing a single network */
59 struct net
60 {
61         struct in_addr network;
62         struct in_addr netmask;
63 };
64
65 /* an array of networks */
66 struct networklist
67 {
68         struct net *nets;
69         int num_nets;
70 };
71
72
73 // Debug tokens.
74 enum debuglevel 
75 {
76         D_ALWAYS, D_FUNC, D_POLL, D_UORI, D_STR, D_MISC, D_NET, D_SPAMC, D_RCPT,
77         D_COPY,
78         D_MAX // must be last
79 };
80
81 class SpamAssassin {
82 public:
83   SpamAssassin();
84   ~SpamAssassin();
85
86   void Connect();
87   void output(const void*, long);
88   void output(const void*);
89   void output(string);
90   void close_output();
91   void input();
92
93   string& d();
94
95   string& spam_status();
96   string& spam_flag();
97   string& spam_report();
98   string& spam_prev_content_type();
99   string& spam_checker_version();
100   string& spam_level();
101   string& content_type();
102   string& subject();
103   string& rcpt();               /* first RCPT TO: recipient (raw) */
104   string& from();               /* MAIL FROM: sender (raw) */
105   string& connectip();  /* IP of sending machine */
106   string  local_user(); /* username part of first expanded recipient */
107   string  full_user();  /* full first expanded recipient */
108   int     numrcpt();    /* total RCPT TO: recpients */
109   int     set_numrcpt();        /* increment total RCPT count */
110   int     set_numrcpt(const int);       /* set total RCPT count to n */
111   string::size_type set_spam_status(const string&);
112   string::size_type set_spam_flag(const string&);
113   string::size_type set_spam_report(const string&);
114   string::size_type set_spam_prev_content_type(const string&);
115   string::size_type set_spam_checker_version(const string&);
116   string::size_type set_spam_level(const string&);
117   string::size_type set_content_type(const string&);
118   string::size_type set_subject(const string&);
119   string::size_type set_rcpt(const string&);
120   string::size_type set_from(const string&);
121   string::size_type set_connectip(const string&);
122
123 private:
124   void empty_and_close_pipe();
125   int read_pipe();
126
127 public:  
128   // flags
129   bool error;
130   bool running;         /* XXX merge running, connected, and pid */
131   bool connected;       /* are we connected to spamc? */
132
133   // This is where we store the mail after it
134   // was piped through SpamAssassin
135   string mail;
136
137   // Data written via output() but before Connect() is stored here
138   string outputbuffer;
139
140   // Variables for SpamAssassin influenced fields
141   string x_spam_status, x_spam_flag, x_spam_report, x_spam_prev_content_type;
142   string x_spam_checker_version, x_spam_level, _content_type, _subject;
143   
144   // Envelope info: MAIL FROM:, RCPT TO:, and IP address of remote host
145   // _rcpt only holds the first recipient if there are more than one
146   string _from, _rcpt, _connectip;
147   
148   // Counter to keep track of the number of recipients
149   int    _numrcpt;
150
151   // The list of recipients for the current message
152   list <string> recipients;
153
154   // List of recipients after alias/virtusertable expansion
155   list <string> expandedrcpt;
156
157   // the sendmail queue id for this message; used for logging
158   string queueid;
159
160   // Process handling variables
161   pid_t pid;
162   int pipe_io[2][2];
163 };
164   
165 /* Private data structure to carry per-client data between calls */
166 struct context
167 {
168         struct in_addr connect_ip;      // remote IP address
169         char *helo;
170         SpamAssassin *assassin; // pointer to the SA object if we're processing a message
171 };
172
173 /* This hack is the only way to call pointers to member functions! */
174 typedef string::size_type (SpamAssassin::*t_setter)(const string &val);
175 #define callsetter(object, ptrToMember)  ((object).*(ptrToMember))
176        
177 int assassinate(SMFICTX*, SpamAssassin*);
178
179 void throw_error(const string&);
180 void debug(enum debuglevel, const char* fmt, ...) __printflike(2, 3);
181 string::size_type find_nocase(const string&, const string&, string::size_type = 0);
182 int cmp_nocase_partial(const string&, const string&);
183 void closeall(int fd);
184 void parse_networklist(char *string, struct networklist *list);
185 int ip_in_networklist(struct in_addr ip, struct networklist *list);
186 void parse_debuglevel(char* string);
187 char *strlwr(char *str);
188
189 #endif