Простой способ, вероятно, получить Perl и Mail :: IMAPClient и использовать что-то вроде:
use Mail::IMAPClient;
my $imap = Mail::IMAPClient->new(
Server => $imaphost, User => $login, Password => $pass, Uid => 1
);
$imap->select("demo_folder");
my $msgs = $imap->search("ALL");
for my $h (
# get specified headers from every message in folder "demo_folder" the
values %{ $imap->parse_headers( $msgs , "Date", "From", "Subject") } )
{
# $h is the value of each element in the hash ref returned
# from parse_headers, and $h is also a reference to a hash.
# We'll only print the first occurrence of each field because
# we don't expect more than one particular header line per
# message.
print map { "$_:\t$h->{$_}[0]\n"} keys %$h;
}