Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Note: written before parent node was updated.

Good idea, but far less than enough hubris. You can replace the entire repetitive beginning of the script by just a few lines:

sub make_rx_from { open my $fh, "<", shift or warn("Can't open fromgood $!\n"), retur +n; chomp(my @line = <$fh>); return map qr/$_/, @line; } my @togood = make_rx_from "togood"; my @receivedgood = make_rx_from "receivedgood"; my @badcontent = make_rx_from "contentbad"; my @maillists = make_rx_from "maillist"; my @badwords = make_rx_from "badwords"; my @frombad = make_rx_from "frombad"; my @fromgood = make_rx_from "fromgood";
But that's still far from ideal. Look at your code's main loop: you are examining a specific header, testing it against a whitelist and a blacklist, flagging accordingly. The same pattern every time. That can be factored out along these lines:
HEADER: foreach my $line (@$messref) { # detects first blank line go do body check of first 10 body lines last if $line =~ /^\s*$/; my ($header) = grep $line =~ /^$_:/i, keys %test_for; next unless $header; for my $test (qw(ok bad)) { my @match = grep $line =~ $_, @{ $test_for{$header}{$test} }; next if not @match; $flag = $test; print "Message $test - header $header matched: @match\n"; last HEADER; } }
You could also check the message size prior to any other tests for efficiency. I'll post the complete code as I refactored it in a separate node, for easier downloading.

Makeshifts last the longest.

In reply to Re: dialup spam removal with Net::POP3 (program repair shop) by Aristotle
in thread dialup spam removal with Net::POP3 by zentara

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2023-03-31 15:34 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (76 votes). Check out past polls.