aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiveIMAP.pl21
1 files changed, 15 insertions, 6 deletions
diff --git a/archiveIMAP.pl b/archiveIMAP.pl
index f8116ce..d3606b4 100644
--- a/archiveIMAP.pl
+++ b/archiveIMAP.pl
@@ -89,7 +89,8 @@ my $cutDate = DateTime->now();
$cutDate->add( months => -$howManyMonths );
my @sourceFolders = grep(!/^INBOX\/Archiv/,$imap->folders());
-my ($msgDateInStr,$msgYear,$msgDateStr,$targetFolder);
+my %targetedMessages;
+my ($msgYear,$msgDateStr,$targetFolder);
foreach my $folder (@sourceFolders) {
$imap->select($folder);
@@ -98,14 +99,22 @@ foreach my $folder (@sourceFolders) {
if ($#msgsProc > 0) {
print "Move $#msgsProc in $folder.\n";
foreach my $msg (@msgsProc) {
- $msgDateInStr = $imap->date($msg);
- $msgYear = getMessageYear($msgDateInStr);
+ $msgYear = getMessageYear($imap->date($msg));
if ($msgYear !~ /^\s*$/) {
$targetFolder = getTargetFolder($folder,$msgYear);
- print "Move message $msg from the folder $folder to $targetFolder.\n";
- #$imap->move($targetFolder,$msg);
+ if ($debug) {
+ print "Move message $msg from the folder $folder to $targetFolder.\n";
+ }
+ push ( @{ $targetedMessages{$folder} } , $msg);
}
}
}
-}
+ foreach my $tFolder (keys %targetedMessages) {
+ if (!($imap->exists($tFolder))) {
+ $imap->create($tFolder)
+ or die "Could not create $tFolder: $@\n";
+ }
+ $imap->move($tFolder,$targetedMessages{$tFolder});
+ }
+}
$imap->close();