summaryrefslogtreecommitdiff
path: root/mailman/rules/administrivia.py
diff options
context:
space:
mode:
authorBarry Warsaw2009-01-25 13:01:41 -0500
committerBarry Warsaw2009-01-25 13:01:41 -0500
commiteefd06f1b88b8ecbb23a9013cd223b72ca85c20d (patch)
tree72c947fe16fce0e07e996ee74020b26585d7e846 /mailman/rules/administrivia.py
parent07871212f74498abd56bef3919bf3e029eb8b930 (diff)
downloadmailman-eefd06f1b88b8ecbb23a9013cd223b72ca85c20d.tar.gz
mailman-eefd06f1b88b8ecbb23a9013cd223b72ca85c20d.tar.zst
mailman-eefd06f1b88b8ecbb23a9013cd223b72ca85c20d.zip
Diffstat (limited to 'mailman/rules/administrivia.py')
-rw-r--r--mailman/rules/administrivia.py102
1 files changed, 0 insertions, 102 deletions
diff --git a/mailman/rules/administrivia.py b/mailman/rules/administrivia.py
deleted file mode 100644
index 8807ef952..000000000
--- a/mailman/rules/administrivia.py
+++ /dev/null
@@ -1,102 +0,0 @@
-# Copyright (C) 2007-2009 by the Free Software Foundation, Inc.
-#
-# This file is part of GNU Mailman.
-#
-# GNU Mailman 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 3 of the License, or (at your option)
-# any later version.
-#
-# GNU Mailman 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
-# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-
-"""The administrivia rule."""
-
-from __future__ import absolute_import, unicode_literals
-
-__metaclass__ = type
-__all__ = [
- 'Administrivia',
- ]
-
-
-from email.iterators import typed_subpart_iterator
-from zope.interface import implements
-
-from mailman.config import config
-from mailman.i18n import _
-from mailman.interfaces.rules import IRule
-
-
-# The list of email commands we search for in the Subject header and payload.
-# We probably should get this information from the actual implemented
-# commands.
-EMAIL_COMMANDS = {
- # keyword: (minimum #args, maximum #args)
- 'confirm': (1, 1),
- 'help': (0, 0),
- 'info': (0, 0),
- 'lists': (0, 0),
- 'options': (0, 0),
- 'password': (2, 2),
- 'remove': (0, 0),
- 'set': (3, 3),
- 'subscribe': (0, 3),
- 'unsubscribe': (0, 1),
- 'who': (0, 2),
- }
-
-
-
-class Administrivia:
- """The administrivia rule."""
- implements(IRule)
-
- name = 'administrivia'
- description = _('Catch mis-addressed email commands.')
- record = True
-
- def check(self, mlist, msg, msgdata):
- """See `IRule`."""
- # The list must have the administrivia check enabled.
- if not mlist.administrivia:
- return False
- # First check the Subject text.
- lines_to_check = []
- subject = str(msg.get('subject', ''))
- if subject <> '':
- lines_to_check.append(subject)
- # Search only the first text/plain subpart of the message. There's
- # really no good way to find email commands in any other content type.
- for part in typed_subpart_iterator(msg, 'text', 'plain'):
- payload = part.get_payload(decode=True)
- lines = payload.splitlines()
- # Count lines without using enumerate() because blank lines in the
- # payload don't count against the maximum examined.
- lineno = 0
- for line in lines:
- line = line.strip()
- if line == '':
- continue
- lineno += 1
- if lineno > config.mailman.email_commands_max_lines:
- break
- lines_to_check.append(line)
- # Only look at the first text/plain part.
- break
- # For each line we're checking, split the line into words. Then see
- # if it looks like a command with the min-to-max number of arguments.
- for line in lines_to_check:
- words = [word.lower() for word in line.split()]
- if words[0] not in EMAIL_COMMANDS:
- # This is not an administrivia command.
- continue
- minargs, maxargs = EMAIL_COMMANDS[words[0]]
- if minargs <= len(words) - 1 <= maxargs:
- return True
- return False