procmail
[Top] [All Lists]

Re: procmail blues: grepping from /etc/passwd for "SEND" users...

2002-12-26 15:39:21
At 00:33 2002-12-27 +0300, poff(_at_)sixbit(_dot_)org wrote:
From: Rex Ruthers <rex>
        (a user using "mail" which doesnt set domain or anything)

Unless I have exceptions coded, I typically treat messages which do not contain an @domain as spam.

:0:
* ? formail -x"From:" | egrep -if $HOME/mail/.school-friends
school-friends

where .school-friends is the white list.

This is how most people implement whitelists. It's a compact condition line, not involving longhand scripting necessary to do it other ways.

First Q - is this an efficient way for handling the "whitelist"?

It's a reasonably efficient manner of doing it from a file. You could streamline the processing somewhat by extracting the From: into a variable using procmail code (which doesn't involve spawning other processes):

:0
* ^From:[       ]*\/[^   ].
{
        FROM=$MATCH
}

# if $MAILDIR is set to $HOME/mail already, then you don't need to specify
# it on the egrep - it is basically the working directory.
:0:
* egrep -i "${FROM}" $HOME/mail/.school-friends
school-friends

A liability here may be mismatched quotes - I don't do things this way myself. I do some things like so:

:0h
FAILKEY=| (formail -xFrom: | $MEGAGREP -i -f $GREENLIST)

# If failkey is blank, we didn't match anything in the greenlist
:0
* FAILKEY ?? ^^^^
{
        # do something
}

This takes the matched text and stores it into the FAILKEY variable, so I can manipulate it within my conditions. Otherwise, this is rather indifferent from how you're running your check.

Note that the difference in efficiency is probably only significant to seriously underpowered/overloaded systems.

I can think of setting FROM=`formail -x"From:"` then * ? grep -i "$FROM"
/whitelist

No need to use formail to extract the variable - at that point, you're still invoking an external process (although saving yourself the shell necessary for the intermediate pipe, I believe).

Next problem, this user-without-a-domain name...

Check your From_ header.

or something but I don't know how in procmail-syntax

:0
* ! USER ?? ^^^^
* ? grep -i "$USER" /etc/passwd
"sdf'ers"

Since conditions are AND'ed, and the first one sequentially which fails will cause the recipe to not match, if USER is empty (^^^^), then it won't match the INVERTED (!) check for emptyness, and therefore the grep won't even be conducted.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail