Tips from The Answer Guy

Learn how to block mail your mail and tighten your security from The Answer Guy.

Netscape Mail Block

I need to refuse to accept e-mail from a particular person.
How can I configure Netscape and/or CND1.0 to bounce the person's
mail back to them? —Mitch, Mobile, Alabama

And the Answer Is...

I'd use procmail, a little programming language
written specifically for processing mail. CND uses procmail as the
“local delivery agent” by default. This means that sendmail
passes any mail for a local account to procmail, and then lets
procmail do the final delivery to your mail box,
/var/spool/mail/your_login_name. At the same time,
procmail checks for a .procmailrc file in your home directory, and
does some ownership and permissions checks on it for you.

The author of a .procmailrc file can specify a variety of
settings and clauses which are called “recipes”, and can also
modularize the file by using a variety of INCLUDE directives.
Here's a simple example that should get you started:

The :0 marks this as a new
recipe—each new recipe starts with this line. The
h and the r on that line are
flags tell procmail which parts of the message to hand to your
action line (i.e., the one that starts with a pipe, |).

h says: “Give me the
header.”

r says: “Treat the incoming
data as raw.”

The r flag is given to prevent your
response from failing if the sender has failed to put a blank line
at the end of his message.

The following four “star” lines in the script are
conditions. The first specifies that the header will show that the
message is “from” your spammer, that is, your unwanted sender.
This address will exactly match any “from” or “From:” line that
contains your target e-mail address. The next two lines of the
script ensure that you don't respond to daemons and mailers
(mailing lists). The last * line, which you should fill in with
your user name and host name, ensures that your don't respond to
your own response. Those three conditions are included to protect
your script from being tricked into undesirable actions. Consider
them to be the minimum overhead on any auto-responders that you
write.

The next line of the script, which starts with a “|” pipe
character, describes the action to take. In procmail there are
three types of actions:

A file name specifies an mbox
(elm, pine or mailx compatible) folder in which to store the
message.

A directory name specifies an mh
or mmdf folder for mail storage.
mh and mmdf use different
naming schemes for the messages in their folder directories, but
you don't need to worry about this difference unless you use one of
their mail user agents.

A ! (bang) line specifies an
e-mail address to which the message is to be bounced. A
| (pipe) line specifies that the message is to
be filtered through a local program.

formail is a program that comes with the
procmail package. It “formats mail headers”. This particular
formail command formats a “reply”
(-r) header, and adds two additional header
lines—a standard “Precedence: junk” line and a personal “X-”
line. The RFC822 spec allows you to use the X- line to embed custom
information into a header. It is also in the
formail command line that you prevent an attack
by routing your response back into your own script, i.e., a mail
loop.

The echo and cat
statements after the formail line provide output
that is appended after the mail header and that becomes the body of
your response. You can add additional echo lines or you can create
a file and use cat to add it here.

If you are new to procmail (which is almost certain given
your question—auto-responders are some of the first things that
procmail users learn), you may be nervous about breaking something
and losing some of your mail. To protect yourself you will want to
start your .procmailrc with the following simple recipe:

:0 c
fallback

This recipe, if it is the first recipe in the
script, appends a copy of every incoming message to a file named
fallback in your ~/Mail directory by default.
You can compare the contents of that folder to your inbox until you
are confident that everything is working as you expect.

Please read the procmail and procmailex (examples) man pages
for more details. The author, Stephen van der Berg, has also
written an automated mail list management package called SmartList
that is highly regarded among people that I know who have used it.
I like SmartList much better than Majordomo. —Jim

Trending Topics

Upcoming Webinar

Getting Started with DevOps - Including New Data on IT Performance from Puppet Labs 2015 State of DevOps Report

August 27, 2015
12:00 PM CDT

DevOps represents a profound change from the way most IT departments have traditionally worked: from siloed teams and high-anxiety releases to everyone collaborating on uneventful and more frequent releases of higher-quality code. It doesn't matter how large or small an organization is, or even whether it's historically slow moving or risk averse — there are ways to adopt DevOps sanely, and get measurable results in just weeks.