pop2messbox.pl

#!/usr/bin/perl
use Mail::POP3Client;
use IO::File;

my $Hostname = $ARGV[0];
my $Username = $ARGV[1];
my $Password = $ARGV[2];
my $Location = $ARGV[3];

if ( defined($Hostname) &&
        length($Hostname) > 0 &&
        defined($Username) &&
        length($Username) > 0 &&
        defined($Password) )
{
        if ( ! -d $Location )
        {
                die(qq{$Location is not a valid directory path});
        }
        else
        {
                my $POP = new Mail::POP3Client(
                                USER     => $Username,
                                PASSWORD => $Password,
                                HOST     => $Hostname,
                                USESSL   => true,
                );

                $POP->Connect() >= 0 || die $POP->Message();
                for ($i = 1; $i < = $POP->Count(); $i++)
                {
                        my $Filename = $Location . ‘/’ . join(’_',$Hostname,$Username,$i) . ‘.eml’;
                        my $Filehandle = new IO::File;
                        open($Filehandle, “>$Filename”);
                        $POP->RetrieveToFile( $Filehandle, $i );
                        close($Filehandle);
                }
                $POP->Close();

        }
}

Its no problem to use…
shell$ mkdir /some/storage/location
shell$ ./pop2messbox.pl pop3.host.com username password /some/storage/location/

Requires…
Mail::POP3Client from CPAN

Leave a Reply