pawan has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone I am trying to decode and extract (image/jpg) attachments from emails/usenet postings. Using MIME::Parser and MIME::Entity->parts(), I have been able to access the individiual attachments as entities, when i print them using MIME::Entity->print(), I am able to see the header, which displayes the encoding used, Base64, followed by the encoded data. When i gather the encoded data using MIME::Entity->print_body() in a string and try decoding it using MIME::Base64::base64_decoder(), the resulting output when written to file is not a valid .jpg I would appreicate any help in solving the problem. Also some images are uuencoded, is there a CPAN module, which detects the encoding and is able to apply the appropriate decoder? Thanks pawan

Replies are listed 'Best First'.
Re: decoding (image/jpg) attachments
by Corion (Patriarch) on Feb 11, 2004 at 09:42 UTC

    I did not have any problems using the MIME modules to look at attached files, but possibly you are using Windows or a recent Perl, and then to write the data, you must use binmode before writing your binary data to the file:

    open OUT, "> $filename" or die "Couldn't write attachment to '$filename' : $!"; binmode OUT; print OUT $attachment_data; close OUT;
      I used the binmode option and it works. Thanks Pawan
Re: decoding (image/jpg) attachments
by kvale (Monsignor) on Feb 11, 2004 at 09:22 UTC
    I don't know what to say about the MIME problem, except that showing us the code in question may help in debugging it.

    Convert::UU can uudecode a string or file.

    -Mark