472,368 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

Filter class

Hello NG,

Curious to know whether exists a filter class.
I'm doing some rough mail filtering on my own criteria, but I'm very new on
programming and I like to find some clue on passing a config file of rules
which will be regex by Python.

Sep 30 '06 #1
1 1427
On 17:02, sabato 30 settembre 2006 TheSaint wrote:
Hello NG,

Curious to know whether exists a filter class.
I'm doing some rough mail filtering on my own criteria, but I'm very new on
programming and I like to find some clue on passing a config file of rules
which will be regex by Python.

I went to study some long and I developed a small program, herebelow.
But I'd appreciate if it vill come some suggestion for a pythonic cosmetic
fashion :)

Thank to everybody.

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++
#! /usr/bin/env python
"""" Test the mailserver to clean unwanted mail"""

from poplib import POP3
import ConfigParser , sys , os , re

def call_POP(args):
if len(args) != 4: return
for cnt in range(len(args)):
if args[cnt] =='' or args[cnt] == None : return
a = POP3(args[0])
print 'Server %s reply %s' %(args[0], a.pass_(args[2]))
(numMsgs, totalSize) = a.stat()
msg9 = ''
for i in range(1, numMsgs +1):
for hdrline in a.top(i,0)[1]:
for argmn in args[3]:
if not re.search(argmn[1], hdrline): continue
lsenty = 0
if argmn[0].startswith('a') and not argmn[0].startswith('d'):
#list only the messages that aren't matching
if lsenty == i: continue # no duplicate messages
fwrt.write('Msg No %03d\nTEST "%s" \n %s\n' \
%(i,argmn[1], hdrline))
lsenty = i

def get_mydir(file):
if os.name == 'posix':
adir = os.path.split(file)[0]
afil = os.path.split(file)[1]
if adir == '': adir = os.getcwd()
for pth in ('~/', '$HOME/'):
if pth in adir: adir = os.environ['HOME']
file = adir + '/' + afil
if not os.path.exists(file):
print 'Configuration file not found'
return 0
return file

if len(sys.argv) != 3:
print 'Incorrect Number of arguments!'
infil = get_mydir(sys.argv[1])
if not infil: sys.exit(0)
opnfil = sys.argv[2]
fwrt = open(opnfil,'w')

cfg = ConfigParser.ConfigParser()
infil = ''
fltr = 'Filters'
if fltr in cfg.sections():
infil = cfg.items(fltr)
for section in cfg.sections():
if section.lower() in ('setting', 'filters'): continue
adir = 0
afil = {}
for pth in ('server', 'user', 'pass'):
afil[adir] = cfg.get(section, pth)
adir += 1
afil[adir] = infil
print 'Now trying to connect to ' + section

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++

Also the config File enclosed (some detail is obscured for obvious purposes).

================================================== ========================
PASS = xxxxxxxxxxxxxxxxxxx
USER = wwwwwwwwwwwwwwwwwwwww
SERVER = eeeeeeeeeeeeeeeee

SERVER = popmmmmmmmmmmmmmm
USER = godddllrrrrrrrrr
PASS = rrettttttttttt

SERVER = fgotttttttttee
USER = gggggggrrrrrrdfng
PASS = rrrrrrrrrrrrrrro

SERVER = ffpogakfbmb
USER = fglkfrtrtthajl
PASS = fg8uarewaehueh

#All section is not impemented. It's supposed to give either a filepath or
# none
LOG = no
# obviously how much we want to know about the process
# Some case we won't need errors from python and let the matter die as is
# some implementation of threading to have the way to log on
# all the server in parallel

# A = Allow (anything which starts with "a" is filtered as allowed)
# to keep as good.

A01 = ^From: .*\.cz
A02 = ^(To|Cc): .*wwwwwwwwwwwwwwwwwwwww
A03 = ^(To|Cc): .*godddllrrrrrrrrr@
A04 = ^(To|Cc): .*fglkfrtrtthajl@
A05 = ^(To|Cc): .*122951205u@
A06 = ^From: .*\.my

# D = Deny (anything which starts with "a" is filtered as denied) and will
# fill the list for deletion.

D01 = ^From: .*\.com\.my
D02 = \*\*\*SPAM\*\*\*
================================================== ========================

Let me say that is an experimental program for learning purpose, yet. More
things should be implemented like :
1 Real deletion for those email listed in the report file.
2 a single group pattern for the regex search
3 Logging errors and all functions mentioned in the "Setting" section.
4 last but not least a GUI.

The idea was born when i was looking for the "mailfilter" package for Arch
Linux. Actually has been retired. Then I tought " It would be good if a
platform indipendent program will do the same job or a bit more".

Testing on win32 platform is good help.
So, if somebody like to join, very welcome for all of the possible chances,
please try to contact me at _fulvio AT tm DOT net DOT my_.

Oct 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: NRGY | last post by:
Hi. I need help with a filtering function that I can't get to whatever I try. I have this output that I need to filter: <tr> <td class="box_content" align="center">3,259</td> <td...
by: Robin Cull | last post by:
Imagine I have a dict looking something like this: myDict = {"key 1": , "key 2": , "key 3": , "key 4": } That is, a set of keys which have a variable length list of associated values after...
by: Lou | last post by:
I'm using the Response Filter Class in MS KB article 811162 (http://support.microsoft.com/default.aspx?scid=kb;EN-US;811162) to generate a static htm page from an asp.net template page being...
by: Edward Burns | last post by:
I am trying to create an events calendar with a complete month view. I want to be able to get all the events for a particular month, using only one recordset on the page then be able to loop...
by: Paul de Goede | last post by:
I set the Response.Filter in my aspnet application but I have noticed that if you do a Server.Transfer that the filter doesn't get called. And in actual fact the response is mostly empty. It seems...
by: Brad | last post by:
I have a response filter which injects "standard" html into my pages. The filter works fine when the initial stream is small enough not to buffer...or....if I have a large unbuffered stream (i.e. I...
by: Owen Wong | last post by:
Please look at my newly written class. It is meant to be used to filter suspicious html input from an online html editor. I need help about 2 things: 1. Does it need to filter more things? Which I...
by: sjickells | last post by:
Hi I am having a problem using asp:TextBox's in a transparent table. I have a background image on the page and a table in the middle of the page. I have set the background colour of the table...
by: david.katkowski | last post by:
I'm trying to use the __builtin__ filter function within a class; however, I receive the following error: NameError: global name 'MajEthnic' is not defined The line of code is: EthMaj =...
by: CatchSandeepVaid | last post by:
Suppose i have one-to-one association between Product and ProductBasic. and we have applied filter on ProductBasic Class. I have applied this filter as in Java side we have one-to-one relationship...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.