#!/usr/bin/perl

# this script adds the from address to the spamassassin whitelist,
# pipes the message back through spamassassin to remove the SPAM
# markup, and then pipes it back into procmail so it will be filtered
# correctly.

# use to recover mail that has been marked as spam because you have
# friends who WRITE THEIR MAIL IN ALL CAPS AND USE HTML

use strict;
use warnings;

my @msg;
my $line;
my $whitefile = "/home/jaq/.spamassassin/user_prefs";

@msg = <STDIN>;

open OUT, ">>$whitefile"
    or die "couldn't open file $whitefile";

my ($from) = map /^From:.*[< ]([\w.-]+\@([\w.-]+\.)+\w+)>?/, @msg;

print OUT "whitelist_from $from\n" if ($from);
close OUT;

open SA, "|spamassassin -d | procmail" or die "couldn't open spamassassin";
print SA @msg;
close SA;
