#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) || ($subentity->mime_type =~ m/text\/plain/i)){ $body = join "", @{$subentity->body}; next; } #this elsif is needed for Outlook's nasty multipart/alternative 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('content-disposition.filename'); }else{ #some clients send attachments as application/x-type. #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('content-disposition.filename'); } } } $nooatt = $#attachment + 1; } }