This file is indexed.

/usr/bin/delete_spam is in trac-email2trac 2.4.7-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/python
#
# Copyright (C) 2002
#
# This file is part of the email2trac utils
#
# 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, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# 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
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
#
# vi:
#	set ts=4
"""
Author: Bas van der Vlies
Date  : 29 September 2205
Desc. : Delete Spam tickets from database. Else we get an lot of 
        tickets

Usage :
	delete_spam [ -f/--file <configfile>  -n/--dry-run -p/--project <name> -v/--verbose]

defaults:
	configfile = /etc/email2trac.conf

SVN Info:
        $Id: delete_spam.py.in 374 2010-06-09 15:15:07Z bas $
"""

import os
import sys
import getopt
import shutil
import ConfigParser

from trac import __version__ as trac_version

def ReadConfig(file, name):
	"""
	Parse the config file
	"""

	if not os.path.isfile(file):
		print 'File %s does not exists' %file
		sys.exit(1)

	config = ConfigParser.ConfigParser()
	try:
		config.read(file)
	except ConfigParser.MissingSectionHeaderError,detail:
		print detail
	  	sys.exit(1)

  	# Use given project name else use defaults
  	#
	if name:
		if not config.has_section(name):
			print "Not an valid project name: %s" %name
			print "Valid names: %s" %config.sections()
			sys.exit(1)

		project =  dict()
		for option in  config.options(name):
			project[option] = config.get(name, option) 

	else:
		project = config.defaults()

	return project



def new_delete_spam(parameters):
	"""
	This only works for trac versions higher or equal then 0.10
	"""

	debug = int(parameters['debug'])
	DRY_RUN = parameters['DRY_RUN']
	VERBOSE = parameters['VERBOSE']

	project = parameters['project']


	env = Environment(project, create=0)
	db = env.get_db_cnx()

	cursor = db.cursor()
	cursor.execute("SELECT id FROM ticket WHERE  component = 'Spam';") 
	while 1: 
		row = cursor.fetchone()
		if not row:
			break 

		spam_id =  row[0]

		if debug or DRY_RUN or VERBOSE:
			print "Deleting ticket %s" %spam_id

		try:
			tkt = Ticket(env, spam_id, db)
		except util.TracError, detail:
		        print detail
			continue

		if DRY_RUN:
			print 'DRY_RUN: tkt.delete()'
		else:
			tkt.delete()

if __name__ == '__main__':
	# Default config file
	#
	configfile = '/etc/email2trac.conf'


	try:
		 opts, args = getopt.getopt(sys.argv[1:], 'hf:np:v', ['help', 'file=', 'dry-run', 'project=', 'verbose'])
	except getopt.error,detail:
		print __doc__
		print detail
		sys.exit(1)

	DRY_RUN = False
	VERBOSE = False
	project_name = None

	for opt,value in opts:
		if opt in [ '-h', '--help']:
			print __doc__ 
			sys.exit(0) 
		elif opt in ['-f', '--file']:
			configfile = value
		elif opt in ['-n', '--dry-run']:
			DRY_RUN = True
		elif opt in ['-p', '--project']:
			project_name = value
		elif opt in ['-v', '--verbose']:
			VERBOSE = True

	# Determine major trac version used to be in email2trac.conf
	# Quick hack for 0.12
	#
	version = '0.%s' %(trac_version.split('.')[1])
	if version.startswith('0.12'):
		version = '0.12'

	if VERBOSE:
		print "Found trac version: %s" %version

	## We only support versions 0.11 and 0.12
	#
	if not version in ['0.11', '0.12']:
		print 'Trac version %s is not suported' %(version)

	settings = ReadConfig(configfile, project_name)
	if not settings.has_key('project'):
		print __doc__
		print 'No project defined in config file, eg:\n\t project: /data/trac/bas'
		sys.exit(1)

	settings['DRY_RUN'] = DRY_RUN
	settings['VERBOSE'] = VERBOSE

	from trac.env import Environment
	from trac.ticket import Ticket
	from trac import util



	new_delete_spam(settings)

	print 'Spam is deleted succesfully..' 
# EOB