Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: MIME::Tools to save attachment properly

by Corion (Patriarch)
on Jan 24, 2017 at 08:00 UTC ( [id://1180202]=note: print w/replies, xml ) Need Help??


in reply to Re: MIME::Tools to save attachment properly
in thread MIME::Tools to save attachment properly

Have you looked at the ->mime_type and the other attributes of the attachment?

Are you certain that the attachment itself is OK in the mail?

Have you inspected the raw data before parsing it? Maybe it is broken in some way that MIME::Parser doesn't handle?

Replies are listed 'Best First'.
Re^3: MIME::Tools to save attachment properly
by sachss (Sexton) on Jan 24, 2017 at 12:21 UTC

    I liked at ->mime_type which is "application/octet-stream", but I am not aware of other information options.

    The attachment in the actual email is fine as far as I can tell. I have about 46 emails, each with a single attachment, which is about 10 Mb, which composes a 460 Mb 7z file as a whole.

    How do I check the raw data? I thought that was what I was trying to output, which comes out as zero-length, although, spot-checking would suggest it might be being overwritten for some reason, as I do see a non-zero length during then zero-length at the end.

      I checked the $entity data through Dump::Data, and looks like an actual email. I did find that
      my $bh = $part->bodyhandle; print "MIME Type: $type\n";
      will outputs all the parts.

      But

      my $bh = $part->bodyhandle; print "MIME Type: $type\n"; if (defined $bh) { open(my $OUTFILE, ">", $bh->path) or die $!; binmode($OUTFILE); $bh->print(\$OUTFILE); close($OUTFILE); } #End IF $bh defined
      the $bh-print, seems to 'overwrite' the attachments making them zero-length.

      So I removed that part and my code works. I do need to look at MIME::Parser::Filer more to clean up my code.

      I do appreciate everyone's input and this wonderful site.

      I would look at the data you accumulate here:

      my $entity = $parser->parse_data(join '', @{$server->get($i)});

      And write that to a file and try to find out whether the attachment payload is malformed or whether there are two attachments with the same suggested output filename etc.

      If you suspect that the output file is overwritten, consider running your program under truss or strace to find the API calls that are made. Also consider looking at MIME::Parser::Filer to avoid using (or at least output) the filenames that come in the mail and give your own filenames if you suspect overwriting going on.

      Maybe you can also remove most of the base64 encoded payload (if it has been proven to be valid) and replace it by something much smaller that you can post here so we can try to reproduce your problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180202]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found