]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - spamass-milter.h
Imported Upstream version 0.4.0
[deb_pkgs/spamass-milter.git] / spamass-milter.h
1 //-*-c++-*-
2 //
3 //  $Id: spamass-milter.h,v 1.28 2014/08/15 01:51:19 kovert 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 union net
60 {
61         struct
62         {
63                 uint8_t af;
64         } net;
65         struct
66         {
67                 uint8_t af;
68                 struct in_addr network;
69                 struct in_addr netmask;
70         } net4;
71         struct
72         {
73                 uint8_t af;
74                 struct in6_addr network;
75                 int netmask; /* Just the number of bits for IPv6 */
76         } net6;
77 };
78
79 /* an array of networks */
80 struct networklist
81 {
82         union net *nets;
83         int num_nets;
84 };
85
86
87 // Debug tokens.
88 enum debuglevel 
89 {
90         D_ALWAYS, D_FUNC, D_POLL, D_UORI, D_STR, D_MISC, D_NET, D_SPAMC, D_RCPT,
91         D_COPY,
92         D_MAX // must be last
93 };
94
95 class SpamAssassin {
96 public:
97   SpamAssassin();
98   ~SpamAssassin();
99
100   void Connect();
101   void output(const void*, long);
102   void output(const void*);
103   void output(string);
104   void close_output();
105   void input();
106
107   string& d();
108
109   string& spam_status();
110   string& spam_flag();
111   string& spam_report();
112   string& spam_prev_content_type();
113   string& spam_checker_version();
114   string& spam_level();
115   string& content_type();
116   string& subject();
117   string& rcpt();               /* first RCPT TO: recipient (raw) */
118   string& from();               /* MAIL FROM: sender (raw) */
119   string& connectip();  /* IP of sending machine */
120   string  local_user(); /* username part of first expanded recipient */
121   string  full_user();  /* full first expanded recipient */
122   int     numrcpt();    /* total RCPT TO: recpients */
123   int     set_numrcpt();        /* increment total RCPT count */
124   int     set_numrcpt(const int);       /* set total RCPT count to n */
125   string::size_type set_spam_status(const string&);
126   string::size_type set_spam_flag(const string&);
127   string::size_type set_spam_report(const string&);
128   string::size_type set_spam_prev_content_type(const string&);
129   string::size_type set_spam_checker_version(const string&);
130   string::size_type set_spam_level(const string&);
131   string::size_type set_content_type(const string&);
132   string::size_type set_subject(const string&);
133   string::size_type set_rcpt(const string&);
134   string::size_type set_from(const string&);
135   string::size_type set_connectip(const string&);
136
137 private:
138   void empty_and_close_pipe();
139   int read_pipe();
140
141 public:  
142   // flags
143   bool error;
144   bool running;         /* XXX merge running, connected, and pid */
145   bool connected;       /* are we connected to spamc? */
146
147   // This is where we store the mail after it
148   // was piped through SpamAssassin
149   string mail;
150
151   // Data written via output() but before Connect() is stored here
152   string outputbuffer;
153
154   // Variables for SpamAssassin influenced fields
155   string x_spam_status, x_spam_flag, x_spam_report, x_spam_prev_content_type;
156   string x_spam_checker_version, x_spam_level, _content_type, _subject;
157   
158   // Envelope info: MAIL FROM:, RCPT TO:, and IP address of remote host
159   // _rcpt only holds the first recipient if there are more than one
160   string _from, _rcpt, _connectip;
161   
162   // Counter to keep track of the number of recipients
163   int    _numrcpt;
164
165   // The list of recipients for the current message
166   list <string> recipients;
167
168   // List of recipients after alias/virtusertable expansion
169   list <string> expandedrcpt;
170
171   // the sendmail queue id for this message; used for logging
172   string queueid;
173
174   // Process handling variables
175   pid_t pid;
176   int pipe_io[2][2];
177 };
178   
179 /* Private data structure to carry per-client data between calls */
180 struct context
181 {
182         char connect_ip[64];    // remote IP address
183         char *helo;
184         SpamAssassin *assassin; // pointer to the SA object if we're processing a message
185 };
186
187 /* This hack is the only way to call pointers to member functions! */
188 typedef string::size_type (SpamAssassin::*t_setter)(const string &val);
189 #define callsetter(object, ptrToMember)  ((object).*(ptrToMember))
190        
191 int assassinate(SMFICTX*, SpamAssassin*);
192
193 void throw_error(const string&);
194 void debug(enum debuglevel, const char* fmt, ...) __printflike(2, 3);
195 string::size_type find_nocase(const string&, const string&, string::size_type = 0);
196 int cmp_nocase_partial(const string&, const string&);
197 void closeall(int fd);
198 void parse_networklist(char *string, struct networklist *list);
199 int ip_in_networklist(struct sockaddr *addr, struct networklist *list);
200 void parse_debuglevel(char* string);
201 char *strlwr(char *str);
202 void warnmacro(const char *macro, const char *scope);
203 FILE *popenv(char *const argv[], const char *type, pid_t *pid);
204
205 #endif