# junkfilter
# a junk email filter system for procmail 
# Copyright 1997-2002 Gregory Sutter <gsutter@zer0.org>
#
# $Id: junkfilter,v 2.41 2002/05/20 01:22:41 gsutter Exp $
#
# Please read the file "README" and the page
# http://junkfilter.zer0.org/ before using junkfilter.

# There shouldn't be anything in this file that is user-
# configured.  Check the "junkfilter.config" file for 
# all options.

# Get configuration options

INCLUDERC=$JFDIR/junkfilter.config

# Include personal configuration file, if it exists.

:0 
* ? test -r $HOME/.junkfilterrc
{
	INCLUDERC=$HOME/.junkfilterrc
}

# Be sure status variables are unset

JFEXP
JFSTATUS

# Initialize variables

JFVERSION=20020519

# set the actual procmail LINEBUF to the configured length
LINEBUF=$JFLINEBUF

# a newline
JFNL="
"

# printable character range, ascii 33 through ascii 126
JFPCHAR=([!-~])

# a valid username
JFUSRNAM=([-._+a-z0-9]+)

# a valid domain, sans TLD
JFDOMNAM=([0-9a-z][-0-9a-z]+)

# IANA valid TLDs
JFTLD=(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|[a-z][a-z])

# build the username, domain, and TLD into a valid email address
JFADDR=($JFUSRNAM@($JFDOMNAM\.)+$JFTLD)

# comparisons with this variable should never match.
JFNOMATCH="pangalacticgargleblastersareverytastyuntilyouexplode"

# a valid IP quad (four needed, separated by ".", for a full IP address)
JFIPNUM=(2([0-4][0-9]|5[0-5])|1[0-9][0-9]|[1-9][0-9]|[0-9])

# a full valid IP address
JFIP=$JFIPNUM\.$JFIPNUM\.$JFIPNUM\.$JFIPNUM

# whitespace (space or tab) of length greater than or equal to one character
JFWS="[ 	]+"

# a bunch of headers where the person sending the email can be found
JFFROM=^((X-)?(((Envelope-)?Sender|(Apparently-|Resent-)?From)|Return-Path):(.*\<)?)

# same as JFFROM, but includes Received: header
JFFROMREC=^((X-)?(((Envelope-)?Sender|(Apparently-|Resent-)?From)|Return-Path|Received):(.*\<)?)

# Now call the various sections

# Is the JF_WHITE section activated?
:0
* $ $JF_WHITE^0
{
	JFVER=(^|[^-_.a-z0-9])
	JFVERR=([^-_.a-z0-9]|$)
	JFSECUSER=$JF_WHITE_USER
	JFSECUSERLOC=$JF_WHITE_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.white
}

# Is the JF_USER section activated?
:0
* $ $JF_USER^0
{ INCLUDERC=$JFDIR/junkfilter.user }

# Is the JF_ONE section activated?
:0
* $ $JF_ONE^0
{ INCLUDERC=$JFDIR/junkfilter.one }

# Is the JF_TWO section activated?
:0
* $ $JF_TWO^0
{ INCLUDERC=$JFDIR/junkfilter.two }

# Is the JF_THREE section activated?
:0
* $ $JF_THREE^0
{ INCLUDERC=$JFDIR/junkfilter.three }

# Is the JF_FOUR section activated?
:0
* $ $JF_FOUR^0
{ INCLUDERC=$JFDIR/junkfilter.four }

# Is the JF_DIALUPS section activated?
:0
* $ $JF_DIALUPS^0
{
	JFSECTION=dialups
	JFVER=^Received:.*
	JFVERR="\\>.*by ([-a-z0-9]+\.)*$JFMAILDOM\\>"
	JFSECUSER=$JF_DIALUPS_USER
	JFSECUSERLOC=$JF_DIALUPS_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.lists
}

# Is the JF_ADDRESSES section activated?
:0
* $ $JF_ADDRESSES^0
{
	JFSECTION=addresses
	JFVER=[^-_.a-z0-9]
	JFVERR
	JFSECUSER=$JF_ADDRESSES_USER
	JFSECUSERLOC=$JF_ADDRESSES_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.lists
}

# Is the JF_IP section activated?
:0
* $ $JF_IP^0
{
	JFSECTION=ip
	JFVER=$JFFROMREC
	JFVERR=\\>
	JFSECUSER=$JF_IP_USER
	JFSECUSERLOC=$JF_IP_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.lists
}

# Is the JF_HEADERS section activated?
:0
* $ $JF_HEADERS^0
{
	JFSECTION=headers
	JFVER=^
	JFVERR
	JFSECUSER=$JF_HEADERS_USER
	JFSECUSERLOC=$JF_HEADERS_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.lists
}

# Is the JF_BODYCHK section activated?
:0
* $ $JF_BODYCHK^0
{
	LINEBUF=$JFBLINEBUF
	INCLUDERC=$JFDIR/junkfilter.bodychk
	LINEBUF=$JFLINEBUF
}

# Is the JF_DOMAINS section activated?
:0
* $ $JF_DOMAINS^0
{
	JFSECTION=domains
	LINEBUF=$JFBLINEBUF
	JFVER=(^|[^-_a-z0-9])
	JFVERR=([^-_.a-z0-9]|$)
	JFSECUSER=$JF_DOMAINS_USER
	JFSECUSERLOC=$JF_DOMAINS_USER_LOC
	INCLUDERC=$JFDIR/junkfilter.lists
	LINEBUF=$JFLINEBUF
}

# Call the OPT section
INCLUDERC=$JFDIR/junkfilter.opt

# Get some statistics
INCLUDERC=$JFDIR/junkfilter.stats

# EOF junkfilter
