473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 1465
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.