#!/usr/bin/perl use strict; use warnings; my $fh; open $fh, "<", shift; my @message = <$fh>; use Mail::SpamAssassin::Message; my $msg = Mail::SpamAssassin::Message->new( { 'message' => \@message, } ) || die "Message error?"; #foreach my $p ($msg->find_parts(qr/^(text|image|application)\b/i, 1)) { foreach my $p ($msg->find_parts(qr/^application\b/i, 0)) { eval { #no warnings ; my $type = $p->{'type'}; my $attachname = $p->{'name'}; print "Content type is: $type\n"; print "write file name: $attachname\n"; open my $out, ">", "$attachname" || die "Can't write file $attachname:$!"; binmode $out; print $out $p->decode(); }; warn $@ if $@; }