Skip to content

Instantly share code, notes, and snippets.

@edipretoro
Created October 2, 2011 09:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edipretoro/1257285 to your computer and use it in GitHub Desktop.
Save edipretoro/1257285 to your computer and use it in GitHub Desktop.
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