#!/usr/bin/perl
#
# Assuming a bunch of spam in < some-file, feed it one message at a
# time to procmail for testing purposes.

$| = 1;
@lines = <STDIN>;

$number = 0;
for ($i = 0; $i <= $#lines; $i++) {
    if ($lines[$i] =~ /^From /i) {
	for ($j = $i+1; $j <= $#lines; $j++) {
	    print $lines[$j] if ($lines[$j] =~ /^Subject:/);
	    last if ($lines[$j] =~ /^From /i);
        }

	@msg = @lines[$i+1..$j-1];
	open OUT, ">/tmp/splonk.test";
	print OUT @msg;
	close OUT;
	`procmail < /tmp/splonk.test`;
	$number++;

	$i = $j-1;
    }
}
print "Messages processed: $number\n";
