in reply to Using MIME::Tools to save attachments

You're not showing what you do have, but I recommend reading the MIME::Tools perldocs, and in particular the docs about the parts()/parts_DFS(), body(), body_handle() methods. The MIME::Tools library is a pretty hairy beast. Some code I've recently written to save email messages including attachments to a database:
for my $p ($m->parts_DFS()) { # Skip 'container' parts next if $p->effective_type() =~ /^multipart/; $sth_insert_bdy->execute($key, $p->stringify_body(), $m->head->multipart_boundary || "", $p->head->mime_type || "", $p->head->mime_encoding || "", $p->head->recommended_filename || ""); }
The $m variable is a MIME::Entity object with the message and the attachment(s).

Replies are listed 'Best First'.
Re: Re: Using MIME::Tools to save attachments
by Lanthade (Initiate) on May 14, 2002 at 04:47 UTC
    Thanks for the tipe on the parts/parts_DFS procedures. Unfortunately they havn't gotten me anywhere. The mail message I'm dealing with has the following structure:
    X-POP3-Rcpt: hidden@hidden.org Received: from hidden (hidden [111.111.111.111]) by hidden.org (8.10.2/8.10.2) with ESMTP id g441dFH07987; Fri, 3 May 2002 21:39:15 -0400 From: "Hidden" <hidden@hidden.org> To: <hidden@hidden.org> Cc: <hidden@hidden.org> Subject: Hidden Date: Fri, 3 May 2002 20:52:30 -0500 Message-ID: <000801c1f30e$5aaccb90$0c0210ac@hidden.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0009_01C1F2E4.71D6C390" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.3416 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C1F2E4.71D6C390 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit # message here ------=_NextPart_000_0009_01C1F2E4.71D6C390 Content-Type: application/msword; name="File.DOC" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="File.DOC" # encoded datafile here ------=_NextPart_000_0009_01C1F2E4.71D6C390--
    The message is stored in an array and is obtained using the following code. The array is then fed into the parser entity parse_data():
    use Mail::POP3Client; use MIME::Parser; $pop = new Mail::POP3Client( USER => "hidden", PASSWORD=> "hidden", HOST => "hidden" ); @message = ($pop->Head(1),"\n",$pop->Body(1)); my $parser = new MIME::Parser; $entity = $parser->parse_data(\@message);
    I then try and do anything with that entity and I get nothing. The code creates a .txt file in the run directory with a size of 0.
    Any ideas what I'm doing wrong?
    Thanks!