On Wed, 2009-03-25 at 12:46 -0700, Kenneth Porter wrote:
> I've noticed a lot of spam lately in codepage Windows-1251 (Cyrillic). I'd 
> like to reject it with a "Cyrillic not understood; please resubmit as 
> Unicode". Is there a canonical MIMEDefang idiom for doing that?

I wanted to do largely the same thing and finally found the time to
write it. I was concerned only with Cyrillic subjects as the indicator
of spam. I put the code below in filter_end(), except for the "use"
statements, which I put at the top with the others. In my filter, I
added points to the SpamAssassin score, but you could call
action_bounce() if you wanted.

I don't know if it's strictly necessary to call decode with "us-ascii".
I did it because I was concerned about Perl's internal handling of bytes
vs. characters.

Any feedback on this code would be greatly appreciated.

Richard

========================================

use Encode;
use MIME::Words;

if ($Subject =~ m/=\?.+\?.+\?.+\?=/)
{
        my $decoded_subject = "";
        foreach my $pair (MIME::Words::decode_mimewords($Subject))
        {
                if (defined($pair->[1]) && $pair->[1] ne "")
                {
                        $decoded_subject .= decode($pair->[1], $pair->[0]);
                }
                else
                {
                        $decoded_subject .= decode("us-ascii", $pair->[0]);
                }
        }

        if ($decoded_subject =~ m/\p{Cyrillic}/)
        {
                # DO SOMETHING HERE: REJECT, ETC.
        }
}

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Reply via email to