#!/usr/bin/perl use strict; use Mail::POP3Client; my @accounts = ( { USER => "simon", AUTH_MODE => "PASS", PASSWORD => "MYPASS", HOST => "pop3.myhost.net" }, # Other accounts here ); my %midcache; %midcache = map {chomp; $_ => 1} `tail -50 /home/simon/.msgidcache`; $|=1; for (@accounts) { print "\nConnecting to $$_{HOST}..."; my $pop = new Mail::POP3Client (%$_); unless ($pop) { warn "Couldn't connect\n"; next; } my $count = $pop->Count; if ($count <0) { warn "Authorization failed"; next; } if (!$count ) { print "No new mail\n"; next; } print "\n"; my @mails; for my $num (1..$count) { print "\n"; my @head = $pop->Head($num); for (@head) { /^(From|Subject):\s+(.*)/i and do { print "$1\t$2\n"; $mails[$num]->{$1} = $2; }; /^Message-Id:\s+(\S+)/i and do { if (exists $midcache{$1}) { print "(Killing duplicate)\n"; $mails[$num]->{mid} = $1; $pop->Delete($num); } $midcache{$1}++; } } } }