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 contact@drstuart.net. Some of my spam is written to other @drstuart.net addresses besides contact. Anything like that WOULD be spam. How would I make one of my spam_keyword entries be "other-than-contact"@drstuart.net?

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"@drstuart.net.

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 (/contact@drstuart.net/) {
    print $out qq/$file\n/;
    next;
  }
  if (/spam_keyword_1/ || /spam_keyword_2/ || /spam_keyword_3/) {
    print $out qq/$file\n/;
  }
}

Make sure that contact@drstuart.net is in the email when doing this.

What the "unless" line does is it checks if contact@drstuart.net 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 name, if you have one. (I'm @pkrumins, btw.))

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

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