-
Notifications
You must be signed in to change notification settings - Fork 53
/
mimedecode
executable file
·94 lines (65 loc) · 1.7 KB
/
mimedecode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
=begin metadata
Name: mimedecode
Description: extract MIME attachments in uudecode-like manner
Author: Nick Ing-Simmons, nick@ni-s.u-net.com
License:
=end metadata
=cut
use v5.12.0;
use Getopt::Std;
SANITY: {
my $external_module = 'MIME::Parser';
my $rc = eval "require $external_module; $external_module->import; 1";
die "This program needs the $external_module module.\n" unless $rc;
}
{package PerlPowerTools::MIME::Parser;
push @INC, 'MIME::Parser'; # this is old school so -c doesn't complain
sub new_body_for
{
my ($parser,$head) = @_;
my $outname = $head->recommended_filename;
if (defined $outname)
{
return MIME::Body::File->new($parser->output_path($head));
}
else
{
return MIME::Body::Scalar->new;
}
}
}
my %opt = ( 'd' => '.' );
getopts('d:',\%opt);
my $parser = PerlPowerTools::MIME::Parser->new;
$parser->output_dir($opt{'d'});
if (@ARGV)
{
foreach my $file (@ARGV)
{
my $entity = $parser->parse_in($file);
}
}
else
{
my $entity = $parser->read(\*STDIN);
}
__END__
=head1 NAME
mimedecode - extract MIME attachments in uudecode-like manner
=head1 SYNOPSIS
mimedecode [-d directory] < file
mimedecode [-d directory] file...
=head1 DESCRIPTION
C<mimedecode> processes mail files using B<MIME::Parser> module.
It handles "multipart" messages and saves "attached" files
(i.e. parts with suggested file names) to their suggested names
in the directory specified after C<-d>, or the current directory if
C<-d> is not given.
=head1 BUGS
It needs the module installed.
Should probably consider more of headers in deciding if it really
is a useful attachment.
=head1 AUTHOR
Slapped together by Nick Ing-Simmons <nick@ni-s.u-net.com>
=cut