diff options
Diffstat (limited to 'expireIMAP.pl')
-rw-r--r-- | expireIMAP.pl | 76 |
1 files changed, 8 insertions, 68 deletions
diff --git a/expireIMAP.pl b/expireIMAP.pl index 153a99f..5f00651 100644 --- a/expireIMAP.pl +++ b/expireIMAP.pl @@ -4,9 +4,8 @@ use strict; use warnings; use Mail::IMAPClient; use Data::Dumper; -use DateTime::Format::Strptime; +use DateTime; -my $msg; my $hostname = "localhost"; my $login = "matej"; my $passwd = "lubdkc"; @@ -15,6 +14,7 @@ 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( @@ -24,72 +24,12 @@ $imap = Mail::IMAPClient->new( UID => 1 ) or die "Cannot connect to localhost as matej: $@"; -my $Strp = new DateTime::Format::Strptime( - pattern => '%a, %d %b %Y %H:%M:%S %z' -); -my $StrpNoTZ = new DateTime::Format::Strptime( - pattern => '%a, %d %b %Y %H:%M:%S' -); - -$imap->select($ARGV[0]); -my $hash = $imap->fetch_hash("INTERNALDATE","FLAGS"); - -my @flags; -my $isDeleted; -my $msgDateStr; -my $msgDate; - my $cutDate = DateTime->now(); $cutDate->add( months => -$howManyMonths ); -# FIXME: Wrong -- USE $imap->before(RFC2060 date) -# SEARCH UNDELETED BEFORE -foreach $msg (keys(%$hash)) { - @flags = $imap->flags($msg); - $isDeleted = grep(/\\Deleted/,@flags); - if (!$isDeleted) { - $msgDateStr = $imap->date($msg); - $msgDate = $Strp->parse_datetime($msgDateStr); - if (!$msgDate) { - $msgDate = $StrpNoTZ->parse_datetime($msgDateStr); - } - if (!$msgDate) { - next; # TODO: message without Date: - # not sure what to do about it - # Currently just do nothing and let it rot there. - } - die "WARNING: \$msgDate = $msgDate" if $@; - - if ($msgDate < $cutDate) { - print "Msg $msg with date $msgDate is to be deleted.\n"; - } - } -} - -# print "\@flags = @flags, \$isDeleted = $isDeleted\n"; -# $msgID = $imap->get_header($msg,"Message-Id"); -# print "\$msg ID = $msg\nMESSAGE-ID = $msgID\n"; -# $headers = $imap->parse_headers($msg,"Date","Received","Subject","To"); -# print "Headers = " . Data::Dumper->Dumpxs([$headers],['$headers']) . "\n"; - -## Get a list of messages in the current folder: -#my @msgs = $imap->messages or die "Could not messages: $@\n"; -## Get a reference to an array of messages in the current folder: -#my $msgs = $imap->messages or die "Could not messages: $@\n"; - -#use Mail::IMAPClient; -# my $imap = Mail::IMAPClient->new( Server => $imaphost, -# User => $login, -# Password=> $pass, -# Uid => 1, # optional -# ); -# -# $imap->select("World Domination"); -# # get the flags for every message in my 'World Domination' folder -# $flaghash = $imap->flags( scalar($imap->search("ALL"))) ; -# -# # pump through sorted hash keys to print results: -# for my $k (sort { $flaghash->{$a} <=> $flaghash->{$b} } keys %$flaghash) { -# # print: Message 1: \Flag1, \Flag2, \Flag3 -# print "Message $k:\t",join(", ",@{$flaghash->{$k}}),"\n"; -# } +# 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();
\ No newline at end of file |