Article 13648 of alt.sources:


Submitted by: johnbob
Archive-name: jmfilter/part04

#!/bin/sh
# this is output.shar.04 (part 4 of jmfilter)
# do not concatenate these parts, unpack them in order with /bin/sh
# file jmpack.pl continued
#
touch 2>&1 | fgrep '[-amc]' > /tmp/s3_touch$$
if [ -s /tmp/s3_touch$$ ]
then
    TOUCH=can
else
    TOUCH=cannot
fi
rm -f /tmp/s3_touch$$
CurArch=4
if test ! -r s3_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s3_seq_.tmp || exit 1
echo "x - Continuing file jmpack.pl"
sed 's/^X//' << 'SHAR_EOF' >> jmpack.pl
X# in any way, in association with any person, author, contributor,
X# corporation, or organization does not express or imply any warranty,
X# guarantee, commitment, or endorsement of any kind.
X#
X
X
X# initialization outside the package
X
X($username,$passwd,$uid,$gid,$quota,$comment,$gcos,$homedir,$shell) = getpwuid($<);
Xdie "username not defined" unless defined($username);
Xdie "homedir not defined" unless defined($homedir);
X
Xif( ! defined($jmlog) )
X{
X    $jmlog="$homedir/.jmlog";
X}
Xif( ! defined($junkbldbfile) )
X{
X    $junkbldbfile="$homedir/.jmbldb";
X}
Xif( ! defined($junklsdbfile) )
X{
X    $junklsdbfile="$homedir/.jmlsdb";
X}
Xif( ! defined($jm_tmp_directory) )
X{
X    $jm_tmp_directory='/tmp';
X}
Xif( ! defined($mbox) )
X{
X    $mbox="/usr/spool/mail/$username";
X}
Xif( ! defined($junkmbox) )
X{
X    $junkmbox="$homedir/.jm_mbox";
X}
Xif( ! defined($jm_evidence) )
X{
X    $jm_evidence="$homedir/.jm_ev";
X}
Xif( ! defined($junk_score_limit) )
X{
X    $junk_score_limit=5;
X}
Xif( ! defined($stop_loop_hours) )
X{
X    $stop_loop_hours=24;
X}
Xif( ! defined($remove_after_months) )
X{
X    $remove_after_months=6;
X}
Xif( ! defined($evidence_limit) )
X{
X    $evidence_limit=4;
X}
Xif( ! defined($no_nasty) )
X{
X    $no_nasty=0;
X}
Xif( ! defined($sendmail_program) )
X{
X    $sendmail_program="/usr/sbin/sendmail";
X}
Xif( ! defined($whofrom) )
X{
X    $whofrom=$username;
X    local($hn)=`hostname`;
X    chop($hn);
X    if( $hn ne "" )
X    {
X        $whofrom .= ( '@' . $hn );
X    }
X}
Xif( ! defined($also_report_to) )
X{
X    $also_report_to="";
X}
X
X
Xpackage jmpack;
X
X# initialization inside the package
X
Xrequire "timelocal.pl";
X
X%month_s_to_n = (
X"Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4, "Jun", 5, "Jul", 6, "Aug", 7,
X"Sep", 8, "Oct", 9, "Nov", 10, "Dec", 11,
X);
X
X%weekday_s_to_n = (
X"Sun", 0, "Mon", 1, "Tue", 2, "Wed", 3, "Thu", 4, "Fri", 5, "Sat", 6,
X);
X
X# need to get a real table here
X%tzone_s_to_n = (
X"EST", "-0500", "EDT", "-0400", "CST", "-0600", "CDT", "-0500", "MST", "-0700",
X"MDT", "-0600", "PST", "-0800", "PDT", "-0700", "JST", "+0900", "JDT", "+1000",
X);
X
X
Xsub tmpfile
X{
X    local($n) = 0;
X    local($lockname) = "$main'jm_tmp_directory/jm.lock";
X    local($base) = "$main'jm_tmp_directory/jm.$$";
X    local($tmp) = "$base.$n";
X
X    open(TMPLOCK,">$lockname");
X    flock(TMPLOCK,2); # exclusive lock
X
X    while( -f $tmp )
X    {
X        $n++;
X        $tmp = "$base.$n";
X    }
X
X    # create the file here so that it will exist
X    # after the lock is released and before it is used
X    # by the caller
X    open(TMPTOUCH,">$tmp");
X    close(TMPTOUCH);
X
X    flock(TMPLOCK,8); # unlock
X    close(TMPLOCK);
X
X    return $tmp;
X}
X
Xsub jmlog
X{
X    local($logtext) = @_;
X
X    if( open(LOGF,">>$main'jmlog") )
X    {
X        flock(LOGF,2); # exclusive lock
X        seek(LOGF,0,2); # make sure we append
X
X        print LOGF "$logtext\n";
X
X        flock(LOGF,8); # unlock
X        close(LOGF);
X    }
X}
X
Xsub is_blacklisted
X{
X    local($address) = @_;
X    local($rv) = 0;
X
X    if( ! defined($address) || $address eq "" )
X    {
X        return 0;
X    }
X
X    open(JMBLDBLOCK,">$main'junkbldbfile.lock");
X    flock(JMBLDBLOCK,2); # exclusive lock
X    dbmopen(jmbldb,$main'junkbldbfile,0600);
X
X    local($entry) = $jmbldb{$address};
X
X    if( defined($entry) )
X    {
X        $rv=1;
X    }
X
X    dbmclose(jmbldb);
X    flock(JMBLDBLOCK,8); # unlock
X    close(JMBLDBLOCK);
X
X    return $rv;
X}
X
Xsub add_to_blacklist
X{
X    local($address,$evidence) = @_;
X    local($used) = 0;
X
X    if( ! open(JMBLDBLOCK,">$main'junkbldbfile.lock") )
X    {
X        return $used;
X    }
X    flock(JMBLDBLOCK,2); # exclusive lock
X    dbmopen(jmbldb,$main'junkbldbfile,0600);
X
X    if( ! defined($jmbldb{$address}) )
X    {
X        $jmbldb{$address} = $evidence;
X
X        if( $jmbldb{$address} ne "" )
X        {
X            $used=1;
X        }
X    }
X    else
X    {
X        local(@elist) = split(/\s+/,$jmbldb{$address});
X
X        if( scalar(@elist) < $main'evidence_limit )
X        {
X            if( $evidence ne "" )
X            {
X                if( $jmbldb{$address} ne "" )
X                {
X                    $jmbldb{$address} .= ' ';
X                }
X                $jmbldb{$address} .= $evidence;
X                $used=1;
X            }
X        }
X    }
X
X    dbmclose(jmbldb);
X    flock(JMBLDBLOCK,8); # unlock
X    close(JMBLDBLOCK);
X
X    return $used;
X}
X
Xsub lookup_in_database
X{
X    local($dbname,$key) = @_;
X    local($rv);
X    local(%db);
X
X    open(DB,">$dbname.lock");
X    flock(DB,2); # exclusive lock
X    dbmopen(db,$dbname,0600);
X
X    $rv = $db{$key};
X
X    dbmclose(db);
X    flock(DB,8); # unlock
X    close(DB);
X
X    return $rv;
X}
X
Xsub delete_in_database
X{
X    local($dbname,$key) = @_;
X    local($rv);
X    local(%db);
X
X    open(DB,">$dbname.lock");
X    flock(DB,2); # exclusive lock
X    dbmopen(db,$dbname,0600);
X
X    $rv = $db{$key};
X
X    if( defined($rv) )
X    {
X        delete $db{$key};
X    }
X
X    dbmclose(db);
X    flock(DB,8); # unlock
X    close(DB);
X
X    return $rv;
X}
X
Xsub get_machine_name
X{
X    local($l) = @_;
X
X    if( $l !~ /@/ )
X    {
X        return undef;
X    }
X
X    if( $l =~ /^[\w\.\-\*]+@([\w\.\-\*]+)$/ )
X    {
X        local($machine) = $1;
X
X        return $machine;
X    }
X
X    if( $l =~ /^<?@[A-Za-z0-9\.]+:[A-Za-z0-9\.]+@([A-Za-z0-9\.]+)>?$/ )
X    {
X        local($machine) = $1;
X
X        return $machine;
X    }
X
X    if( $l =~ /^[A-Za-z0-9\.]+\%([A-Za-z0-9\.]+)@[A-Za-z0-9\.]+$/ )
X    {
X        local($machine) = $1;
X
X        return $machine;
X    }
X
X    return undef;
X}
X
Xsub convert_to_local_time
X{
X    local($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$tzone) = @_;
X    local($hour_diff);
X
X    if( ! defined($tzone) )
X    {
X        $tzone='+0000';
X    }
X    elsif( $tzone eq '' )
X    {
X        $tzone='+0000';
X    }
X    elsif( $tzone =~ /^[A-Za-z]+$/ )
X    {
X        $tzone =~ y/a-z/A-Z/;
X
X        $tzone = $tzone_s_to_n{$tzone};
X    }
X
X    if( $tzone =~ /([-+]\d\d)(\d\d)/ )
X    {
X        $hour_diff = $1+($2/60);
X    }
X    elsif( $tzone =~ /([-+]\d)(\d\d)/ )
X    {
X        $hour_diff = $1+($2/60);
X    }
X    else
X    {
X        $hour_diff = 0;
X    }
X
X    if( $year =~ /^19(..)/ )
X    {
X        $year = $1;
X    }
X
X    # use timegm so that it won't mess with TZ stuff
X    local($tmpseconds) = &timegm($sec,$min,$hour,$mday,$mon,$year);
X
X    # convert back to GMT by subtracting a negative value
X    $tmpseconds -= ($hour_diff*60*60);
X
X    # convert back to expanded local time
X    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tmpseconds);
X
X    return ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
X}
SHAR_EOF
echo "File jmpack.pl is complete"
chmod 0644 jmpack.pl || echo "restore of jmpack.pl fails"
if [ $TOUCH = can ]
then
    touch -am 0929155696 jmpack.pl
fi
set `wc -c jmpack.pl`;Wc_c=$1
if test "$Wc_c" != "7271"
then echo original size 7271, current size $Wc_c;fi
# ============= jmretadd ==============
echo "x - extracting jmretadd (Text)"
sed 's/^X//' << 'SHAR_EOF' > jmretadd &&
X#!/usr/bin/perl -- -*-Perl-*-
X
X#
X# $Id: jmretadd,v 1.14 1996/09/28 03:19:20 johnbob Exp johnbob $
X#
X# No copyright.
X#
X# This code and documentation is referred to as "information".
X#
X# This information is provided "AS IS" WITHOUT WARRANTY OF ANY KIND,
X# EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
X# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
X# PURPOSE, OR NON-INFRINGEMENT. Some jurisdictions do not allow the
X# exclusion of implied warranties, so the above exclusion may not
X# apply to you. 
X#
X# This information contains bugs.
X# Use at your own risk.
X# Existence of this information, whether broadcasted, posted, mailed,
X# archived, printed, distributed by avian carriers, or made available
X# in any way, in association with any person, author, contributor,
X# corporation, or organization does not express or imply any warranty,
X# guarantee, commitment, or endorsement of any kind.
X#
X
X($username,$passwd,$uid,$gid,$quota,$comment,$gcos,$homedir,$shell) = getpwuid($<);
Xdie "username not defined" unless defined($username);
Xdie "homedir not defined" unless defined($homedir);
X$jmrctext=&read_entire_file("$homedir/.jmrc");
Xeval $jmrctext;
X$jmrctext="";
Xif( ! defined($jmpath) )
X{
X    $jmpath="$homedir/bin";
X}
Xpush(@INC,$jmpath);
Xrequire "jmpack.pl";
Xsub read_entire_file
X{
X    local($fname) = @_;
X    local($rv) = "";
X    local($l);
X
X    if( ! open(RCF,"$fname") )
X    {
X        return $rv;
X    }
X    while($l=<RCF>)
X    {
X        $rv .= $l;
X    }
X    close(RCF);
X
X    return $rv;
X}
X
X%a_list = ();
X$verbose=0;
X
X%options = (
X'-v', '$verbose=1',
X);
X
Xif ( (@ARGV) )
X{
X    for $arg (@ARGV)
X    {
X        if( defined( $options{$arg} ) )
X        {
X            eval $options{$arg};
X        }
X        else
X        {
X            &return_addresses($arg);
X        }
X    }
X}
X
Xexit 0;
X
Xsub return_addresses
X{
X    local($fname) = @_;
X    local($section) = 0;
X    local($limbo) = "";
X
X    $verbose && print "return_addresses $fname\n";
X
X    %a_list = ();
X
X    if( ! open(INF,"<$fname") )
X    {
X        $verbose && print "can't open file [$fname]\n";
X        return;
X    }
X    while($l=<INF>)
X    {
X        chop($l);
X
X        if( $section == 0 )
X        {
X            if( $l eq "" )
X            {
X                $section = 1;
X                if( $limbo ne "" )
X                {
X                    &header_line($limbo);
X                    $limbo = "";
X                }
X            }
X            elsif( $l =~ /^\s/ )
X            {
X                $limbo .= $l;
X            }
X            else
X            {
X                if( $limbo ne "" )
X                {
X                    &header_line($limbo);
X                    $limbo = "";
X                }
X                $limbo = $l;
X            }
X        }
X        elsif( $section == 1 )
X        {
X            &examine_line($l);
X        }
X    }
X    close(INF);
X
X    local($firstone)=1;
X    foreach $address ( sort keys %a_list )
X    {
X        if( $verbose )
X        {
X            print "$a_list{$address} of $address\n";
X        }
X        else
X        {
X            if( $firstone )
X            {
X                $firstone=0;
X                print "$address";
X            }
X            else
X            {
X                print " $address";
X            }
X        }
X    }
X
X    if( ! $verbose )
X    {
X        print "\n";
X    }
X
X    %a_list = ();
X}
X
Xsub header_line
X{
X    local($l) = @_;
X
X    # message-id looks like an address, so skip it
X    return if $l =~ /message-id: /i;
X
X    return if $l =~ /^apparently-to: /i;
X    return if $l =~ /^Received: /i;
X    return if $l =~ /^to: /i;
X    return if $l =~ /^cc: /i;
X
X    &examine_line($l);
X}
X
Xsub examine_line
X{
X    local($l) = @_;
X
X    # message-id looks like an address, so skip it
X    return if $l =~ /message-id: /i;
X
X    while( $l =~ s/<(@[A-Za-z0-9\.]+:[A-Za-z0-9\.]+@[A-Za-z0-9\.]+)>// )
X    {
X        $address = $1;
X        $verbose && print "[$address] out of [$l]\n";
X        if( ! defined($a_list{$address}) )
X        {
X            $a_list{$address} = 1;
X        }
X        else
X        {
X            $a_list{$address}++;
X        }
X    }
X
X    while( $l =~ s/([A-Za-z0-9\.]+\%[A-Za-z0-9\.]+@[A-Za-z0-9\.]+)// )
X    {
X        $address = $1;
X        $verbose && print "[$address] out of [$l]\n";
X        if( ! defined($a_list{$address}) )
X        {
X            $a_list{$address} = 1;
X        }
X        else
X        {
X            $a_list{$address}++;
X        }
X    }
X
X    while( $l =~ s/([\w\.\-\*]+@[\w\.\-\*]+)// )
X    {
X        $address = $1;
X        $verbose && print "[$address] out of [$l]\n";
X        if( ! defined($a_list{$address}) )
X        {
X            $a_list{$address} = 1;
X        }
X        else
X        {
X            $a_list{$address}++;
X        }
X    }
X}
SHAR_EOF
chmod 0755 jmretadd || echo "restore of jmretadd fails"
if [ $TOUCH = can ]
then
    touch -am 0929155696 jmretadd
fi
set `wc -c jmretadd`;Wc_c=$1
if test "$Wc_c" != "4701"
then echo original size 4701, current size $Wc_c;fi
# ============= patchlevel.h ==============
echo "x - extracting patchlevel.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > patchlevel.h &&
X#define PATCHLEVEL      0
SHAR_EOF
chmod 0644 patchlevel.h || echo "restore of patchlevel.h fails"
if [ $TOUCH = can ]
then
    touch -am 0929155696 patchlevel.h
fi
set `wc -c patchlevel.h`;Wc_c=$1
if test "$Wc_c" != "26"
then echo original size 26, current size $Wc_c;fi
# ============= jmrc.example ==============
echo "x - extracting jmrc.example (Text)"
sed 's/^X//' << 'SHAR_EOF' > jmrc.example &&
X$jmpath="$homedir/bin";
X@subject_exempt_list = ( 'exemptfromjunkmailfilter' );
X@address_exempt_list = (
X'postmaster',
X'MAILER\-DAEMON',
X);
X# don't send mail by default
X$no_nasty=1;
X# report junkmail to local postmaster too
X#$also_report_to='postmaster';
SHAR_EOF
chmod 0644 jmrc.example || echo "restore of jmrc.example fails"
if [ $TOUCH = can ]
then
    touch -am 0929155696 jmrc.example
fi
set `wc -c jmrc.example`;Wc_c=$1
if test "$Wc_c" != "254"
then echo original size 254, current size $Wc_c;fi
# ============= dot.forward.example ==============
echo "x - extracting dot.forward.example (Text)"
sed 's/^X//' << 'SHAR_EOF' > dot.forward.example &&
Xusername,|"/home/username/jmarrival"
SHAR_EOF
chmod 0644 dot.forward.example || echo "restore of dot.forward.example fails"
if [ $TOUCH = can ]
then
    touch -am 0929155696 dot.forward.example
fi
set `wc -c dot.forward.example`;Wc_c=$1
if test "$Wc_c" != "37"
then echo original size 37, current size $Wc_c;fi
rm -f s3_seq_.tmp
echo "You have unpacked the last part"
exit 0


