#!/usr/local/bin/perl # mailwormkiller.pl # (c) Bart Lateur 20/21 sept 2003 # This is free software. Just don't pretend YOU wrote it! # framework based on example 8.1 of Lincoln Stein's book, # "Network Programming with Perl" # Edit these to your personal settings: my($host, $login, $passwd) = qw(mailhost.mydomain.com mylogin mypasswo +rd); use strict; use Net::POP3; use Mail::Header; my $pop = Net::POP3->new($host, Timeout=>30) or die "Can't connect to +$host: $!\n"; my $messages = $pop->login($login => $passwd) or die "Can't log in: " +, $pop->message,"\n"; printf "Check at %s\n", scalar localtime; my $delcount = 0; if($messages += 0) { printf "Inbox holds %d message%s\n", $messages, $messages!=1 && 's +'; for my $msgnum (1 .. $messages) { my $header = $pop->top($msgnum, my $linecount = 40); my $parsedhead = Mail::Header->new($header); chomp(my $subject = $parsedhead->get('Subject')); chomp(my $from = $parsedhead->get('From')); my $deleted = 0; my $offset = ''; if($parsedhead->get('Mime-Version')) { my $redone; { local $_ = join "", @$header; tr/\r//d; s/^(.+\n)+\n+//; (undef, $deleted) = m[^--.*\n (?:(?:Content|[\t\ ]).+\n)* Content-(?:Type:\s+\w*/[\w\-]+;\s+ |Disposition:\s+\w+;\s+file) name=("?).*\.(exe|scr|pif|com|dll|bat|cpl)\1$]xmi and $offset = substr($_, 0, $+[0]) =~ tr/\n//; # for earlier perls you can get along (with slightly d +ifferent results) by using: # $offset = $` =~ tr/\n//; last if $deleted || $redone++ || tr/\n// < $linecount; $header = $pop->top($msgnum, $linecount = 700); redo; } } if($deleted) { $pop->delete($msgnum); $delcount++; } printf "%3d %-3s %3s %-25s %s\n", $msgnum, $deleted || 'ok', +$offset, $from, $subject; } printf "%d message%s deleted.\n\n", $delcount, $delcount!=1 && 's' +; } else { printf "%s\n\n", "You don't have pending mail."; } $pop->quit;

In reply to Kill that Swen worm on your POP3 account! by bart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.