This piece of code is intended for those people that are using qmail, and which have set up a .qmail-default to have all email (other) addresses of a domain wind up in the same mailbox.

This behaviour has become very annoying when spammers just get a valid domain name and just start prefixing names they found somewhere else. You will then always get these in your mailbox. And because they don't bounce, some spammers will use that knowledge to conclude it's a valid email address and start using it again.

Of course, blacklisting these email addresses is pretty straightforward in qmail: just add the appropriate .qmail-.... file. But of course, we're lazy, so I devised a lazier way to do this.

Instead of having to login to a shell and go to the right directory and start creating the file, the only thing you need to do is do a "send again" of an offending email. You will receive that email then once more, but never again will you receive email on that address.

Theory of operation: add the line:

|./blacklist yourfrom@address.com
as the first line to your .qmail-default file. Keep the rest of the lines in there. Whenever a mail is received with "yourfrom@address.com" as the sender of the email, then it will put the addressee on the blacklist (by creating a .qmail-addressee and .qmail-addressee-default file that drops the email).

Lifting the blacklist is as easy as removing the appropriate .qmail-addressee files.

Put this code in a file named "blacklist" and make sure it is executable with your uid. You can name it anything you want and put it anywhere you want, as long as you adapt the first line in the .qmail-default file accordingly.

Thanks to batkins for unknowingly inspiring me to do this.

Liz

#!/usr/local/bin/perl exit 0 unless $ENV{'SENDER'} eq shift; # deliver normally if not th +e master my $dot = $ENV{'LOCAL'}; exit 0 if $dot =~ m#[^\w\-\.]#; # give up if strange charact +ers here exit 0 unless $dot =~ s#^$ENV{'USER'}-##; # drop user, fail if fails $dot = ".qmail-$dot"; foreach ('','-default') { # bare + extra garbage in na +mes next if -e ".qmail-$dot$_"; # we don't want to overwrite open OUT,">$dot$_" or die "Could not open '$dot$_': $!\n"; print OUT "#\n"; # enough for qmail to waste close OUT; } exit 0; # deliver this one normally

In reply to Easy blacklister for qmail by liz

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.