[PATCH] bulk mode
David Relson
relson at osagesoftware.com
Tue Apr 8 03:02:11 CEST 2003
Michael,
If you're interested in some experimenting, the attached patch implements a
bulk mode ('-b') patch. Usage is:
bogofilter {options} -B file1 file2 file3 ...
Using the '-p' is likely a bad idea (too much output). Using a single '-v'
is likely a good idea, as is using '-t' (terse mode).
David
-------------- next part --------------
Index: bogoconfig.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/bogoconfig.c,v
retrieving revision 1.31
diff -u -r1.31 bogoconfig.c
--- bogoconfig.c 7 Apr 2003 14:01:37 -0000 1.31
+++ bogoconfig.c 8 Apr 2003 00:42:47 -0000
@@ -99,7 +99,7 @@
static bool config_algorithm(const unsigned char *s);
static bool select_algorithm(const unsigned char ch, bool cmdline);
-static void process_args(int argc, char **argv, int pass);
+static int process_args(int argc, char **argv, int pass);
/* externs for query_config() */
@@ -157,11 +157,12 @@
{ NULL, CP_NONE, { (void *) NULL } },
};
-void process_args_and_config_file(int argc, char **argv, bool warn_on_error)
+int process_args_and_config_file(int argc, char **argv, bool warn_on_error)
{
+ int files;
process_args(argc, argv, 1);
process_config_files(warn_on_error);
- process_args(argc, argv, 2);
+ files = process_args(argc, argv, 2);
if (!twostate && !threestate) {
twostate = ham_cutoff < EPS;
@@ -180,7 +181,7 @@
if (DEBUG_CONFIG(0))
fprintf(dbgout, "stats_prefix: '%s'\n", stats_prefix);
- return;
+ return files;
}
static bool config_algorithm(const unsigned char *s)
@@ -360,7 +361,7 @@
** there are leftover command line arguments.
*/
-void process_args(int argc, char **argv, int pass)
+int process_args(int argc, char **argv, int pass)
{
int option;
int exitcode;
@@ -379,7 +380,7 @@
#if HAVE_DECL_OPTRESET
optreset = 1;
#endif
- while ((option = getopt(argc, argv, ":23d:eFhlL:m:o:snSNvVpuc:CgrRfqtI:O:y:x:DT" G R F)) != -1)
+ while ((option = getopt(argc, argv, ":23d:eFhlL:m:o:snSNvVpuc:CgrRfqtI:O:y:x:BDT" G R F)) != -1)
{
#if 0
if (getenv("BOGOFILTER_DEBUG_OPTIONS")) {
@@ -559,6 +560,10 @@
today = string_to_date((char *)optarg);
break;
+ case 'B':
+ bulk_mode = true;
+ break;
+
case 'D':
dbgout = stdout;
break;
@@ -585,12 +590,12 @@
if (exitcode)
exit (exitcode);
- if (optind < argc) {
+ if (!bulk_mode && optind < argc) {
fprintf(stderr, "Extra arguments given, first: %s. Aborting.\n", argv[optind]);
exit(2);
}
- return;
+ return optind;
}
#define YN(b) (b ? "yes" : "no")
Index: bogoconfig.h
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/bogoconfig.h,v
retrieving revision 1.7
diff -u -r1.7 bogoconfig.h
--- bogoconfig.h 4 Mar 2003 21:21:41 -0000 1.7
+++ bogoconfig.h 8 Apr 2003 00:42:47 -0000
@@ -20,6 +20,6 @@
extern const char *user_config_file;
extern void query_config(void);
-extern void process_args_and_config_file(int argc, char **argv, bool warn_on_error);
+extern int process_args_and_config_file(int argc, char **argv, bool warn_on_error);
#endif
Index: globals.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/globals.c,v
retrieving revision 1.8
diff -u -r1.8 globals.c
--- globals.c 2 Mar 2003 00:38:22 -0000 1.8
+++ globals.c 8 Apr 2003 00:42:47 -0000
@@ -29,6 +29,7 @@
bool quiet; /* '-q' */
bool terse; /* '-t' */
int verbose; /* '-v' */
+bool bulk_mode; /* '-B' */
FILE *fpin = NULL; /* '-I' */
int Rtable = 0; /* '-R' */
Index: globals.h
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/globals.h,v
retrieving revision 1.9
diff -u -r1.9 globals.h
--- globals.h 2 Mar 2003 00:38:22 -0000 1.9
+++ globals.h 8 Apr 2003 00:42:47 -0000
@@ -24,6 +24,7 @@
extern bool terse; /* '-t' */
extern bool quiet; /* '-q' */
extern bool passthrough; /* '-p' */
+extern bool bulk_mode; /* '-B' */
extern int verbose; /* '-v' */
extern FILE *fpin; /* '-I' */
Index: main.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/main.c,v
retrieving revision 1.23
diff -u -r1.23 main.c
--- main.c 1 Apr 2003 14:33:27 -0000 1.23
+++ main.c 8 Apr 2003 00:42:47 -0000
@@ -73,8 +73,9 @@
{
int exitcode = 0;
FILE *out;
+ int count;
- process_args_and_config_file(argc, argv, true);
+ count = process_args_and_config_file(argc, argv, true);
/* initialize */
init_charset_table(charset_default, true);
@@ -127,13 +128,34 @@
if (run_type & (RUN_NORMAL | RUN_UPDATE))
{
double spamicity;
- rc_t status = bogofilter(&spamicity);
+ rc_t status;
- write_message(out, status);
-
- exitcode = (status == RC_SPAM) ? 0 : 1;
- if (nonspam_exits_zero && passthrough && exitcode == 1)
- exitcode = 0;
+ if (!bulk_mode) {
+ status = bogofilter(&spamicity);
+ write_message(out, status);
+ exitcode = (status == RC_SPAM) ? 0 : 1;
+ if (nonspam_exits_zero && passthrough && exitcode == 1)
+ exitcode = 0;
+ }
+ else {
+ bool error = false;
+ while (count < argc && !error) {
+ const char *filename = argv[count];
+ fclose(fpin);
+ fpin = fopen( filename, "r" );
+ if (fpin == NULL) {
+ error = true;
+ fprintf(stderr, "Can't read file '%s'\n", filename);
+ }
+ else {
+ status = bogofilter(&spamicity);
+ fprintf(out, "%s ", filename);
+ write_message(out, status);
+ count += 1;
+ }
+ }
+ exitcode = !error ? 0 : 1;
+ }
}
else {
register_messages(run_type);
Index: rstats.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/rstats.c,v
retrieving revision 1.9
diff -u -r1.9 rstats.c
--- rstats.c 30 Mar 2003 14:13:01 -0000 1.9
+++ rstats.c 8 Apr 2003 00:42:47 -0000
@@ -68,6 +68,8 @@
void rstats_init(void)
{
header.list = (rstats_t *) xcalloc( 1, sizeof(rstats_t));
+ header.count = 0;
+ header.robn = 0;
current = header.list;
}
More information about the bogofilter-dev
mailing list