aboutsummaryrefslogtreecommitdiffstats
path: root/expireIMAP.pl
blob: 5f00651f592c73988a82f623bd33b1cf77313ddb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use strict;
use warnings;
use Mail::IMAPClient;
use Data::Dumper;
use DateTime;

my $hostname = "localhost";
my $login = "matej";
my $passwd = "lubdkc";

die "Just one name of the folder, please." unless $#ARGV == 0;

# How many months before today the cut date should be?
my $howManyMonths = 3;
my $lengthOfScreen = 65;

my $imap = Mail::IMAPClient->new();
$imap = Mail::IMAPClient->new(
	Server => $hostname,
	User => $login,
	Password => $passwd,
	UID => 1
) or die "Cannot connect to localhost as matej: $@";

my $cutDate = DateTime->now();
$cutDate->add( months => -$howManyMonths );

# Do the stuff!
$imap->select($ARGV[0]);
my @msgsProc = $imap->search(" UNDELETED BEFORE " . $cutDate->strftime("%d-%b-%Y"));
print "\$#msgsProc = $#msgsProc\n";
$imap->delete_message(@msgsProc) or die "Cannot delete $#msgsProc messages.";
$imap->close();