Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
setifilter ... un utitlity per mailfilter
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian)
View previous topic :: View next topic  
Author Message
IgaRyu
Guru
Guru


Joined: 23 Jan 2003
Posts: 302
Location: Verona

PostPosted: Mon Sep 29, 2003 3:48 pm    Post subject: setifilter ... un utitlity per mailfilter Reply with quote

Chi usa mailfilter per lo spam sulla posta saprà quanto e noioso dovero ogni volta aprire il file di configurazione per aggiornare quello di cui vogliamo liberarci.

Stufo anch'io mi son deciso a scirvere uno scriptino che risolva il problema. Basta il comando con il parametro e la stringa da intercettare ed il file viene aggiornato automaticamente.

Al solito consigli e migliorie sono ben accette :)

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum