procmail
[Top] [All Lists]

Re: how to use file to block several user

2005-01-05 09:04:15
Rakesh Man Karmacharya wrote:

<> I am new in procmail
<> I can block mail from individual user but i want to block several users .And
<> i heared that we can list all the users in a file and we can block their
<> mails
<> so plz any one can help me how to do?

You can find this in the procmail archives (Follow the link from
www.procmail.org and use the search feature).  Here's a new entry for
the search <g>:

  BITBUCKET="/dev/null"                 # Set this to something besides the
                                        # bitbucket until you are sure the
                                        # recipe does what you want!!

  BLACKLIST="$HOME/blacklist.txt"       # Or wherever you want to store your
                                        # blacklist file.


  FROM=|formail -IReply-To: -rtzxTo:    # Get a clean From

  :0
  * ? fgrep -xqis "$FROM" $BLACKLIST
  $BITBUCKET

This recipe searches a file ($BLACKLIST) for a line that matches the
sender address in an incoming email.  The search is done by the fgrep
program (not part of procmail, but installed on every unix in creation).
procmail checks the return code (exit code) of fgrep to see whether
fgrep found the address in the file or not. If it didn't, procmail goes
on. If the address was in the file, then procmail writes the message out
to the location defined in $BITBUCKET and exits.

Make sure you put addresses into the $BLACKLIST file like this:

  johndoe(_at_)example(_dot_)org
  prince_john(_at_)sherwood(_dot_)com

(Ie., strip off any text and just use the address part)

What the fgrep flags mean:

  The "-x" flag to grep tells it to return ONLY a match against the whole
  line.  So, for example, if you had the line "johndoe(_at_)example(_dot_)org" 
in the
  blacklist file and received mail from "doe(_at_)example(_dot_)org" the -x flag
  prevents a match. Which is good.

  The "-q" tells grep to not return anything on standard out. You only
  want to see the exit code. (Unix programs typically return some data
  and set a variable in the shell that informs whether the program was
  successful ($? = 0) or not ($? != 0).  -q suppresses that output.

  The "-i" tells grep to ignore the case of the strings.  Ordinarily,
  "JohnDoe(_at_)Example(_dot_)org" and "johndoe(_at_)example(_dot_)org" 
wouldn't match. With
  "-i" they do.  Email is case insensitive, so you want the comparison
  to also be insensitive.

  The "-s" tells grep to ignore files that don't exist or can't be read.
  If you delete your blacklist file, you don't want ALL your email going
  to the bitbucket so it is vital to tell grep that the lack of the file
  isn't an error. (Umm. "Ooops")

Reto
-- 
R A Lichtensteiger      rali(_at_)tifosi(_dot_)com

        "Vote, n. The instrument and symbol of a freeman's power to make a
           fool of himself and a wreck of his country." - Ambrose Bierce

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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