#!/usr/bin/perl # # This script will download all messages from an account using the pop3 protocol # In order to work properly, you need to configure the settings below # # author: rakudave@gmx.net # website: www.rakudave.ch # # last update: 30.09.2008 ############################### EDIT BELOW ############################### my $dir = ''; # download directory (/home/foo/mails) my $username = ''; # username (user@foo.com) my $password = 'l'; # password (****) my $pop3 = ''; # your pop3-server (pop3.foo.com) ############################## STOP EDITING ############################## use strict; use Getopt::Std; use Net::POP3; # use NET:POP3 library my $pop = Net::POP3->new($pop3); my $i = 0; if ($pop->login($username, $password) > 0) { my $msgnums = $pop->list; # hashref of msgnum => size # get message ID my $nr = number(); # loop until no mails left, deleting each mail after download foreach my $msgnum (keys %$msgnums) { my $msg = $pop->get($msgnum); open OUT, ">$dir/$nr.eml" or die "error: can't create $dir/$nr"; print OUT @$msg; close OUT; $pop->delete($msgnum); $i++; $nr++; } } $pop->quit; # print statusreport if($i){ print "$i new messages have been stored in $dir.\n" } else{ print "no new messages...\n" } exit; # calculate message ID's sub number{ opendir DIR, $dir or die("error: $dir does not exist!"); my @files = readdir DIR; closedir DIR; my $i = scalar(@files) - 1; # fixed +1 to -1 thus ignoring . and .. return $i; } __END__