#!/usr/bin/env perl # use strict; use warnings; use File::Find; use Email::Simple; use File::Slurp qw( read_file ); my $directory = '/home/******/Mail/.family.directory/Browne, Bill & Martha'; my $outfile = 'output2.txt'; my @found_files; find( sub { push @found_files, $File::Find::name }, $directory ); foreach(@found_files) { my $file = "$_"; if (-f $file) { print $_,"\n"; my $intext = File::Slurp::read_file( $file ); my $mail = Email::Simple->new($intext); my $from_header = $mail->header("From"); my $to_header = $mail->header("To"); my $date_header = $mail->header("Date"); my $cc_header = $mail->header("CC"); my $bcc_header = $mail->header("BCC"); my @emails = ""; push @emails, ($from_header, $to_header); if( length $cc_header ) { push @emails, $cc_header; } if( length $bcc_header ) { push @emails, $bcc_header; } File::Slurp::write_file( $outfile, {append => 1 }, join("\n", @emails ) ); } }