IMAP from Perl

I’m quickly finding it necessary to get back “into” scripting: I’d throw stuff together here and there, but it’s been a while since I wrote anything more than a dozen lines or so, and I haven’t done anything with Perl in far too long.

For a project I’m going to be doing, I just discovered something awesome: Perl’s Net::IMAP::Simple

This code doesn’t actually do much, but it’s still pretty neat how simple Perl makes it:

# Open the connection
$server = new Net::IMAP::Simple("$servername") or die("Couldn't open connection to server $servernamen");
print "Connected to $servername...n";

# Authenticate
$server->login("$user", "$pass") or die("Couldn't authenticate with server as $user : $passn");
print "Authenticated as $user...n";

# Get a message count (frivilous)
$message_count = $server->select($folder) or die("Selecting folder $folder failed.n");
print "Connected with $message_count messages...n";

# Print a list of all folders?
@folders = $server->mailboxes();
foreach $x (@folders) {
        print "$xn";
}

With a little looping magic, it should be easy enough to extract whatever’s needed from each message! (There are some more complex IMAP scripts, but, well, they’re not called IMAP::Simple…)

Leave a Reply

Your email address will not be published. Required fields are marked *