#!/usr/bin/env perl # use strict; use warnings; use Data::Dumper; use File::Slurp qw( read_file ); use Email::Address; use Email::MIME::Attachment::Stripper; use File::Slurp qw(slurp write_file); my $infile = '/home/****/Mail/.family.directory/1277709595.16641.pRLSb:2,S'; my $outfile = 'output4.txt'; my $intext = File::Slurp::read_file( $infile ); my $stripper = Email::MIME::Attachment::Stripper->new($intext); my $email_mime = $stripper->message; print $email_mime; # displays "Email::MIME=HASH(0x1601e60)" my @emails = Email::Address->parse( $email_mime ); File::Slurp::write_file( $outfile, join("\n", @emails) ); # no output ? my $parsed = Email::MIME->new($intext); #print "Parsed content :\n". Dumper( $parsed) . "\n"; my $parts = $parsed->parts; print "Number of email parts : $parts\n"; # displays "Number of email parts : 25" my @parts = $parsed->parts; foreach my $attachment ( $stripper->attachments ) { write_file( $attachment->{filename}, { buf_ref => \$attachment->{payload} } ) or die "Can't write $attachment->{filename}: $!\n"; }