[Mailman-Developers] Re: [Mailman-Users] admin requests on the lists

Scott scott@chronis.pobox.com
Fri, 13 Nov 1998 14:25:34 -0500


forgot to take out that "print lines" line of code, it should be removed.

scott

On Fri, Nov 13, 1998 at 02:24:26PM -0500, Scott wrote:
| 
| Ok, here's a better version.  fixes the readlines thing, and strips the sig.
| 
| #
| # given an IncomingMessage object,
| # test for administrivia (eg subscribe, unsubscribe, etc).
| # the test must be a good guess -- messages that return true
| # get sent to the list admin instead of the entire list.
| #
| def IsAdministrivia(msg):
|     lines = map(string.lower, string.split(msg.body, "\n"))
|     #
|     # check to see how many lines that actually have text in them there are
|     #
|     admin_data = {"subscribe": (0, 3),
|                   "unsubscribe": (0, 1),
|                   "who": (0,0),
|                   "info": (0,0),
|                   "lists": (0,0),
|                   "set": (2, 3),
|                   "help": (0,0),
|                   "password": (2, 2),
|                   "options": (0,0),
|                   "remove": (0, 0)}
|     lines_with_text = 0
|     print lines
|     for line in lines:
|         if string.strip(line):
|             lines_with_text = lines_with_text + 1
|         if lines_with_text > 30: # we might want to change this to mm_cfg.DEFAULT_MAIL_COMMANDS_MAX_LINES.
|             return 0
|     sig_ind =  string.find(msg.body, "\n-- ")
|     if sig_ind != -1:
|         body = msg.body[:sig_ind]
|     else:
|         body = msg.body
|     if admin_data.has_key(string.lower(string.strip(body))):
|         return 1
|     try:
|         if admin_data.has_key(string.lower(string.strip(msg["subject"]))):
|             return 1
|     except KeyError:
|         pass
|     for line in lines[:5]:
|         if not string.strip(line):
|             continue
|         words = string.split(line)
|         if admin_data.has_key(words[0]):
|             min_args, max_args = admin_data[words[0]]
|             if min_args <= len(words[1:]) <= max_args:
|                 return 1
|     return 0
| 
| 
| scott
| 
| 
| On Fri, Nov 13, 1998 at 08:18:32PM +0100, Gergely Madarasz wrote:
| | Hello!
| | 
| | I think I found it.
| | In IsAdministrivia:
| |     lines = map(string.lower, msg.readlines())
| | This returns the whole message, and then checks for administrivia in it,
| | including the headers. Some mailers add custom headers, mta-s add Received
| | headers, so we cannot tell how many header lines there can be. And then it
| | checks 
| | 	if lines_with_text > 10:
| | headers will be counted too. So I guess this should be modified to check
| | only the body of the message. Now I increased this number to 30, should
| | work in most cases, but this is only a hack... :)
| | 
| | -- 
| | Madarasz Gergely           gorgo@caesar.elte.hu         gorgo@linux.rulez.org
| |       It's practically impossible to look at a penguin and feel angry.
| |           Egy pingvinre gyakorlatilag lehetetlen haragosan nezni.
| |                     HuLUG: http://mlf.linux.rulez.org/
| | 
| | 
| | _______________________________________________
| | Mailman-Developers maillist  -  Mailman-Developers@python.org
| | http://www.python.org/mailman/listinfo/mailman-developers
| |