Procmail on IgLou
-----------------------------------------------------------------------
                    The FAQ For Using Procmail on Iglou

                           v0.03 - July 30, 1997

                   by Robert Goodwin (rsg0910@iglou.com)
-----------------------------------------------------------------------


Table of Contents
=================
1.0    Why this FAQ?
2.0    What is procmail?
3.0    Why should I use it?
4.0    Requirements for using procmail
5.0    Setting up procmail
  5.1  Setting up your .procmailrc file
  5.2  Setting up your .forward file
  5.3  Testing your setup
6.0    How does it work?
7.0    Other procmail things you can do
  7.1.0 Bouncing the message
    7.1.1  Bouncing it back to one or more users
    7.1.2  Bouncing it back no matter who sent it
    7.1.3  Bouncing combinations
  7.2  Instead of the headers, check the body
  7.3  Using commands and cutting down the size of the file
    7.3.1  Reading from an external file
    7.3.2  Setting up a file request system of sorts
    7.3.3  Setting up a mailing list
  7.4.0  Combinations of the above and other commands
    7.4.1  A better mailing list
    7.4.2  Making sure you don't bounce a legitimate email
8.0    Suggestions, tips, etc...
9.0    Extra online help
10.0   Contributors and thanks


1.0  Why this FAQ?

Many of you have been wondering how to use procmail on IgLou, since some of
you would rather go for it than MailBlock or MailBlock Select. I've written
this file just for the rest of you who wish to use it. So, have a seat, sit
back, and relax!

This will also be found in my homepage, until Iglou either hires me or
allows me to place it in a more publicly-viewed area.

http://members.iglou.com/rsg0910/ig-proc.faq.html


2.0  What is procmail?

Procmail is a general-purpose mail filter program, that can be used with
any email reading utility, no matter what you use. IgLou uses version 3.03,
rather than the newer 3.11pre7 version.


3.0  Why should I use it?

Do you get spam email, unsolicited email, as well as just plain junk mail
that you don't even want, yet it keeps coming into your box the way the
Energizer Bunny keeps going and going? That's why. You don't want it, it's
annoying, and a bazillion other reasons you can think of. You're the one
who creates and maintains the filter file. This makes it loads better than
MailBlock, which is maintained by the IgLou techs. While I've not used the
MailBlock Select, my feeling is that it's still a little limited.


4.0  Requirements for using procmail

So far, it seems you need a shell account, whether or not you're in the
menus or sitting directly in the shell. You do need some patience, as some
junkmails will make it past your filters, not to mention a little time.

This FAQ cannot even begin to list all the commands, but examples will be
given and posted as it is written.


5.0  Setting up procmail

Everything you have to do, must be done in your account, in your main
directory, unless otherwise mentioned.


5.1  Setting up your .procmailrc file

You will need to create the .procmailrc file, with your favorite editor.

   #Set on when debugging
   VERBOSE=off

   #Replace `mail' with your mail directory (Pine uses mail, Elm uses Mail)

   #You can easily use a different directory of your own, just for the
   #procmail stuff. In this example case below, the file 'log' will be
   #found in your homepage, in your 'mail' directory.

   MAILDIR=$HOME/mail
   LOGFILE=$MAILDIR/log

   :0
   * ^Subject.*test
   testing

Note that the line above contains a zero (0), not the letter "oh".  For
now, don't worry about the meaning of this recipe. Save it normally. It
will be explained below.

WORD OF WARNING: If you set your VERBOSE= to on, then anything that is sent
to you, you will get it, and the sender will get a bounce. I'm not sure
why, but it seems to have something to do with IgLou's mail system. This
can cause problems for those on mailing lists.


5.2  Setting up your .forward file

   "| /usr/local/bin/procmail -f-"

Everything you see in that line above, including double quotes, is used.
Save this, and then you will need to make your .forward world readable and
your home directory world searchable in order for the mail transport agent
to "see" it.  To do this type:

      chmod 644 .forward
      chmod a+x .

Some FAQs out there show a .filter file that looks like it contains;

   "|IFS=' '| exec /usr/local/bin..."

In the case of IgLou's setups, the IFS command does not work. All that's
required is that the .forward file run the procmail program.


5.3  Testing your setup

Send yourself two test messages: one with `test' in the subject and one
without `test' in the subject.

Start your mailer (pine, elm, etc.) and check that the messages were
delivered correctly.  The one with `test' in the subject should be in the
folder you selected to receive the test messages, and the one without
`test' in the subject should be in your inbox.


6.0  How does it work?

The script you used above was;

  :0:
  * ^Subject.*test
  testing


The meaning of this recipe is:

Notation            Meaning
========            =======
:0                  Begin a recipe
  :                 Use a lock file (optional)
*                   Begin a condition
  ^                 Match the beginning of a line followed by....
   Subject          ``Subject:'' followed by....
           .        any character (.) followed by....
            *       0 or more of preceding character (any character in this
                       case) followed by....
              test  ``test''
testing             If successful match, put in the procmail folder you set
                    up in the earlier example, into a filename called
                    testing. It merely dumps the entire file in there.


7.0  Other procmail things you can do

Think procmail is limited? Not quite. It's pretty much unlimited, more
flexible than you think. In the above script, replace the 'testing' with;


7.1.0  Bouncing the message

7.1.1  Bouncing it back to one or more users

  ! username@domain.com

What it will do is bounce it right back to that email address. If there's
more than one, you can do this;

  ! address1,address2,address3,address4

...and so on. If you don't want to have to type in all those addresses all
the time for each entry, try this at the top of the .procmailrc;

  EMAILADDRESS='address1,address2,address3...'

Then change the ! line above with;

  ! $EMAILADDRESS

Saves loads of typing.


7.1.2  Bouncing it back no matter who sent it

But, there's going to be a time where you have a general-purpose entry, and
you don't want to have to search the headers for a valid email address, and
so on, which can take time. So, replace the bounceback address with;

  EXITCODE=xx

...where xx is a number. Below is the listing, from sysexits.h found in the
/usr/include directory, which is a C source code header, as part of the
sendmail library. This is merely a section, modified for easier reading.


64 - EX_USAGE -- The command was used incorrectly, e.g., with the wrong
     number of arguments, a bad flag, a bad syntax in a parameter, or
     whatever.
65 - EX_DATAERR -- The input data was incorrect in some way.  This should
     only be used for user's data & not system files.
66 - EX_NOINPUT -- An input file (not a system file) did not exist or was
     not readable.  This could also include errors like "No message" to a
     mailer (if it cared to catch it).
67 - EX_NOUSER -- The user specified did not exist.  This might be used for
     mail addresses or remote logins.
68 - EX_NOHOST -- The host specified did not exist.  This is used in mail
     addresses or network requests.
69 - EX_UNAVAILABLE -- A service is unavailable.  This can occur if a
     support program or file does not exist.  This can also be used as a
     catchall message when something you wanted to do doesn't work, but you
     don't know why.
70 - EX_SOFTWARE -- An internal software error has been detected.  This
     should be limited to non-operating system related errors as possible.
71 - EX_OSERR -- An operating system error has been detected.  This is
     intended to be used for such things as "cannot fork", "cannot create
     pipe", or the like.  It includes things like getuid returning a user
     that does not exist in the passwd file.
72 - EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, etc.)
     does not exist, cannot be opened, or has some sort of error (e.g.,
     syntax error).
73 - EX_CANTCREAT -- A (user specified) output file cannot be created.
74 - EX_IOERR -- An error occurred while doing I/O on some file.
75 - EX_TEMPFAIL -- temporary failure, indicating something that is not
     really an error.  In sendmail, this means that a mailer (e.g.) could
     not create a connection, and the request should be reattempted later.
76 - EX_PROTOCOL -- the remote system returned something that was "not
     possible" during a protocol exchange.
77 - EX_NOPERM -- You did not have sufficient permission to perform the
     operation.  This is not intended for file system problems, which
     should use NOINPUT or CANTCREAT, but rather for higher level
     permissions.  For example, kre uses this to restrict who students can
     send mail to.

So, in essence, the short script below will do just this;

     :0
     * ^From.*savetrees.com
     EXITCODE=75

It will check for all mail in the From: part of the header, compare it to
see if it's from savetrees.com, and if it is, bounce it back to them
telling there's a failure in the system somewhere, when there wasn't. Heck,
they're being mean to you, so you're being mean right back in their face.

The most popular setting is 77, permission denied.


7.1.3  Bouncing combinations

However, if you want to do multiple things, like bounce it, but you also
want to save it, put everything you want to do between curly braces.

     :0
     * ^From.*savetrees.com
     {
       EXITCODE=77

       :0 c
       ! $EMAILADDRESS

       :0
       savetrees
     }

What this will do is check the headers to see if it's from savetrees.com,
and if so then bounce it right back to the sender and send the message to
the addresses in EMAILADDRESS. The 'c' is required if you have more than
two things going on in the recipe. After it sends the message to all those
in EMAILADDRESS, it doesn't stop, but save it to the savetrees file in the
directory you set up earlier. That's a pretty mean one, eh? If you don't
want to save it to a file at all, just junk it, then replace the
'savetrees' file with /dev/null. Trashed. Blackholed. You get the idea.


7.2  Instead of the headers, check the body

All the above you read were written for the headers. Procmail defaults to
reading the headers, until you tell it to look elsewhere. The below script
will look for anything that has something to do with something sent by the
Extractor Pro junk.

     :0 B
     * Extractor Pro
     EXITCODE=77

Notice the :0 B. It's telling procmail to search the body of the message
instead of defaulting to the headers, and bounce it right back.

Finally, combinations of all the above can have some pretty impressive
results. But, you want to make sure you're setting all this up right, and
not bouncing legitimate email. Check the log file that procmail creates
every now and then, to see what's erroneously bounced.


7.3  Using commands and cutting down the size of the file

7.3.1  Reading from an external file

If you want to cut down the size of the procmailrc file, and put all your
domain bounces, etc., in a separate file, you can do this. Simply change
the * line that checks for your hit list to this;

  * ? fgrep -isp $HOME/procmaildir/hitlistname

What fgrep does is that it searches the hitlistname file for anything that
matches the headers of that message. You may wish to have a separate file
if you do bounces on different places, like one for the headers only, one
for the body only, and one for a combination of header and body. This can
easily cut down the size of your procmailrc file by quite a bit, in some
cases, at least half.


7.3.2  Setting up a file request system of sorts

There are people out there who don't have access to the web, and you may
not want to send them the files by hand.

  :0 h
  * !^Subject.*Re:
  * ^Subject.*filerequest filename
  | (/usr/local/bin/formail -rt ; \  cat filename) \
  | $SENDMAIL -oi -t

This is the most basic file requestor system you can have. What you're
doing is you're having it search in the Subject line for 'filerequest
filename' with filename being the requested file, in the second * line. If
it hits on this, it goes into formail, which regenerates a new header with
-r and trust the original headers, via -t, in looking for who it's from.
That means that the person sending you the request must use his own email
address, no faked ones. Then 'type out,' or cat, the filename into a
buffer, and via sendmail, send it to that person. The h in the first line
means to eliminate the headers.

However, if the other person replies with a thank you for the message, and
it doesn't have the first * line, it'll keep sending the file til someone
changes the subject line. What the first * line does is, to not send the
filename if it's a reply, thus preventing loops.

This is also great for those of you who are on vacation, letting people
know when you will be back. However, there's a little feature in the shell
called vacation. However, with a well-written procmail script, you may not
even require this. Read the man pages to see how it works.


7.3.3  Setting up a mailing list

This is one of the things you'll wish to do, but you'll want to be creative
in customizing the basic setup.

  :0
  * the list
  {
    :0 b
    ! mailing list name or list of people
  }

What this does is take the body of the incoming message, and send it to
everyone in the mailing list. If you have a number of people in the list,
you'll wish to change the line above to;

  ! $LIST

and make LIST="addresslist". If you have quite a few people in the list,
then you'll want to;

  ! `cat filename`

with filename being the addresses of people.


7.4.0  Combinations of the above and other commands

7.4.1  A better mailing list 

  :0
  * ? fgrep -isf $MAILIST
  {
    :0 b
    ! mailing list name or list of people
  }

This makes sure that all those subscribed to the list can send responses.
Everyone else won't even begin to have a chance.


7.4.2  Making sure you don't bounce a legitimate email

All the above won't help if you have legitimate email that gets bounced. If
you're talking with someone, either on a mailing list or a friend, about
someone who spammed you. Of course you're gonna tell them all the details,
and the person may reply back with those spammers in the reply, or the
other way around. Then it's gonna get bounced right back. However, there's
a way to prevent this.

  :0
  * ? fgrep -isf goodmail
  /usr/bin/username

What this does is check the goodmail file, and if there's any match, send
it right on to your emailbox, and quit processing. If it doesn't match, go
on with the processing of the rest of the procmail recipe. This is good
when you're on a mailing list, and your recipe keeps bouncing back mail
that contains stuff you don't want to hit your box. Guess what happens when
the list owner gets too many bounces? Yep. You get removed, and you have to
go through the subscribe process all over again.

Place this before the checking for spammers. That way, it'll just send the
legitimate mail in, and not bother with the rest.


8.0  Suggestions, tips, etc...

Nothing, and I mean, *NOTHING*, beats reading the man pages. You will want
to read up on procmail, procmailrc, procmailex, and procmailsc, as well as
sendmail, formail, and a few others.

When you first start running procmail, you will see in your log file an
error that says that it's enforcing stricter permissions on your mailbox.
That means that instead of chmod 660, which is the normal setup, it's a
600. That's normal. If you remove your .forward and .procmailrc files, you
must remember to set it back to 660, otherwise your mail will end up
floating around the queue, unsent, til you change it.


9.0  Extra online help

Web Page: http://www.jazzie.com/ii/internet/procmail/
          http://www.best.com/~ii/internet/procmail/ (mirror of above URL)

Man Pages:    procmail(1)   - autonomous mail processor
              procmailrc(5) - procmail rc file
              procmailex(5) - procmail rc file examples
              procmailsc(5) - procmail weighted scoring techique
              egrep(1)      - search file for regular expression (procmail
                              uses egrep-style regular exprssions along
                              with some of its own expressions like ^TO)
              formail(1)    - mail reformatter
              sendmail(8)   - send mail over the internet

Newsgroup:    comp.mail.misc

Mailing List: procmail@informatik.rwth-aachen.de
           Subscribe to the procmail mailing list by sending mail:
             To: procmail-request@informatik.rwth-aachen.de
             Subject: subscribe

Procmail Archives:
           Get a list of files available at the procmail mail server by
           sending mail:
             To: procmail-request@informatik.rwth-aachen.de
             Subject: archive ls

           Get Best of the Procmail mailing list by sending mail (you'll
           need gzip and a MIME-decoder to unpack it):
             To: procmail-request@informatik.rwth-aachen.de
             Subject: archive get best_of_procmail_list*

Reading the above best of procmail list archive can most easily help you
solve your problems, though it will be a fairly large file, about 2 megs.
It's worth the read if you take the time.


10.0  Contributors and thanks

Jeff McAdams (jeffm@iglou.com) and Dean Brooks (dean@iglou.com) assisted in
some questions I posed them, so I gotta thank them for their help. Some of
the above came from a mailing list, some from man pages, and others from a
FAQ, as well as other users, especially Steve Gustafson
(gustavus@iglou.com) for sharing his procmail script with me and a bit of
debugging when I ran into some rather weird problems.