1 #!/usr/bin/env python 2 # 3 # Copyright (C) 2010 by the Free Software Foundation, Inc. 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 18 # USA. 19 20 """This is a template for a custom handler that will examine the content 21 of all the text/* parts in the message and take action based on matching 22 various regexps. It is not intended to be used as is, but rather as 23 a starting point for implementing something useful. 24 """ 25 26 import re 27 28 from Mailman import Utils 29 from Mailman import Errors 30 from Mailman.i18n import _ 31 from Mailman.Handlers import Hold 32 from Mailman.Handlers import Moderate 33 34 class BadContent(Errors.HoldMessage): 35 reason = _('Message contains improper content') 36 rejection = _('Your message contained content not allowed on this list.') 37 38 # The following regexps are things to search for in the text/* parts of 39 # the message if more than one matches, the precedence is DISCARD over 40 # REJECT over HOLD. 41 DISCARD = re.compile(r'discard_pattern', re.IGNORECASE) 42 REJECT = re.compile(r'reject_pattern', re.IGNORECASE) 43 HOLD = re.compile(r'hold_pattern', re.IGNORECASE) 44 # And if the following regexp matches the Subject: header, the message will 45 # be unconditionally accepted. 46 ACCEPT = re.compile(r'accept_pattern', re.IGNORECASE) 47 48 # Note that this is just an example of how various things might be done. 49 # It it not intended to be used as is. 50 51 def process(mlist, msg, msgdata): 52 # First see if the subject matches the accept pattern (simple test - 53 # Doesn't work with encoded Subject) 54 if ACCEPT.search(msg[subject]): 55 msgdata['approved'] = 1 56 # Used by the Emergency module 57 msgdata['adminapproved'] = 1 58 return 59 discard = reject = hold = False 60 # Go through the message and examine the text/* parts. 61 for part in msg.walk(): 62 if part.get_content_maintype() == 'text': 63 payload = part.get_payload(decode=True) 64 if DISCARD.search(payload): 65 discard = True 66 if REJECT.search(payload): 67 reject = True 68 if HOLD.search(payload): 69 hold = True 70 if discard: 71 # This will honor the list's forward_auto_discards setting. 72 Moderate.do_discard(mlist, msg) 73 # Doesn't return. 74 if reject: 75 listowner = mlist.GetOwnerEmail() 76 raise Errors.RejectMessage, Utils.wrap(_("""\ 77 Your message has been automatically rejected due to its content. 78 If you think that your messages are being rejected in 79 error, contact the mailing list owner at %(listowner)s.""")) 80 if hold: 81 Hold.hold_for_approval(mlist, msg, msgdata, BadContent)
Attached FilesTo refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
You are not allowed to attach a file to this page.