Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rename a batch of EML files
#!/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