diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-09-18 16:47:55 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-09-18 16:47:55 -0300 |
commit | b4e2708c6f8cc2191c581aef404803478e65e678 (patch) | |
tree | 703d3f7f8f96d9564e7cc3f8ebf85a38c93ab3e1 /philter.py | |
parent | 4fdd3ebb2b0622fb6cff7376a02a5b92c1aba2ae (diff) | |
download | scripts-b4e2708c6f8cc2191c581aef404803478e65e678.tar.gz scripts-b4e2708c6f8cc2191c581aef404803478e65e678.tar.bz2 |
Moved scripts to custom repos
Diffstat (limited to 'philter.py')
-rwxr-xr-x | philter.py | 83 |
1 files changed, 0 insertions, 83 deletions
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() |