I have a script which reads certain emails that are piped to it.

Here is the part that successfully gets the "body" of the message:
if ($MIME_entity->parts > 0) { for (my $i=0;$i<$MIME_entity->parts;$i++) { my $subEntity = $MIME_entity->parts($i); my $ignore_plain = 0; my $ignore_html = 0; $ishtml = "1" if $subEntity->mime_type eq 'text/html'; $ishtml = "0" if $subEntity->mime_type eq 'text/plain'; if (($subEntity->mime_type eq 'text/html') && ($ignore_htm +l == 0)) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_plain=1; } } if (($subEntity->mime_type eq 'text/plain') && ($ignore_pl +ain=0)) { if (my $io = $subEntity->open("r")) { while (defined($_=$io->getline)) { $_ =~ s/"/\"/g; $body .= $_; } $io->close; $ignore_html=1; } } } } else { $body = join "", @{$MIME_entity->body}; }
My question is this...
Why can't I split the body, when trying to get a certain piece of info?
Here is how I'm trying it. I first check the subject and body.
if (($to && ($to =~ /system_mail\@/)) && ($subject =~ /(mail failu +re|mail delivery failure|Mail delivery failed)/i && $body =~ /permane +nt error/i)) { Set_Mail_Failure($newfrom,$subject,$body); }
The purpose is to know if a registered user has canceled their email account, and has not updated it in our database. This way we do not send them any more to that email account, until they re-add that account and re-validate it.

Here is what I did with the Set_Mail_Failure sub.

sub Set_Mail_Failure { my ($_c_from,$_c_subject,$_c_body) = @_; $_temp_body = $_c_body; $_cntr = 0; foreach my $_lck (split /\015\012/, $_temp_body) { $_cntr++; $_lck =~ s/^\s+$//g; $_lck =~ s/\s+$//g; if ($_lck =~ /^To:/i) { ($_trash,$_actual_email) = split /\</, $_lck, 2; ($_actual_email,$_trash) = split /\>/, $_lck, 2; $_is_right_chk = $dbh->selectrow_array(qq{ SELECT `subscri +bed` FROM `reg_users` WHERE `email` = ? }, undef, $_actual_email); if ($_is_right_chk) { $_full_msg = $_c_subject . "\n\n" . $_c_body; $dbh->do (qq{ UPDATE registered_users SET subscribed = + ?, mail_failure = ?, mail_failure_msg = ? WHERE email = ?}, undef, 0, 1, $_full_msg, $_actual_email); open(FILE,">>show_results.txt") or die "Could not open + file... $!"; # Debug only print FILE "Found email to be $_actual_email - Now I'm + ending this and exiting...\n"; # Debug only close(FILE); # Debug only last; $dbh->disconnect() if $dbh; exit; } else { next; } } else { next; } } # Debugging only.... not going to stay. open(FILE2,">show_email.txt") or die "Could not open file... $!"; print FILE2 "$_c_body"; close(FILE2); open(FILE,">>show_results.txt") or die "Could not open file... $!" +; print FILE "I must have NOT found the email($_cntr lines)! I am fi +xing to exit!\nLast Line: $_lck\n"; close(FILE); exit; # Did not work, and since it was a error email, just ignore it a +nd exit... }
I know I'm not a "good" programmer, but it does work, except the Set_Mail_Failure. Well it works, however, I cannot get the "split" to work. I've tried these different ways:
split /\015\012/, $_temp_body split /\cM\cJ/, $_temp_body split /\r\n/, $_temp_body
None of them work :o(
Those are the different way's I've tried to split the foreach statement. I even tried a while statement and that had the same results.

Can you please tell me how or what is making it not split? The debug .txt file I have it create, has $_lck contain the WHOLE email body message.

I would really appreciate some help with this.
Thanks in advance for any assistance.

Richard

In reply to reading a email piped to a script.... by powerhouse

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.