DCPM: De-SWENing

Simon Waters Simon at wretched.demon.co.uk
Sat Sep 20 14:30:58 CDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Argh, this virus was building up faster at Demon's mail server than the
SMTP delivery could cope.

So I thought lets do a custom Perl script to keep my hand in, because I
couldn't find a simple "header" rule to kill the messages reliably. Some
people were discussing uppercase headers - hmm.

One thing I still find tricky is what to prefix variables with in Perl.

Am I right in thinking that Net::POP3 ->list() is returning a reference
to a hash, not a hash, hence the $mail->{$msg}, as programmers seem to
say "returns a has" when they mean "returns a reference to a hash", or
am I just showing my lack of sleep :(

Okay it needs some comments, and a few extra "die" statements, but it
seems to kill all messages with size betwee 139998 and 160616 with an
uppercase "SUBJECT" in the headers in my POP3 mail box. Demon use
"domain" rather than "username", but it makes no odds whatever you need
to access your POP3 mail.

Use at your own risk, no warranty applies. Comments on how it might be
better written gratefully received. Feel free to pass onto people even
less skiled at Perl but with more viruses (i.e. desparate).

BEFORE:
There are 514 messages waiting on punt-3.mail.demon.net for
wretched.demon.co.uk

AFTER:
There are 198 messages waiting on punt-3.mail.demon.net for
wretched.demon.co.uk

Alas 100 odd of these are still obviously spam, and a few are viruses,
but that is at least 44MB less junk to eat my bandwidth.


#!/usr/bin/perl -w
use strict;
use Net::POP3;
my $server = 'pop3.demon.co.uk' ;
my $domain = 'wretched';
my $passwd = '???????';
my $min = 139998 ;
my $max = 160616 ;

my $popserv = Net::POP3->new($server);
my $nummail = $popserv->login($domain,$passwd);
printf("You have $nummail messages queued\n");

# Get size of messages
my $mail = $popserv->list();

my $msg;

foreach $msg (keys %$mail )
{

 my $size = $mail->{$msg} ;

 if ( ( $size > $min ) and ( $size < $max ) )
 {
   my $headers = $popserv->top($msg);
   my $subject = grep {/^SUBJECT:/} @$headers;
   if ( $subject eq 1 )
   {
    # Lets kill all uppercase subjects as we are mean like that
    $popserv->delete($msg);
   }
 }
}

$popserv->quit();
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/bKrvGFXfHI9FVgYRApGZAJkBrwI5XSRk71JBNXS6UeGCnZirBwCff6WU
wSu+Uvx4TyMAqtkHKWwXtqA=
=By/i
-----END PGP SIGNATURE-----



More information about the Devoncornwall-pm mailing list