| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | # | ||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | mail_tempaddress_purge.pl - purge Mail::TempAddress::Address object when | ||||||||||
| 7 | they expire | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | mail_tempaddress_purge.pl directory [min_age] [-v] | ||||||||||
| 12 | |||||||||||
| 13 | =cut | ||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | # apply roles | ||||||||||
| 18 | 1 | ▶ | use Mail::TempAddress::Addresses; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use Mail::Action::Role::Purge; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | use Class::Roles | ||||||||||
| 21 | 1 | ▶ | apply => { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | role => 'Purge', | ||||||||||
| 23 | to => 'Mail::TempAddress::Addresses' | ||||||||||
| 24 | 1 | }; | |||||||||
| 25 | |||||||||||
| 26 | # parse command line | ||||||||||
| 27 | 1 | ▶ | use Getopt::Long; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | my $verbose; | |||||||||
| 29 | 1 | GetOptions( "verbose" => \$verbose ); | |||||||||
| 30 | 1 | my $dir = shift; | |||||||||
| 31 | 1 | my $min_age = shift; | |||||||||
| 32 | 1 | ▶ | die( "usage: $0 address_dir [min_age]\n" ) unless $dir; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | # create a tempaddr object | ||||||||||
| 35 | 1 | my $addys = Mail::TempAddress::Addresses->new( $dir ); | |||||||||
| 36 | |||||||||||
| 37 | # report how many addresses exist | ||||||||||
| 38 | 1 | print "$dir contains ", $addys->num_objects, " addresses\n"; | |||||||||
| 39 | |||||||||||
| 40 | # if verbose, list the addresses | ||||||||||
| 41 | 1 | ▶ | list_addresses() if $verbose; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | # run the purge routine | ||||||||||
| 44 | 1 | my $purged = 0; | |||||||||
| 45 | 1 | $purged = $addys->purge($min_age); | |||||||||
| 46 | |||||||||||
| 47 | # report how many addresses were purged; | ||||||||||
| 48 | 1 | my $justone = (1 == $purged); | |||||||||
| 49 | 1 | ▶ | print $purged . ($justone ? " address was" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | : " addresses were") . " purged\n"; | ||||||||||
| 51 | |||||||||||
| 52 | # if verbose, list the addresses | ||||||||||
| 53 | 1 | ▶ | list_addresses() if $verbose; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | # all done! | ||||||||||
| 56 | 1 | exit(0); | |||||||||
| 57 | |||||||||||
| 58 | sub list_addresses | ||||||||||
| 59 | 2 | ▶ | { | ||||||||
|
Subroutine
list_addresses: called CC=2 SCAR=6.9
| |||||||||||
| 60 | |||||||||||
| 61 | 2 | my $i = 0; | |||||||||
| 62 | 2 | for( @{ $addys->object_names } ) { | |||||||||
| 63 | 15 | print $i++ . " $_\n"; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | |||||||||||
| 69 | __END__ | ||||||||||