...soul, as in software?

Rantings about life.

20081010

Fri, 10 Oct 2008

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:

pop3purger
#!/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 connexion is stablished 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.

posted at: 07:33 | path: | permanent link to this entry

Valid XHTML 1.1 Valid CSS! powered by blosxom Debian GNU/Linux VPS hosting by RimuHosting