Ramprasad A Padmanabhan wrote:
> 
> I would like to write a program that deletes all mails from my popserver
> which are older than 'n' days
> 
> Is there a script available already. If I were to write a script using
>   Mail::POP3Client , I would have to fetch the headers of all mails and
> the parse mail headers
> 
> Is there no module that can return all mails recd before a particular date

The Post Office Protocol is pretty simple and does not store any
meta-data about the messages on the server.  The only date you could use
is the "Date:" header of the actual emails but that is set by the MUA
and may not be valid.


#!/usr/bin/perl
# UNTESTED
use warnings;
use strict;
use Net::POP3;

my $pop_host = 'pop3.somehost.com';
my $pop_user = 'Padmanabhan';
my $pop_pswd = '********';
# parse_date() is some undefined routine to convert dates
my $too_old  = parse_date( '1 Nov 2003' );

my $pop = Net::POP3->new( $pop_host );

my $num = $pop->login( $pop_user, $pop_pswd )
    or die "Cannot login to $pop_host";

my $list = $pop->list();
for my $mesg ( keys %$list ) {
    my $headers = $pop->top( $mesg );
    my $date;
    for ( @$headers ) {
        last if ( $date ) = /^Date:\s+(.+)/;
        }
    if ( defined( $date ) and parse_date( $date ) < $too_old ) {
        $pop->delete( $mesg );
        }
    }
$pop->quit();

__END__



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to