Bass-Fighter has asked for the wisdom of the Perl Monks concerning the following question:

ok, I posted 2 weeks ago something about logging an attachment. this is what I could make with grand help of webfiend.
#!usr/bin/perl use v5.8.0; use warnings; use strict; use MIME::Parser; my $parser = MIME::Parser->new(); $parser->output_under('/tmp'); my $entity = $parser->parse(\*STDIN); if ( $entity->is_multipart ) { for my $part ( $entity->parts ) { my $head = $part->head; if ( my $filename = $head->recommended_filename ) { print "Attachment name: $filename\n"; } } }
I have 2 mails to test the system. the first gives the output what I want. the second gives this: Can't locate object method "binmode" via package "IO::File" at /usr/lib/perl5/site_perl/5.8.0/MIME/Body.pm line 437. does anyone know how to solve this?

Replies are listed 'Best First'.
Re: attachment logging
by Anonymous Monk on Dec 18, 2008 at 11:10 UTC
    { no warnings; sub IO::File::binmode {} }

      Of course, this is just a band-aid, as binmode actually does something, nowadays even on systems with unixish file semantics. Most likely, the proper fix would be to upgrade IO::File to a later version than is installed, or to copy the code for IO::File::binmode into that subroutine:

      sub binmode { ( @_ == 1 or @_ == 2 ) or croak 'usage $fh->binmode([LAYER])'; my($fh, $layer) = @_; return binmode $$fh unless $layer; return binmode $$fh, $layer; }
        and where in my code must I set this?, srry, I'm still a rooky in perl. just 3 weeks of experience with this...