aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatej Cepl <mcepl@redhat.com>2008-10-09 18:27:08 +0200
committerMatej Cepl <mcepl@redhat.com>2008-10-09 18:27:08 +0200
commit3e2d459aff9fac8ad5b6893cb545b5ab5c895b8c (patch)
tree2108ef9f70fe930cc245da9f38f187aae74f1fa3
parent3a82fd41012560461d6e37d9f8bed8865740d6a6 (diff)
downloadimapArch-3e2d459aff9fac8ad5b6893cb545b5ab5c895b8c.tar.gz
assureFolder should be more or less working.
-rw-r--r--archiveIMAP.pl34
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