diff options
-rw-r--r-- | archiveIMAP.pl | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/archiveIMAP.pl b/archiveIMAP.pl index 5b5c04f..a1833de 100644 --- a/archiveIMAP.pl +++ b/archiveIMAP.pl @@ -38,18 +38,24 @@ sub getTargetFolder { sub assureFolder { my $imaphandle = shift; my $fullfoldername = shift; + my $sep = $imap->separator($fullfoldername); if ($imaphandle->exists($fullfoldername)) { return 1; } - + my $parentpath = join ($sep, + (split /$sep/,$fullfoldername)[0,-1] + ); + assureFolder($imaphandle,$parentpath); + $imaphandle->create($fullfoldername) or + die "Unable to create folder $fullfoldername"; } our $Strp = new DateTime::Format::Strptime( - pattern => '%a, %d %b %Y %H:%M:%S %z' + pattern => '%a, %d %b %Y %H:%M:%S %z' ); our $StrpNoTZ = new DateTime::Format::Strptime( - pattern => '%a, %d %b %Y %H:%M:%S' + pattern => '%a, %d %b %Y %H:%M:%S' ); sub getMessageYear { @@ -63,12 +69,12 @@ sub getMessageYear { print "Date EMPTY.\n"; return ""; # TODO: message without Date: # not sure what to do about it - # Currently just do nothing and - # return empty string. + # Currently just do nothing and + # return empty string. } my $year = $msgDt->year; if ($debug) { - print "\$msgStr = $msgStr, \$msgDt = $msgDt, year = $year\n"; + print "\$msgStr = $msgStr, \$msgDt = $msgDt, year = $year\n"; } return $year; @@ -123,16 +129,16 @@ foreach my $folder (@sourceFolders) { } } foreach my $tFolder (keys %targetedMessages) { - # FIXME: check the situation when the parent folder(s) don't exist - # what about different folder separators? (i.e., can we put - # "Archiv/2007/Pratele/PCF" as an argument of $imap->create?) - # RFC says (in 6.3.3) that server SHOULD create parent folders - # if (!($imap->exists($tFolder))) { - $imap->create($tFolder) - or die "Could not create $tFolder: $@\n"; + # Not sure how would following deal with non-existent + # parent folder, so rather recursively create + # parents. + # + #$imap->create($tFolder) + # or die "Could not create $tFolder: $@\n"; + assureFolder($imap,$tFolder); } $imap->move($tFolder,$targetedMessages{$tFolder}); } } -$imap->close(); +$imap->close();
\ No newline at end of file |