procmail
[Top] [All Lists]

recipe: process a list

2003-10-18 18:27:08
Suppose you have a variable Webhost, 
it may even have gotten its value like this:

  :0B
  * http://\/[^/?";'>: ]+
  {
    Webhost = "$MATCH"
    :0  # chip off userid@
    * Webhost ?? @\/.*
    { Webhost = "$MATCH"

    #do something with Webhost here
  }


And you want to find out if that Webhost 
is on one-or-more blacklists.

  xBLs
  rbls_pre
  rbls = "
first.blocklist.tld
second.blocklist.tld
-third.blocklist.tld
forth.blocklist.tld
"  
# see http://www.sdsc.edu/~jeff/spam/cbc.html
# see http://www.cluecentral.net  (geo-mapping of IP-nrs)

  INCLUDERC = "rblcheck.rc"

  # rblcheck.rc
  # -----------
  :0
  *$ rbls ?? ^^$\rbls_pre\/[  ]*[^  ]*([  ]|$)*
  * MATCH ?? > 0
  {
    rbls_pre = "$rbls_pre$MATCH"
    xBL

    :0
    * MATCH ?? ()\/[^  ]+
    { xBL = "$MATCH" }

    :0
    * xBL ?? ^^[^-]
    *! ?rblcheck -cq -s $xBL $WebHost
    { xBLs = "$xBLs,$this" }

    INCLUDERC = "$_"
  }
  # -----------

As ever, both [  ] and [^  ] contain a space and a tab.


The same result can be reached by:
1. Do a sed on $rbls to change it into "-s list1 -s list2 -s list4"; 
2. Call rblcheck once, with that full list-of-services;
3. Use sed -n to shape the output of #2 into $xBLs.

With the value of xBLs you can have formail add a header 
  X-rblcheck: $Webhost is listed in $xBLs (after you 
chipped of the 1st comma: * xBLs ?? ^^,\/.*)

The rblcheck is here: http://rblcheck.sourceforge.net/

You can use the same technique to convert some list into 
another, like turning a list of e-mail-addresses into a 
regex, even with the dots escaped. Often, sed is better.

-- 
Affijn, Ruud

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

<Prev in Thread] Current Thread [Next in Thread>
  • recipe: process a list, Ruud H.G. van Tol <=