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

Hi.

I'm trying to retrieve an attachment from an email. I've tried using the MIME modules, but can't get this working right.

The following is the email's content...

This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C210A9.5C28F260
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0008_01C210A9.5C28F260"




------=_NextPart_001_0008_01C210A9.5C28F260
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi This is a test. Ralph.

------=_NextPart_001_0008_01C210A9.5C28F260
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



http-equiv=3DContent-Type>






Hi This is a test.=20
Ralph.


------=_NextPart_001_0008_01C210A9.5C28F260--

------=_NextPart_000_0007_01C210A9.5C28F260
Content-Type: image/gif;
name="antipodi.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="antipodi.gif"

R0lGODlheAARAKIAAPbNzfvo6P////GqquRZWdwsLNkZGdYBASwAAAAAeAARAAAD/ii60LCQtSiC
gy7rp+zEGxBQEUAUhlEQA1mFHOnF3WEfo3wT0WDztZtQCBQAbhHD8GZoUQIEWwGFOhRoCt/yYCDk
INpDT+h8CmnaYmA7LB5tSbatrACsWJWCotscyw1fWUgQBUJ6OjeHggdFAgOPA1FzkDFvYhBKjJAE
mTgLAQUDoI+cpKJ9C1pNm4l+l3U2KTZYQTdlaS5hLpZxB3SWZVEnqwOrnFOKjlKudLoLkgTQiEI5
uCTOFLyYcxG2NQQAkQuHoAE+t8sRhYxggxU3DTeBQSo/i43tcCTaC5m/3spaPBpHcE0RLckWGcj3
CqGCdfjecQGmjN01dyUwCsgE/i5cMXkKOD1gEaBkgZKgHipy6IrhOG4VF0ZYw0WAJEDWKGDLqK+f
HF/PrFCJJuyE0JqLElZ8tXSRJ4lAIdCUCTFny30aOw1BFdLAg4EPCQqYkiqdy7L6JHFJ0SnhVKfS
LvbkyXTjD0gDaJ1zVEbRoS5olapySfMnjbch2+TSyCArTBfvvIgLm8dc1IpK4zqNSZQoR6mxPmmN
uBnrXLuXIQtDASlUJBVkA9NthsSfTpD0GFq8fbrxaduQO/RxzYlFqABe8xGL1IphmHlQyyAOak9u
Xd91gQc3cqdFyo0DQrnaAsiV5giSFE0XXp33dVi/H2+HIoWKEvHjhXSBHsYBG/QOF0hASwYuzFBg
gAL+B5kJKKiAhwwwQDZDAgA7

------=_NextPart_000_0007_01C210A9.5C28F260--

How can I retrieve the gif file from all this data?

The MIME module is really complex, and I can't seem to get this working in any way.

Please help.

Thanks,
Ralph.

Replies are listed 'Best First'.
Re: MIME Problem with Email
by dree (Monsignor) on Jun 11, 2002 at 09:51 UTC
    Use MIME::Tools.
    In particular try:
    use strict; use MIME::Parser; my $parser = new MIME::Parser; $parser->output_under("./"); #directory where to store the components my $entity = $parser->parse(\*STDIN) or die "parse failed\n"; $entity->dump_skeleton;
    and from the console, write:
    $perl abovecode.pl < mail.txt
    So in ./ you'll find a directory like "msg-10237 (cut) 2055-0" in which you have the components.