Perl mojo
I enjoy writing small Perl scripts to perform admin tasks.
A couple of days ago I had to delete more than 3000 messages in an email inbox, relaying only on POP3 to do it.
Issuing 3000+ dele
commands by hand was not a very desirable prospect, so I
performed a CPAN search looking for POP3-handling modules.
Bingo! Mail::Box::POP3 does the trick nicely. And it was already installed in my debian box, so I could proceed immediately:
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;
use Mail::Box::POP3;
my $pop = Mail::Box::POP3->new(
access => 'rw',
trace => 'DEBUG',
type => 'pop3',
username => 'someuser',
password => 'somepass',
server_name => 'pop3.whatever.server.example'
) or die "Cannot connect: $!";
$_->delete for $pop->messages;
Once $pop
is created, the connetion is established with the server, and the
message list (headers only) is loaded into the object, and available through
the ‘messages’ method.
A simple ‘for’ iterates through the list, and deletes every sucker.
Nice and sweet.
Tags
perl
email