Ticket #2706: spam.py

File spam.py, 1.3 kB (added by mickem, 9 months ago)

strange, the svn diff disregarded new files... well, here is the spam.py

Line 
1 # -*- coding: utf-8 -*-
2 # Spam adapter for tracdiscussion
3 # Written by: Michael Medin <michael [at] medin [dot] name>
4 #
5 from StringIO import StringIO
6
7 from trac.core import *
8 from trac.config import IntOption
9 from trac.mimeview import is_binary
10 from tracdiscussion.api import IDiscussionManipulator
11 from trac.util.text import to_unicode
12 from tracspamfilter.api import FilterSystem
13
14 class DiscussionFilterAdapter(Component):
15     implements(IDiscussionManipulator)
16
17     # IDiscussionManipulator methods
18
19     def validate_message(self ,req, author, body):
20         if req.perm.has_permission('TICKET_ADMIN'):
21             # An administrator is allowed to spam
22             return []
23         if 'preview' in req.args:
24             # Only a preview, no need to filter the submission yet
25             return []
26         changes = [(None, body)]
27         FilterSystem(self.env).test(req, author, changes)
28         return []
29
30     def validate_topic(self, req, author, subject, body):
31         if req.perm.has_permission('TICKET_ADMIN'):
32             # An administrator is allowed to spam
33             return []
34         if 'preview' in req.args:
35             # Only a preview, no need to filter the submission yet
36             return []
37         changes = [(None, body)]
38         FilterSystem(self.env).test(req, author, changes)
39         return []