I currently have a perl script that removes a pdf attatchment from an email sent to a specific account and runs it through various processes. I also parses various parts of the attatchment name to determine how to handle the attatchment.

The problem I am having is often the attatchment name will have brackets in it, i.e. 01267-OHN-CC-000088733[1].pdf and for some reason if it has these brackets it wont read the file name. Instead of $var = 01267-OHN-CC-000088733[1].pdf it equals -1.pdf or -2.pdf (the number depending on how many other files are already in that folder with the blank .pdf name). If the attatcment name does not have the brackets it reads the attatchment name no problem.

If I do a $entity->dump_skeleton I get the following output:
OUTPUT: Num-parts: 2 -- Content-type: multipart/alternative Effective-type: multipart/alternative Body-file: NONE Num-parts: 2 -- Content-type: text/plain Effective-type: text/plain Body-file: this/is/my/path/2006-02-17/msg-32404-1.txt -- Content-type: text/html Effective-type: text/html Body-file: this/is/my/path/saved/2006-02-17/msg-32404-2.html -- Content-type: application/octet-stream Effective-type: application/octet-stream Body-file: this/is/my/path/saved/2006-02-17/-3.pdf Recommended-filename: 01267-TXN-CC-000086475[1].pdf

So it appears its showing the right file name in

Recommended-filename: 01267-TXN-CC-000086475[1].pdf

I am just not sure how to get that value instead of what I currently get in

Body-file: this/is/my/path/saved/2006-02-17/-3.pdf

Here is the code snippet how I currently extract the file name

# create a MIME::Parser object to # extract any attachments found within. my $parser = new MIME::Parser; $parser->output_dir( $savedir ); my $entity = $parser->parse_data($msg); # extract our mime parts and go through each one. my @parts = $entity->parts; foreach my $part (@parts) { # determine the path to the file in question. my $path = ($part->bodyhandle) ? $part->bodyhandle->path : undef +; print "This is the $path \n"; #right here if it doesnt have the + brackets it will give the correct file name if it does it will come +back -1.pdf or some other count

In reply to file attatchment name by bobdole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.