I have a perl program that I put together and I am having problems extracting attachments with file names with a "/". I just get a blank name. Here is the code I am using.
#get email body if ($entity->parts > 0){ for ($i=0; $i<$entity->parts; $i++){ $subentity = $entity->parts($i); if (($subentity->mime_type =~ m/text\/html/i) || ($subenti +ty->mime_type =~ m/text\/plain/i)){ $body = join "", @{$subentity->body}; next; } #this elsif is needed for Outlook's nasty multipart/altern +ative messages elsif ($subentity->mime_type =~ m/multipart\/alternative/i +){ $body = join "", @{$subentity->body}; #split html and text parts @body = split /------=_NextPart_\S*\n/, $body; #assign the first part of the message, #hopefully the text, part as the body $body = $body[1]; #remove leading headers from body $body =~ s/^Content-Type.*Content-Transfer-Encoding.*? +\n+//is; next; } #grab attachment name and contents foreach $x (@attypes) { if ($subentity->mime_type =~ m/$x/i){ $bh = $subentity->bodyhandle; $attachment = $bh->as_string; push @attachment, $attachment; push @attname, $subentity->head->mime_attr('conten +t-disposition.filename'); }else{ #some clients send attachments as application/x-ty +pe. #checks for that $newx = $x; $newx =~ s/application\/(.*)/application\/x-$1/i; if ($subentity->mime_type =~ m/$newx/i){ $bh = $subentity->bodyhandle; $attachment = $bh->as_string; push @attachment, $attachment; push @attname, $subentity->head->mime_attr('co +ntent-disposition.filename'); } } } $nooatt = $#attachment + 1; } }
Here is the header
MIME-Version: 1.0 Importance: Normal X-Priority: 3 (Normal) X-Mailer: SAP NetWeaver 7.02 Content-Type: application/pdf; name="Payment Advice Note from 03/31/2014.PDF" Content-Transfer-Encoding: base64 Content-Description: Payment Advice Note from 03/31/2014 Return-Path: APBATCH@xxxxxxxxxxx.com X-OriginatorOrg: xxxxxxxxxxx.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn%

In reply to extracting email attachments by jrtaylor

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.