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%