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.

TIA
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.

TIA
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
MULTILINE = 8

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])
a.user(args[1])
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'):
continue
#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
fwrt.write('\n\n')
a.quit()

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!'
sys.exit(0)
infil = get_mydir(sys.argv[1])
if not infil: sys.exit(0)
opnfil = sys.argv[2]
fwrt = open(opnfil,'w')

cfg = ConfigParser.ConfigParser()
cfg.read(infil)
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
call_POP(afil)
fwrt.close()

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

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

================================================== ========================
[Jaring]
PASS = xxxxxxxxxxxxxxxxxxx
USER = wwwwwwwwwwwwwwwwwwwww
SERVER = eeeeeeeeeeeeeeeee

[Vodafone]
SERVER = popmmmmmmmmmmmmmm
USER = godddllrrrrrrrrr
PASS = rrettttttttttt

[TMnet]
SERVER = fgotttttttttee
USER = gggggggrrrrrrdfng
PASS = rrrrrrrrrrrrrrro

[YahooIt]
SERVER = ffpogakfbmb
USER = fglkfrtrtthajl
PASS = fg8uarewaehueh

[Setting]
#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
VERBOSE = 3
# Some case we won't need errors from python and let the matter die as is
SWALLOW_ERR = yes
# some implementation of threading to have the way to log on
# all the server in parallel
PARALLEL = yes

[Filters]
# 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_.

Fulvio
Oct 7 '06 #2

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

Similar topics

9
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...
9
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...
1
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...
1
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...
5
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...
3
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...
1
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...
0
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...
1
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 =...
1
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...
2
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...
0
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...
0
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...
0
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...
0
hi
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...
1
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...
0
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...
1
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...
1
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.