summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2010-07-16 23:18:55 -0400
committerBarry Warsaw2010-07-16 23:18:55 -0400
commit2f6fbea64ada4d36b04459be201cacd6c3812ed7 (patch)
tree13e01e407599560c98ba89527f6d1b1d1e700ce1
parentdb19156330bf6bbca9a6e13c5d85676e43be3b29 (diff)
downloadmailman-2f6fbea64ada4d36b04459be201cacd6c3812ed7.tar.gz
mailman-2f6fbea64ada4d36b04459be201cacd6c3812ed7.tar.zst
mailman-2f6fbea64ada4d36b04459be201cacd6c3812ed7.zip
-rw-r--r--setup.py2
-rw-r--r--src/mailman/bin/onebounce.py74
-rw-r--r--src/mailman/bounces/__init__.py0
-rwxr-xr-xtests/onebounce.py94
4 files changed, 75 insertions, 95 deletions
diff --git a/setup.py b/setup.py
index d1bbda200..e671d0821 100644
--- a/setup.py
+++ b/setup.py
@@ -68,7 +68,7 @@ with open('src/mailman/version.py') as fp:
template = Template('$script = mailman.bin.$script:main')
scripts = set(
template.substitute(script=script)
- for script in ('mailman', 'qrunner', 'master')
+ for script in ('mailman', 'qrunner', 'master', 'onebounce')
)
diff --git a/src/mailman/bin/onebounce.py b/src/mailman/bin/onebounce.py
new file mode 100644
index 000000000..f044d0d8c
--- /dev/null
+++ b/src/mailman/bin/onebounce.py
@@ -0,0 +1,74 @@
+# Copyright (C) 2002-2010 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/>.
+
+"""Test bounce detection on message files."""
+
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'main',
+ ]
+
+
+import sys
+
+from mailman.core.i18n import _
+from mailman.options import Options
+
+
+
+class ScriptOptions(Options):
+ """Options for onebounce."""
+
+ usage = _("""\
+%prog [options]
+
+Test the bounce detection for message files.""")
+
+ def add_options(self):
+ """See `Options`."""
+ self.parser.add_option(
+ '-a', '--all',
+ default=False, action='store_true',
+ help=_("""\
+Run the message through all the registered bounce modules. Normally this
+script stops at the first match."""))
+ self.parser.add_option(
+ '-m', '--module',
+ type='string', help=_("""
+Run the message through just the named bounce module."""))
+ self.parser.add_option(
+ '-l', '--list',
+ default=False, action='store_true',
+ help=_('List all available bounce modules and exit.'))
+ self.parser.add_option(
+ '-v', '--verbose',
+ default=False, action='store_true',
+ help=_('Increase verbosity.'))
+
+
+
+def main():
+ """bin/onebounce"""
+ options = ScriptOptions()
+ options.initialize()
+
+ if options.options.list:
+ print 'list of available bounce modules.'
+ sys.exit(0)
diff --git a/src/mailman/bounces/__init__.py b/src/mailman/bounces/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/mailman/bounces/__init__.py
diff --git a/tests/onebounce.py b/tests/onebounce.py
deleted file mode 100755
index f17c0194d..000000000
--- a/tests/onebounce.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#! /usr/bin/env python
-
-# Copyright (C) 2002-2010 by the Free Software Foundation, Inc.
-#
-# 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
-# of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-"""Test the bounce detection for files containing bounces.
-
-Usage: %(PROGRAM)s [options] file1 ...
-
-Options:
- -h / --help
- Print this text and exit.
-
- -v / --verbose
- Verbose output.
-
- -a / --all
- Run the message through all the bounce modules. Normally this script
- stops at the first one that finds a match.
-"""
-
-import sys
-import email
-import getopt
-
-import paths
-from Mailman.Bouncers import BouncerAPI
-
-PROGRAM = sys.argv[0]
-COMMASPACE = ', '
-
-
-
-def usage(code, msg=''):
- print __doc__ % globals()
- if msg:
- print msg
- sys.exit(code)
-
-
-
-def main():
- try:
- opts, args = getopt.getopt(sys.argv[1:], 'hva',
- ['help', 'verbose', 'all'])
- except getopt.error, msg:
- usage(1, msg)
-
- all = verbose = 0
- for opt, arg in opts:
- if opt in ('-h', '--help'):
- usage(0)
- elif opt in ('-v', '--verbose'):
- verbose = 1
- elif opt in ('-a', '--all'):
- all = 1
-
- for file in args:
- fp = open(file)
- msg = email.message_from_file(fp)
- fp.close()
- for module in BouncerAPI.BOUNCE_PIPELINE:
- modname = 'Mailman.Bouncers.' + module
- __import__(modname)
- addrs = sys.modules[modname].process(msg)
- if addrs is BouncerAPI.Stop:
- print module, 'got a Stop'
- if not all:
- break
- if not addrs:
- if verbose:
- print module, 'found no matches'
- else:
- print module, 'found', COMMASPACE.join(addrs)
- if not all:
- break
-
-
-
-if __name__ == '__main__':
- main()