From b4e2708c6f8cc2191c581aef404803478e65e678 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 18 Sep 2014 16:47:55 -0300 Subject: Moved scripts to custom repos --- philter.py | 83 -------------------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100755 philter.py (limited to 'philter.py') diff --git a/philter.py b/philter.py deleted file mode 100755 index 38229aa..0000000 --- a/philter.py +++ /dev/null @@ -1,83 +0,0 @@ -#! /usr/bin/python -# -# Email filter -# -# This is a slighted channged version of Philter available at -# http://philter.sourceforge.net written by Prabhakar V. Chaganti and -# distributed under GPLv2. -# -# Minor changes by rhatto at riseup.net. -# - -import ConfigParser, os, rfc822, re, string, posixpath - - -class Philter: - def __init__(self,match,header,destination,maildir): - self.re = re.compile(match) - self.header = header - self.destination = destination - self.maildir = maildir - - - def __str__(self): - return ("philter : \n \t match: %s \n\t header: %s \n\t destination: %s \n\t maildir: %s" % - (self.re,self.header,self.destination,self.maildir)) - - - -class PhilterDriver: - __propFile = open(string.join((posixpath.expanduser('~'),'/.config/scripts/philterrc'),'')) - __newDir = '/new' - - def createPhilters(self): - sections = PhilterDriver.__config.sections() - sections.sort() - philters=[] - maildir = PhilterDriver.__config.get('DEFAULT','maildir') - for section in sections: - philters.append(Philter((PhilterDriver.__config.get(section,'match')), - string.split(PhilterDriver.__config.get(section,'header'),','), - PhilterDriver.__config.get(section,'destination'), - string.join((maildir,'/',PhilterDriver.__config.get(section,'destination'),'/new'),''))) - return philters - - - def parseConfig(self): - PhilterDriver.__config = ConfigParser.ConfigParser() - PhilterDriver.__config.readfp(PhilterDriver.__propFile) - - - def philterMaildir(self, philters): - inbox = string.join([PhilterDriver.__config.get('DEFAULT','maildir'), - "/",PhilterDriver.__config.get('DEFAULT','inbox'), - PhilterDriver.__newDir],"") - newMessages = os.listdir(inbox) - maildir = PhilterDriver.__config.get('DEFAULT','maildir') - found = 0 - for newMessage in newMessages: - msg = rfc822.Message(open(string.join([inbox,"/",newMessage],""))) - for philter in philters: - for hdr in philter.header: - if msg.getheader(hdr): - if philter.re.search(string.lower(msg.getheader(hdr))): - os.rename(string.join((maildir,'INBOX/new/',newMessage),''), - string.join((philter.maildir,'/',newMessage),'')) - found = 1 - break - - if found: - found = 0 - break - - - def main(self): - driver = PhilterDriver() - driver.parseConfig() - philters = driver.createPhilters() - driver.philterMaildir(philters) - - - -if __name__ == '__main__': - PhilterDriver().main() -- cgit v1.2.3