procmail
[Top] [All Lists]

Re: Please help with questions about Procmail as a filter...

1998-05-19 03:39:34
George Marshall wrote:

1. SEND MAIL TO DEFAULT FILE WITH HEADER INFORMATION AS
   NORMAL, AND/OR GROUP FORWARD WITHOUT HEADERS
 
From time to time I receive e-mail regarding special
subjects that I wish to receive in my default mail
collection directory normally, PLUS sometimes forward to
a group of other people without including the original
header information in the forwarded mail.
  The "c" flag clones the current message.  This allows the
regular copy to yourself and a copy to the group.  You can
*NOT* send an email message without headers.  The mail-
handler won't know wht to do with it.  However, you can use
"formail" to over-write the old headers, or if you're
really hard-working, compose a new set of headers altogether.
You can "man formail" on a unix system to get an idea of how
it works.  I use it on this list to force the "Reply-To:"
address as procmail(_at_)informatik(_dot_)RWTH-Aachen(_dot_)DE rather than
the sender's name.  This message is one of the very few times
I'm over-riding that.  Here's my recipe...

:0 fhw
* ^Resent-Sender: procmail-request(_at_)Informatik\(_dot_)RWTH-Aachen\(_dot_)DE
* !^Reply-To:(_dot_)procmail(_at_)Informatik\(_dot_)RWTH-Aachen\(_dot_)DE
  | formail -i "Reply-To: procmail(_at_)informatik(_dot_)RWTH-Aachen(_dot_)DE"

Let's say you have a list of subject strings you want.  Note
that procmail's string comparisons are *NOT* case sensitive
by default, although you can over-ride that default.

###################
MYSUBJECTS="(spam|\
procmail|\
blah blah blah)"

:0
*$ ^Subject:.*$MYSUBJECTS
* !^X-Loop: George's list
# Make damn sure to put in an identical X-Loop:
# header with formail.  This is designed to avoid
# messy "endless loops" when things go wrong.
{
:0 c
 formail <with appropriate parameters>
 ! john(_at_)some(_dot_)isp(_dot_)com jane(_at_)another(_dot_)isp(_dot_)net 
<etc,etc,etc>
}
###################

2. FILTER MAIL FROM SELECTED SENDER OR HOST *EXCEPT*
   WHEN THE SUBJECT LINE CONTAINS SELECTED CHARACTERS

Can I simply alter my .procmailrc file so that mail from
*(_at_)abc(_dot_)com, for example, will go to my default mail directory
as normal, UNLESS the subject line contains offending
characters, such as FREE OFFER or MONEY MAKER, in which case
the mail would be sent to another designated file?

  Simple...
###################
MYSUBJECTS="(free offer|\
money maker|\
blah blah blah)"

:0:
*$ ^Subject:.*$MYSUBJECTS
junkmail
###################

3. AUTOMATIC FILTER TO DESIGNATED FILE *PLUS* RETURN TO
     SENDER'S ISP WITH A GENERIC MESSAGE FROM ME?
From time to time I receive mail from various e-mail junk
mailers, and I wish to simply forward their mail with
complete headers to their Internet service provider (such as
postmaster(_at_)sender's host.com), along with a request that the
provider investigate and take appropriate action. I also wish
to keep a full copy of the offending e-mail for my records.
  Don't even *THINK* about it.  Spammers are getting very
ingenious about forging headers and covering their tracks.  I
don't see how it's possible to code in enough intelligence
into a procmail filter to cover the possibilities.  Then there
are some ancient mainframes running obsolete versions of
sendmail that don't do an RDNS on relay spammers.  You simply
don't know where the original message came from.

4. THE PURPOSE OF THE SECOND COLON (:) IN THE .PROCMAILRC RECIPES

What is the purpose of the second (:) ? My Internet Service
Provider suggests that my recipes should include a second
colon (:) in the first line, like this:
  This is a lockfile request, to prevent more than one recipe
or process from accessing a file at the same time, and totally
scrambling it.  You only have have to do this for recipes that
write to a physical disk file, like the "nn-list" example.  Any
recipe that dumps to /dev/null, forwards a message to a program,
or another address, does not need a lockfile.  


5. DIRECTING MAIL THAT IS ADDRESSED TO ME GENERICALLY RATHER
   THAN SPECIFICALLY

Occasionally I receive junk e-mail that is not addressed to
me specifically, but instead is addressed to something like
friend(_at_)myhost(_dot_)com(_dot_) Currently, the way I deal with this is:

:0
 *friend@
/dev/null

However, I would like to make a recipe that is more specific,
to say that if my actual e-mail address is not either the
addressee, the CC or BCC addressee of the e-mail, the mail is
then deposited in the alternate directory of my choice (which
may or may not be /dev/null).
  OK, but watch out that you don't dump mailing lists that you
have subscribed to.  Procmail has a built-in environmental
variable LOGNAME that automatically resolves to your logon name,
in your case "georgem".  I also define a couple of variables
called MYLISTS and MYISP.  In your case the MYISP line would be
  MYISP="eskimo\.com"
Mine is uglier because my ISP owns both interlog.com and
interlog.net domains.  MYLISTS includes strings that match
a line from each mailing list you subscribe to.

MYISP="interlog\.(com|net)"
MYLISTS="(^X-Loop:.procmail|\
^From:.risks@)"
:0
*$!^(Sender|From|Reply-To):.*$MYISP
*$!^(Apparently.*|To|Cc):(_dot_)*$LOGNAME(_at_)$MYISP
{
DIAGNOSTIC="///////////////////// Not addressed to me"

:0:
| echo $DIAGNOSTIC>>junkmail ; cat - >>junkmail
}

 The entire mess between the braces (including the braces)
could be replaced with one line

junkmail

but I have several recipe's that can reject messages.  So I
want a diagnostic message with each reject.  It makes things
easier when I get false positives.  Right away I know which
of several recipe's is doing the rejection.

6.      THE MYSTERY OF THE LEADING *ASTERISK*
Meanwhile, including this character works for their staff
members personally. However, when I try writing my recipes
this way, Procmail stops working for me altogether! I am
reluctant to change my .procmailrc file to their method
because mine is now working. Why would their method work
for some and not for me?
  There may be two or more versions of procmail on your ISP's
system, and you may be running the ancient one.  Ask your
ISP to look at your .forward file to see if it points to the
right version.  Note also that the changes you have to make
to get to the current syntax...
 1) put a "*" in front of each condition line
 2) remove the linecount from the top of the recipe
################
:1Hw:
 ^Subject.*\$\$
/dev/null

becomes
################
:Hw:
* ^Subject.*\$\$
/dev/null

Your patience with me (the novice!) and your insights into
these questions are greatly appreciated. I eagerly await
your response.
  Could you please have a look at my "SpamDunk Project" page
http://www.interlog.com/~waltdnes/spamdunk/spamdunk.htm
and let me know how it looks to a relative beginner.  I've
attempted to create a generic procmail setup that can be
used even by people from a DOS/Windows background.  I was a
newbie a few months ago myself.  I find that as I get more
expert in a computer subject, it gets harder to explain to
beginners.  I end up assuming stuff that they don't know.
An opinion from a relative beginner like yourself would be
useful in knowing how well I did the website.

-- 
Walter Dnes (Toronto)
<waltdnes(_at_)interlog(_dot_)com>

<Prev in Thread] Current Thread [Next in Thread>