Ville Walveranta wrote:
Here's the completed code that includes the "blank line check" -- the
body is neither scanned for "Subject: **SPAM**" (saves time and
prevents false positives) nor is the substitution string run against
the body (so that any occurrences of "Subject: **SPAM**" are not
touched in the body).

If someone feels like beautifying my Perl code, or optimizing the
logic, I don't mind. ;-)

Ville

------[begin excerpt from smtpprox MSDW/SMTP/Client.pm]------
sub yammer {
    my ($self, $fh) = (@_);
    my $spamheader = "X-Spam: yes\r\n";
    my $spam = 0;
    local (*_);
    local ($/) = "\r\n";
    while (<$fh>) {
        if ($_ =~ m/^Subject:\s*\*\*SPAM\*\*\s+/i) {
        $spam = 1;
        }
        if ($_ =~ m/^\s*$/) {
        last;
        }
    }
    seek( $fh, 0, 0);
    if ($spam == 1) {
    $self->{sock}->print($spamheader) or die "$0: write error: $!\n";
    }
    while (<$fh>) {
        s/^\./../;
        if ($_ =~ m/^\s*$/) {
        $spam = 0;
        }
        if ($spam == 1) {
        s/^Subject:\s*\*\*SPAM\*\*\s+/Subject: /i;
        }
        $self->{sock}->print($_) or die "$0: write error: $!\n";
    }
    $self->{sock}->print(".\r\n") or die "$0: write error: $!\n";
}


you're removing the blank line. always be careful with "last".

why do you split the while loop? you're changing the code too much...


        my $spamheader="X-Spam: Yes";
        ...
        while (<$fh>) {
          s/^\./../;
          if ($spamheader) {
                if (/^Subject:\s*\*\*SPAM\*\*\s+/i) {
                        $_ = "Subject $'";
                        $self->{sock}->print($spamheader) ...
                } elsif { /^$/) {
                        $spamheader = undef;
                }
          }
          $self->{sock}->print($_) or die "$0: write error: $!\n";
        }
        ...

BTW. I think the proxy adds \r\n by itself (and removes them when it reads the mail). you need to check this though.

anyway, count me out now.






Reply via email to