AntiSpam Script in Python for Frost, (GNU GPL)

J Anjen <scruple532-/[email protected]> Tue, 30 Aug 2005 03:38:54 -0700 (PDT)
Newsgroups gmane.network.freenet.frost.devel,gmane.network.freenet.technical
Message-ID <[email protected]>
The signup process for the devl and tech mailing lists
have been screwed up lately so I'm not sure if this
will make it or not.

Come to #Frost on TOR if you want to coordinate.

Here's a copy of the script I've been working on, it's
not done yet and it doesn't have Bayesian although
Reverned might work if I can get more documentation.

---

#Python
#Using the walker method from
http://effbot.org/librarybook/os-path.htm
#Frost Spam Detector 0.02
#Copyright 2005 to Scruple.
#This program is released under the Free Software
Foundation's GNU GPL 2.0 .
#It doesn't have Bayesian put in yet although it would
be trivial to add Reverend
#http://divmod.org/projects/reverend to it which I may
do.
#Come to #Frost on irc.freenode.net (use TOR) to
discuss.
#To test this, make a directory called Test and put a
board directory into it so its /Test/Freenet/(date
directories) 

import os, stat, shutil, re, sys, codecs

Drive = "C"
DirMov = 'test'
DirList = []
XMLList = []
List = []
WordList=[]
FiledirList = []
Linecount = 0
x = 0
y = 0
MatchName='abc'

KeyMatch='CHK'
AuthorMatch='<From>'
DateMatch='<Date>'
BoardMatch='<Board>'
BodyMatch='<Body>'
BodyMatchBack='</Body>'
RunOnLine=']]>'
BoardGo='Go'

class DirectoryWalker:
    # a forward iterator that traverses a directory
tree

    def __init__(self, directory):
        self.stack = [directory]
        self.files = []
        self.index = 0

    def __getitem__(self, index):
        while 1:
            try:
                file = self.files[self.index]
                self.index = self.index + 1
            except IndexError:
                # pop next directory from stack
                self.directory = self.stack.pop()
                self.files =
os.listdir(self.directory)
                self.index = 0
            else:
                # got a filename
                fullname =
os.path.join(self.directory, file)
                pathall = os.path.join(self.directory,
"")
                if os.path.isdir(fullname) and not
os.path.islink(fullname):
                    self.stack.append(fullname)
                return fullname, pathall

for file, pathall in
DirectoryWalker(Drive+"://test/"):
    DirMovBack = file.find('\\')
    DirMov = file[9:DirMovBack]
    FullpathLen = len(file)
    EXTconfirm = file[FullpathLen - 3:FullpathLen]
    FilesXMLconfirm = file[FullpathLen -
9:FullpathLen]
    if os.path.isfile(file) == True:
        if FilesXMLconfirm == 'files.xml':
            print 'files.xml'
        else:
            if EXTconfirm == 'xml':
                FileStrXML = str(file)
                XMLList.append(FileStrXML)

for file, pathall in
DirectoryWalker(Drive+"://test/"):
    if os.path.isfile(file) <> True:
        if os.listdir(file)==[]:
            FileStrDir = str(file)
            DirList.append(FileStrDir)

print XMLList
print DirList

XMLListCount = len(XMLList)
DirListCount = len(DirList)

print XMLListCount
print DirListCount

#Running down the list of .xml files for parsing.
while y < XMLListCount:
    CurrentFile = XMLList[y]
    Manifile = codecs.open(CurrentFile, "r", "utf-16")
    #Starts at line 500 and counts forwards.
    Linecount = 100
    while Linecount <> 0:
        Maniread = Manifile.readline()
        List.append(Maniread)
        Linecount = Linecount - 1
    ListLength = len(List)
    Manifile.close()

    #Parsing the xml file for tag information.
    while x < ListLength:
        Lineo = List[x]
        Lineostr = Lineo.encode('ascii', 'replace')
        KeyMatchCheck = re.search(KeyMatch,Lineostr)
        AuthorMatchCheck =
re.search(AuthorMatch,Lineostr)
        DateMatchCheck = re.search(DateMatch,Lineostr)
        BoardMatchCheck =
re.search(BoardMatch,Lineostr)
        BodyMatchCheck = re.search(BodyMatch,Lineostr)
        BodyMatchBackCheck =
re.search(BodyMatchBack,Lineostr)
        if AuthorMatchCheck <> None:
            AuthorFront = Lineostr.find('<From>')
            AuthorBack = Lineostr.find('</From>')
            AuthorID = Lineostr[AuthorFront + 6 +
9:AuthorBack - 3]
        if DateMatchCheck <> None:
            AuthorFront = Lineostr.find('<Date>')
            AuthorBack = Lineostr.find('</Date>')
            Date = Lineostr[AuthorFront + 6 +
9:AuthorBack - 3]
        if BoardMatchCheck <> None:
            AuthorFront = Lineostr.find('<Board>')
            AuthorBack = Lineostr.find('</Board>')
            BoardGo = Lineostr[AuthorFront + 7 +
9:AuthorBack - 3]        
        if BodyMatchCheck <> None:
            print x
            print Lineo
            BodyTagFront = x
            BodyTagCount = BodyTagFront
        if BodyMatchBackCheck <> None:
            print x
            print Lineo
            BodyTagBack = x + 1
        x = x + 1

    #Spam detection portion.
    #Reverned looks ok but Orange maybe better.
    #This portion is unfinished.
    while BodyTagCount < BodyTagBack:
        XMLBody = List[BodyTagCount]
        print XMLBody        
        BodyTagCount = BodyTagCount + 1
    y = y + 1
    x = 0
    List = []




		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf