You're viewing a comment by Stuart Marmorstein and its responses.

May 15, 2013, 22:20

A regex question for making this practical: I receive these message files when I use my getmail program to check mail from Some of my spam is written to other addresses besides contact. Anything like that WOULD be spam. How would I make one of my spam_keyword entries be "other-than-contact"

Thanks! Stuart

Comment Responses

May 22, 2013, 19:37

Hi Stuart,

Here's how you make one of your spam_keyword entries be "other-than-contact"

use warnings;
use strict;

my @files = <msg*.txt>;
open my $out, '>', 'spam-emails.txt' or die 'failed opening spam-emails.txt: ' . $!;

for my $file (@files) {
  my $contents = do {
    open my $fh, '<', $file or die 'error opening ' . $filename . ': ' . $!;
    local $/; <$fh>
  $_ = $contents;
  unless (/ {
    print $out qq/$file\n/;
  if (/spam_keyword_1/ || /spam_keyword_2/ || /spam_keyword_3/) {
    print $out qq/$file\n/;

Make sure that is in the email when doing this.

What the "unless" line does is it checks if is NOT the email, and if it is NOT, then print it to spam file, and proceed the next email. ("unless (x) { ... }" means "if (!x) { ... }" in Perl).

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "browser_303": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.