I would like some help with this concept in perl. I have a script that reads email from a POP3 server and uploads it to a database. The program works fine, excpept on messages that have a large number of attachments, I.E. a forwarded message that has been forwarded many times. The subroutine I wrote is recursive, and it crashes my machine if there are a large amount of messages of this type. So I adjusted the code to pass an object reference to the subroutine, thinking that would keep the routine from making another copy of the data each time it was called recursively. however when i did this I got the following error:Can't call method "parts" on unblessed reference at abusemail.pl line 57. I am using v5.8.2 built for i386-linux Code below:
#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->{"attachm
+entdata"} + "$$att_preamble[$lineCounter++]\n";
}
$lineCounter = 0;
#print the attachment header
my $att_header = $attachment->head;
$msgData->{"attachmentdata"} = $msgData->{"attachmentd
+ata"}.$att_header->as_string;
#print the body
my $att_body = $attachment->bodyhandle;
if (defined($att_body)) {
$msgData->{"attachmentdata"} = $msgData->{"attachm
+entdata"}.$att_body->as_string;
print $msgData->{"attachmentdata"}."\n";
$msgData->{"attachmentdata"} =~ s/'/''/mg;
#$msgData->{"attachmentdata"} =~ s/&/$ordValue/mg;
}
if ($attachment->parts() > 0) {
getAttachments(\$attachment)
}
}
}
Calling the routine with this:
getAttachments(\$mime_entity);
$mime_entity is a MIME::Entity object as per the module MIME::Parser
Thanks in advance.
Ketema
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.