Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizashi1122/925c9cd5ce4c99b8961abfe5cf8c4b19 to your computer and use it in GitHub Desktop.
Save kizashi1122/925c9cd5ce4c99b8961abfe5cf8c4b19 to your computer and use it in GitHub Desktop.
use DateTime;
use MIME::Parser;
my $dir = shift || Cwd::getcwd();
my $count = 0;
my @array = ();
touch_emls($dir);
sub touch_emls {
my $dir = shift;
opendir my $dh, $dir or die "$!";
my $parser = MIME::Parser->new;
$parser->output_dir( "/tmp" );
$parser->tmp_to_core(1);
for my $subf (grep !/^\.\.?/, readdir($dh)) {
my $f = "$dir/$subf";
if (-d $f) {
touch_emls($f);
next;
}
if (-f $f) {
my $mail = $parser->parse_open($f);
my $date_str = $mail->head->get("Date");
my $epoch = str2time($date_str);
$parser->filer->purge;
utime $epoch, $epoch, $f; # touch file
my $curdir = dirname $f;
my $filename = basename $f;
# 1475743648.M772840P29835.ip-172-31-10-24,S=5361,W=5456:2,
if ($filename =~ m/^14[0-9]{8}\./) {
my $org = $filename;
$filename =~ s/^14[0-9]{8}/$epoch/;
say "before $org";
say "after $filename";
rename $f, "$curdir/$filename";
}
say $f . " => " . $epoch;
}
}
closedir $dh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment