View previous topic :: View next topic |
Author |
Message |
IgaRyu Guru
Joined: 23 Jan 2003 Posts: 302 Location: Verona
|
Posted: Mon Sep 29, 2003 4:18 pm Post subject: SETFILTER: una utility per mailfilter |
|
|
Chi usa mailfilter per gestire lo spam in entrata, sa quanto sia noioso di volta in volta andare ad editare il file di configurazione per aggiungere filtri.
Visto che sono uno di quelli ho creato questo script per l'inserimento da riga di comando dei filtri che si vogliono.
Al solito commenti e migliorie sono ben accette.
Joe
Code: |
#!/usr/bin/env python
##---------------------------------------------------------------------------##
##
## setifilter -- append filters to mailfilter configuration file
##
## Copyright (C) 2003 Joe Curto
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be of some
## interest to somebody, but WITHOUT ANY WARRANTY; without even the
## implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
## See the GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## writing to the Free Software Foundation, Inc.,
## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
## The license can also be found at the GNU/FSF website: http://www.gnu.org
##
## Joe Curto
## <joe@joe.vr.it>
##
##---------------------------------------------------------------------------##
import os
import sys
import getpass
def usercls():
if os.name=='posix':
os.system('clear')
else:
os.system('cls')
print "SetFilter: a MailFilter setup facility GPL By Joe"
print
if (os.path.exists(os.environ['HOME']+'/.mailfilterrc')==0):
usercls()
print "Attenzione non risulta presente il file di configurazione di mailfilter !!!"
sys.exit(0)
if (len(sys.argv) == 1):
usercls()
print "Use setfilter: "
print " -h or --h or --help for more informations\n\n"
sys.exit(0)
if (sys.argv[1] !='-h' and sys.argv[1] !='--h' and sys.argv[1] !='--help' and sys.argv[1] !='-df' and sys.argv[1] !='-ds' and sys.argv[1] !='-dcs' and sys.argv[1] !='-as' and sys.argv[1] !='-af'):
usercls()
print "Use setfilter: "
print " -h or --h or --help for more informations\n\n"
sys.exit(0)
if (sys.argv[1] =='-h' or sys.argv[1] =='--h' or sys.argv[1] =='--help'):
usercls()
print "setfilter parameters:"
print " -h or --h or --help display this help"
print " -df string : append string to DENY=^From list"
print " -ds string : append string to DENY=^Subject list"
print " -dcs string : append string to DENY_CASE=^Subject list"
print " -as string : append string to ALLOW=^Subject list"
print " -af string : append string to ALLOW=^From list \n\n"
print " Deletion of string is not provvided yet !!\n\n"
sys.exit(0)
if (len(sys.argv) == 2 and (sys.argv[1] !='-h' and sys.argv[1] !='--h' and sys.argv[1] !='--help')):
usercls()
print " Parameters must be 2: The flag and the string to append !!!"
print " setfilter -h or --h or --help for more informations\n\n"
sys.exit(0)
if (os.path.exists(os.environ['HOME']+'/.mailfilterrc')==0):
usercls()
print "Attenzione non risulta presente il file di configurazione di mailfilter !!!"
sys.exit(0)
input=open(os.environ['HOME']+'/.mailfilterrc','rt')
output= open('/tmp/mailfilterrc', 'w')
k=0
DenyFrom = ['']
DenySubj = [""]
DenyCaseSubj = ['']
AllowSubj = ['']
AllowFrom = ['']
for s in input.xreadlines():
if (s[0:10] =='DENY=^From'):
DenyFrom.append(s)
elif (s[0:13] =='DENY=^Subject'):
DenySubj.append(s)
elif (s[0:18] == 'DENY_CASE=^Subject'):
DenyCaseSubj.append(s)
elif (s[0:14] =='ALLOW=^Subject'):
AllowSubj.append(s)
elif (s[0:11] == 'ALLOW=^From'):
AllowFrom.append(s)
else:
output.write(s)
if (sys.argv[1] =='-df'):
DenyFrom.append('DENY=^From:.*'+sys.argv[2]+'\n')
elif (sys.argv[1] =='-ds'):
DenySubj.append('DENY=^Subject:.*'+sys.argv[2]+'\n')
elif (sys.argv[1] =='-dcs'):
DenyCaseSubj.append('DENY_CASE=^Subject:.*'+sys.argv[2]+'\n')
elif (sys.argv[1] =='-as'):
AllowSubj.append('ALLOW=^Subject:.*'+sys.argv[2]+'\n')
elif (sys.argv[1] =='-af'):
AllowFrom.append('ALLOW=^From:.*'+sys.argv[2]+'\n')
i=0
while (i < len(DenyFrom)):
output.write(DenyFrom[i])
i=i+1
output.write("\n")
i=0
while (i < len(DenySubj)):
output.write(DenySubj[i])
i=i+1
output.write("\n")
i=0
while (i < len(DenyCaseSubj)):
output.write(DenyCaseSubj[i])
i=i+1
output.write("\n")
i=0
while (i < len(AllowSubj)):
output.write(AllowSubj[i])
i=i+1
output.write("\n")
i=0
while (i < len(AllowFrom)):
output.write(AllowFrom[i])
i=i+1
output.write("\n")
input.close()
output.close()
os.system("mv " + os.environ['HOME']+'/.mailfilterrc ' +os.environ['HOME']+'/.mailfilterrc.old')
os.system("mv /tmp/mailfilterrc " + os.environ['HOME']+'/.mailfilterrc')
|
_________________ One Flew East
One Flew West
Some Flew On The Kukool's Nest |
|
Back to top |
|
|
IgaRyu Guru
Joined: 23 Jan 2003 Posts: 302 Location: Verona
|
Posted: Thu Oct 02, 2003 11:31 am Post subject: |
|
|
Devo deurre che sono il solo ad usare mailfiter ??? _________________ One Flew East
One Flew West
Some Flew On The Kukool's Nest |
|
Back to top |
|
|
Ginko Guru
Joined: 01 May 2002 Posts: 371 Location: nearby my linux laptop
|
Posted: Thu Oct 02, 2003 12:44 pm Post subject: |
|
|
IgaRyu wrote: | Devo deurre che sono il solo ad usare mailfiter ??? |
Purtroppo supporta solo POP. Non appena il supporto per IMAP verra' rilasciato gli daro' un'occhiata.
Saluti
--Gianluca |
|
Back to top |
|
|
shev Bodhisattva
Joined: 03 Feb 2003 Posts: 4084 Location: Italy
|
Posted: Thu Oct 02, 2003 5:28 pm Post subject: |
|
|
IgaRyu wrote: | Devo deurre che sono il solo ad usare mailfiter ??? |
Io non lo uso, però grazie lo stesso, stai sfornando script a ripetizione _________________ Se per vivere ti dicono "siediti e stai zitto" tu alzati e muori combattendo |
|
Back to top |
|
|
_Echelon_ Apprentice
Joined: 20 Jul 2003 Posts: 293
|
Posted: Thu Oct 02, 2003 5:29 pm Post subject: |
|
|
ehehehehe _________________ Did you know that if you play a Windows 2000 cd backwards, you will hear the voice of Satan?
That's nothing! If you play it forward, it'll install Windows 2000. |
|
Back to top |
|
|
IgaRyu Guru
Joined: 23 Jan 2003 Posts: 302 Location: Verona
|
Posted: Fri Oct 03, 2003 5:53 am Post subject: |
|
|
Bhe ogni tanto mi stufo a ripetere a mano sempre le stesse operazioni ed automizzzo quanto possibile
Joe _________________ One Flew East
One Flew West
Some Flew On The Kukool's Nest |
|
Back to top |
|
|
|