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

Hi all,

I have a problem with "MIME::Parser" package

The problem is that when the email has an attachment with a brackets ( or ) in filename the package stores the file with wrong name in system directory.Let me show the example:

THE CODE IS THAT:

# -------------------------------------------------------------------- +-------------------- use MIME::Parser; $tmp_dir = "/tmp"; $tmp_dir = $tmp_dir.'/'."$$" while -d $tmp_dir; $message_source = 'From root@domainname.localdomain Mon Nov 27 19 +:42:47 2006 Return-Path: <root@domainname.localdomain> Received: from domainname.localdomain (domainname.localdomain [127.0.0 +.1]) by domainname.localdomain (8.13.7/8.13.7) with ESMTP id kARHgljo02 +5235 for <root@domainname.localdomain>; Mon, 27 Nov 2006 19:42:47 +0200 Received: (from root@localhost) by domainname.localdomain (8.13.7/8.13.7/Submit) id kARHglZA025234 for root@localhost; Mon, 27 Nov 2006 19:42:47 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_001_01C7070D.D848F424" Subject: email subject Date: Mon, 13 Nov 2006 10:26:06 -0000 Message-ID: <E27D9DB1DAC80A4EBA2761F3F12F5ACCEDCE37@zuk35exm60.ds.ttt. +com> From: test@test.com To: test@tete.com This is a multi-part message in MIME format. ------_=_NextPart_001_01C7070D.D848F424 Content-Type: multipart/alternative; boundary="----_=_NextPart_002_01C7070D.D848F424" ------_=_NextPart_002_01C7070D.D848F424 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable DM for is attached (56287) ------_=_NextPart_002_01C7070D.D848F424 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Dus-ascii"> <META content=3D"MSHTML 6.00.2900.2963" name=3DGENERATOR></HEAD> <BODY> <DIV><SPAN class=3D990191810-13112006><FONT face=3DArial size=3D2>DM f +or = is attached=20 (56287)</FONT></SPAN></DIV></BODY></HTML> ------_=_NextPart_002_01C7070D.D848F424-- ------_=_NextPart_001_01C7070D.D848F424 Content-Type: application/msword; name="test ().doc" Content-Transfer-Encoding: base64 Content-Description: test ().doc Content-Disposition: attachment; filename="test ().doc" ------_=_NextPart_001_01C7070D.D848F424--'; my $parser = MIME::Parser->new(); $parser->extract_nested_messages(0); $parser->output_dir($tmp_dir); $entity = $parser->parse_data($message_source); for(glob("$tmp_dir/*")) { # ..... } rmtree("$tmp_dir", 0); # -------------------------------------------------------------------- +--------------------

THE PROBLEM IS WHEN STORE ATTACHMENT WITH "TEST ().DOC" NAME THE CREATED FILE HAS NAME: TEST %28%29.DOC

CAN SOMEONE HELP ME?

THANKS IN ADVANCE.

Edited (davorg): fixed formatting

Replies are listed 'Best First'.
Re: Problem with MIME::Parser
by davorg (Chancellor) on Nov 28, 2006 at 11:51 UTC

    Please read Writeup Formatting Tips for advice on how to make your posts as readable as possible. Enclosing your whole post in <pre> tags makes it harder to read.

    It looks like you might need to write a subclass of MIME::Parser::Filer that works as you expect. In particular you'll want to override the methods evil_filename and/or exorcise_filename.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg