#this subroutine goes through a meassage until # all its body parts are dissected and printed sub getAttachments { my $numAttachments = $_[0]->parts; for (my $i = 0; $i < $numAttachments; $i++) { my $attachment = $_[0]->parts($i); #print the attachment preamble my $lineCounter = 0; my $att_preamble = $attachment->preamble; foreach (@$att_preamble) { $msgData->{"attachmentdata"} = $msgData->{"attachmentdata"} + "$$att_preamble[$lineCounter++]\n"; } $lineCounter = 0; #print the attachment header my $att_header = $attachment->head; $msgData->{"attachmentdata"} = $msgData->{"attachmentdata"}.$att_header->as_string; #print the body my $att_body = $attachment->bodyhandle; if (defined($att_body)) { $msgData->{"attachmentdata"} = $msgData->{"attachmentdata"}.$att_body->as_string; print $msgData->{"attachmentdata"}."\n"; $msgData->{"attachmentdata"} =~ s/'/''/mg; #$msgData->{"attachmentdata"} =~ s/&/$ordValue/mg; } if ($attachment->parts() > 0) { getAttachments(\$attachment) } } }