#!/usr/bin/perl -w ###################################################################### +######## ## -*-perl-*- ## ## metamail - My slightly more secure metamail workalike. ## ## Courtesy of Gerard's Perl Page, ## http://www.geocities.com/gerardlanois/perl/ ## REVISION HISTORY ## ## version 1.0 2001/07/12 gerard@lanois.com - Initial release. ## version 1.1 2002/01/31 gerard@lanois.com - parts_DFS instead of r +ecursion ###################################################################### +######## use strict; use MIME::Parser; use File::Path; use File::Copy; use File::Basename; sub yesno($) { my $question = shift; print $question, " (y/n) [n]: "; my $key = <STDIN>; print "\n"; return $key =~ /^y/i; } my $tempdir = "metamail-tmp"; (-d $tempdir) or mkdir $tempdir,0755 or die "mkdir: $!"; (-w $tempdir) or die "can't write to directory"; my $parser = MIME::Parser->new; $parser->output_dir($tempdir); $parser->extract_uuencode(1); defined $ARGV[0] or die "usage: metamail filename\n"; my $entity = $parser->parse_open($ARGV[0]) or die "couldn't parse file "; my $head = MIME::Head->from_file($ARGV[0]); my @hdrs = qw( Subject Reply-to From ); foreach (@hdrs) { my $header = $head->get($_); if (defined $header) { chomp $header; print " $_:", $header, "\n"; } } $entity->dump_skeleton(\*STDOUT); print "-"x40, "\n"; foreach my $part ($entity->parts_DFS) { # Process only those entities which have bodies. next if (!$part->bodyhandle); # If there are evil chars in the bodyhandle path, then MIME::Parse +r # will choke and give a null file name, but the recommended # file name will always have the file name, evil characters # included. my $filename = $part->head->recommended_filename; if (!$filename) { $filename = $part->bodyhandle->path; } fileparse_set_fstype("MSWin32") if ($^O =~/MSWin32/); my ($file, $dir, $ext) = fileparse($filename, '\.[^.]*'); if (yesno("\n\n".$file.$ext." - want it?")) { if ((!-f "./".$file.$ext) || (-f "./".$file.$ext && (yesno("File exists, overwrite?"))) +) { move($part->bodyhandle->path, $file.$ext) ; print "Saved ", $file.$ext, "\n"; } } } $parser->filer->purge; rmtree $tempdir;

In reply to Re: Receiving an email attachment by perldoc
in thread Receiving an email attachment by rogueFalcon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.