[Mimedefang] Rejecting Cyrillic

Richard Laager rlaager at wiktel.com
Thu Apr 16 20:38:15 EDT 2009


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.
	}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://lists.mimedefang.org/pipermail/mimedefang_lists.mimedefang.org/attachments/20090416/47736a7e/attachment.sig>


More information about the MIMEDefang mailing list