#!/usr/local/bin/perl use strict; use warnings; use Email::MIME; use constant DUMP => '/home/simon/public_html/mime/'; my $email = Email::MIME->new(join '', <>); save_parts($email); sub save_parts { my ($mime) = @_; return unless $mime->content_type; if ($mime->content_type !~ /^(text|multipart|message)/) { my $file = DUMP . $mime->filename(1); open FILE, '>', $file or die $!; print FILE $mime->body; close FILE; chmod 0644, $file; } my @parts = $mime->parts; if (@parts > 1) { save_parts($_) for @parts; } }