- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] Program to detach e-mail attachment
- From: John Clarke <johnc+slug@xxxxxxxxxxx>
- Date: Wed, 6 Jul 2005 10:10:45 +1000
- User-agent: Mutt/1.2.5.1i
On Wed, Jul 06, 2005 at 09:42:36 +1000, Peter Rundle wrote:
> looking for some pointers on getting together some code to auto process
> incoming e-mails, detach their attachments and save them as files. The
[snip]
> anyone have some examples, web pages to go visit...
Something like this should do what you want:
#!/usr/bin/perl -w
use strict;
use MIME::Parser;
my $parser = new MIME::Parser;
$parser->output_dir("$ENV{HOME}/attachments");
$parser->parse(\*STDIN) or die "parse failed\n";
MIME::Parser::parse() returns a MIME::Entity which can be used to
process each attachment separately, like this:
$entity = $parser->parse(\*STDIN) or die "parse failed\n";
# now deal with each part
foreach $part ($entity->parts)
{
# do what you want with this part
}
Cheers,
John
--
As David pointed out, soon-to-be postgrad couldn't install software. Sounds
like a good idea to me, particularly at a uni. I sometimes think giving
them keyboards is being overly generous.
-- Craig 'Stevo' Stephenson