[Mimedefang] Rejecting Cyrillic
Michael Glad
glad at cs.au.dk
Sat Apr 18 14:45:32 EDT 2009
A little feedback -- the Encode module throws exceptions when it cannot
decipher an encoding, e.g some unicode variants.
This spells death for an unsuspecting mimedefang slave.
Consequently I've wrapped your code into a function is_cyr and invoke
it as:
$is_cyr = eval { &is_cyr }; $is_cyr = 0 if $@;
This will catch any exception thrown by the Encode module.
Now it can handle eg
=?koi9-r?B?0M/EwdLJ1MUgzMDCyc3PzdU=?=
which I created on purpose by mangling a koi8 subject line from a recent
spam mail.
-- Michael
> 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.
> }
> }
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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 MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
>
More information about the MIMEDefang
mailing list