Created
October 2, 2011 09:49
-
-
Save edipretoro/1257285 to your computer and use it in GitHub Desktop.
Rename a batch of EML files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Email::MIME; | |
use File::Slurp; | |
use File::Next; | |
use DateTime::Format::Flexible; | |
my $iter = File::Next::files( { file_filter => sub { /\.eml$/ } }, '.' ); | |
while (defined( my $file = $iter->() )) { | |
my $text_mail = read_file( $file ); | |
my $email = Email::MIME->new( $text_mail ); | |
my $subject = $email->header('Subject'); | |
my $date = DateTime::Format::Flexible->parse_datetime( $email->header('Date') ); | |
rename( $file, $date->ymd('-') . ' - ' . $subject . '.eml' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment