2
* Copyright (C) 2002 Laird Breyer
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
* Author: Laird Breyer <laird@lbreyer.com>
26
#if defined HAVE_LANGINFO_H
29
/* on OpenBSD, CODESET doesn't seem to be defined -
30
we use 3, which should be US-ASCII, but it's not ideal... */
42
#if defined HAVE_UNISTD_H
50
extern HEADER_State head;
53
extern charbuf_len_t textbuf_len;
55
extern options_t u_options;
57
extern char *progname;
58
extern char *inputfile;
59
extern long inputline;
62
extern long system_pagesize;
64
int exit_code = 0; /* default */
66
/***********************************************************
68
***********************************************************/
69
void print_summary() {
71
/* time_t numsec = (time_t)-1; */
72
/* for(i = 0; i < head.hstack.top; i++) { */
73
/* if( head.hstack.hlines[i].tag == hltRCV ) { */
74
/* if( head.hstack.hlines[i].state & (1<<H_STATE_BAD_DATA) ) { */
77
/* if( numsec == (time_t)-1 ) { */
78
/* numsec = head.hstack.hlines[i].data.rcv.numsec; */
80
/* printf("%ld ", head.hstack.hlines[i].data.rcv.numsec - numsec); */
81
/* numsec = head.hstack.hlines[i].data.rcv.numsec; */
87
printf("I have nothing to say.\n");
91
/***********************************************************
93
***********************************************************/
95
static void usage(char **argv) {
99
"hmine [-vD] [FILE]\n");
103
" checks FILE or STDIN for RFC822 header forgery.\n");
111
" prints program version.\n");
114
int hset_option(int op, char *optarg) {
118
u_options |= (1<<U_OPTION_DEBUG);
121
fprintf(stdout, "hmine version %s\n", VERSION);
122
fprintf(stdout, COPYBLURB, "hmine");
133
void hprocess_file(FILE *input, HEADER_State *head) {
134
char *pptextbuf = NULL;
135
bool_t in_header = 1;
139
set_iobuf_mode(input);
142
/* now start processing */
143
while( fill_textbuf(input, &extra_lines) ) {
146
if( u_options & (1<<U_OPTION_FILTER) ) {
147
fprintf(stdout, "%s", textbuf);
151
if( (textbuf[0] == '\0') ||
152
(textbuf[0] == '\n') ||
153
((textbuf[0] == '\r') && (textbuf[1] == '\n')) ) {
156
if( pptextbuf && !isblank(*textbuf) ) {
157
h = head_push_header(head, pptextbuf);
159
pptextbuf = head_append_hline(head, textbuf);
169
void init_header_handling() {
171
init_head_filter(&head);
174
void cleanup_header_handling() {
175
free_head_filter(&head);
179
int main(int argc, char **argv) {
184
void (*preprocess_fun)(void) = NULL;
185
void (*postprocess_fun)(void) = print_summary;
191
/* set up internationalization */
192
if( !setlocale(LC_ALL, "") ) {
194
"could not set locale, internationalization disabled\n");
196
if( u_options & (1<<U_OPTION_VERBOSE) ) {
198
"international locales not supported\n");
202
#if defined(HAVE_GETPAGESIZE)
203
system_pagesize = getpagesize();
205
if( system_pagesize == -1 ) { system_pagesize = BUFSIZ; }
207
init_signal_handling();
209
/* parse the options */
210
while( (op = getopt(argc, argv,
212
hset_option(op, optarg);
216
/* set up callbacks */
219
if( preprocess_fun ) { (*preprocess_fun)(); }
222
init_header_handling();
224
/* now process only the first file on the command line,
225
or if none provided read stdin */
226
if( (optind > -1) && *(argv + optind) ) {
227
/* if it's a filename, process it */
228
input = fopen(argv[optind], "r");
230
inputfile = argv[optind];
232
u_options |= (1<<U_OPTION_STDIN);
234
if( (u_options & (1<<U_OPTION_VERBOSE)) &&
235
!(u_options & (1<<U_OPTION_CLASSIFY))) {
236
fprintf(stdout, "processing file %s\n", argv[optind]);
239
/* set some initial options */
240
hprocess_file(input, &head);
244
} else { /* unrecognized file name */
246
errormsg(E_ERROR, "couldn't open %s\n", argv[optind]);
253
/* in case no files were specified, get input from stdin */
254
if( !(u_options & (1<<U_OPTION_STDIN)) ) {
256
if( (u_options & (1<<U_OPTION_VERBOSE)) &&
257
!(u_options & (1<<U_OPTION_CLASSIFY)) ) {
258
fprintf(stdout, "taking input from stdin\n");
261
hprocess_file(stdin, &head);
263
/* must close before freeing in_iobuf, in case setvbuf was called */
268
if( postprocess_fun ) { (*postprocess_fun)(); }
270
cleanup_header_handling();
272
cleanup_signal_handling();