diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/mta/aliases.py | 8 | ||||
| -rw-r--r-- | src/mailman/mta/base.py | 11 | ||||
| -rw-r--r-- | src/mailman/mta/bulk.py | 8 | ||||
| -rw-r--r-- | src/mailman/mta/connection.py | 13 | ||||
| -rw-r--r-- | src/mailman/mta/decorating.py | 11 | ||||
| -rw-r--r-- | src/mailman/mta/deliver.py | 34 | ||||
| -rw-r--r-- | src/mailman/mta/exim4.py | 8 | ||||
| -rw-r--r-- | src/mailman/mta/null.py | 8 | ||||
| -rw-r--r-- | src/mailman/mta/personalized.py | 11 | ||||
| -rw-r--r-- | src/mailman/mta/postfix.py | 11 | ||||
| -rw-r--r-- | src/mailman/mta/tests/test_aliases.py | 14 | ||||
| -rw-r--r-- | src/mailman/mta/tests/test_connection.py | 6 | ||||
| -rw-r--r-- | src/mailman/mta/tests/test_delivery.py | 14 | ||||
| -rw-r--r-- | src/mailman/mta/verp.py | 11 |
14 files changed, 48 insertions, 120 deletions
diff --git a/src/mailman/mta/aliases.py b/src/mailman/mta/aliases.py index ae7e70a7f..dc434c613 100644 --- a/src/mailman/mta/aliases.py +++ b/src/mailman/mta/aliases.py @@ -17,11 +17,7 @@ """Utility for generating all the aliases of a mailing list.""" -__all__ = [ - 'MailTransportAgentAliases', - ] - - +from mailman import public from mailman.interfaces.mta import IMailTransportAgentAliases from zope.interface import implementer @@ -38,7 +34,7 @@ SUBDESTINATIONS = ( ) - +@public @implementer(IMailTransportAgentAliases) class MailTransportAgentAliases: """Utility for generating all the aliases of a mailing list.""" diff --git a/src/mailman/mta/base.py b/src/mailman/mta/base.py index 43b737fb9..a04ee4b46 100644 --- a/src/mailman/mta/base.py +++ b/src/mailman/mta/base.py @@ -17,17 +17,12 @@ """Base delivery class.""" -__all__ = [ - 'BaseDelivery', - 'IndividualDelivery', - ] - - import copy import socket import logging import smtplib +from mailman import public from mailman.config import config from mailman.interfaces.mta import IMailTransportAgentDelivery from mailman.mta.connection import Connection @@ -37,7 +32,7 @@ from zope.interface import implementer log = logging.getLogger('mailman.smtp') - +@public @implementer(IMailTransportAgentDelivery) class BaseDelivery: """Base delivery class.""" @@ -118,7 +113,7 @@ class BaseDelivery: return sender - +@public class IndividualDelivery(BaseDelivery): """Deliver a unique individual message to each recipient. diff --git a/src/mailman/mta/bulk.py b/src/mailman/mta/bulk.py index 65dfea0bb..1741e0d4c 100644 --- a/src/mailman/mta/bulk.py +++ b/src/mailman/mta/bulk.py @@ -17,11 +17,7 @@ """Bulk message delivery.""" -__all__ = [ - 'BulkDelivery', - ] - - +from mailman import public from mailman.mta.base import BaseDelivery @@ -38,7 +34,7 @@ CHUNKMAP = dict( ) - +@public class BulkDelivery(BaseDelivery): """Deliver messages to the MSA in as few sessions as possible.""" diff --git a/src/mailman/mta/connection.py b/src/mailman/mta/connection.py index 283e3a44e..44cc31d86 100644 --- a/src/mailman/mta/connection.py +++ b/src/mailman/mta/connection.py @@ -17,22 +17,19 @@ """MTA connections.""" -__all__ = [ - 'Connection', - ] - - import logging import smtplib +from contextlib import suppress from lazr.config import as_boolean +from mailman import public from mailman.config import config log = logging.getLogger('mailman.smtp') - +@public class Connection: """Manage a connection to the SMTP server.""" def __init__(self, host, port, sessions_per_connection, @@ -103,8 +100,6 @@ class Connection: """Mimic `smtplib.SMTP.quit`.""" if self._connection is None: return - try: + with suppress(smtplib.SMTPException): self._connection.quit() - except smtplib.SMTPException: - pass self._connection = None diff --git a/src/mailman/mta/decorating.py b/src/mailman/mta/decorating.py index c0a1dc07b..e9d6f5785 100644 --- a/src/mailman/mta/decorating.py +++ b/src/mailman/mta/decorating.py @@ -17,17 +17,12 @@ """Individualized delivery with header/footer decorations.""" -__all__ = [ - 'DecoratingDelivery', - 'DecoratingMixin', - ] - - +from mailman import public from mailman.config import config from mailman.mta.verp import VERPDelivery - +@public class DecoratingMixin: """Decorate a message with recipient-specific headers and footers.""" @@ -39,7 +34,7 @@ class DecoratingMixin: msgdata['nodecorate'] = True - +@public class DecoratingDelivery(DecoratingMixin, VERPDelivery): """Add recipient-specific headers and footers.""" diff --git a/src/mailman/mta/deliver.py b/src/mailman/mta/deliver.py index 034364da6..fdd564946 100644 --- a/src/mailman/mta/deliver.py +++ b/src/mailman/mta/deliver.py @@ -17,14 +17,10 @@ """Generic delivery.""" -__all__ = [ - 'deliver', - ] - - import time import logging +from mailman import public from mailman.config import config from mailman.interfaces.mailinglist import Personalization from mailman.interfaces.mta import SomeRecipientsFailed @@ -40,7 +36,7 @@ COMMA = ',' log = logging.getLogger('mailman.smtp') - +@public class Deliver(VERPMixin, DecoratingMixin, PersonalizedMixin, IndividualDelivery): """Deliver one message to one recipient. @@ -62,7 +58,7 @@ class Deliver(VERPMixin, DecoratingMixin, PersonalizedMixin, ]) - +@public def deliver(mlist, msg, msgdata): """Deliver a message to the outgoing mail server.""" # If there are no recipients, there's nothing to do. @@ -94,15 +90,15 @@ def deliver(mlist, msg, msgdata): if size is None: size = len(msg.as_string()) substitutions = dict( - msgid = msg.get('message-id', 'n/a'), - listname = mlist.fqdn_listname, - sender = original_sender, - recip = len(original_recipients), - size = size, - time = t1 - t0, - refused = len(refused), - smtpcode = 'n/a', - smtpmsg = 'n/a', + msgid = msg.get('message-id', 'n/a'), # flake8: noqa + listname = mlist.fqdn_listname, # flake8: noqa + sender = original_sender, # flake8: noqa + recip = len(original_recipients), # flake8: noqa + size = size, # flake8: noqa + time = t1 - t0, # flake8: noqa + refused = len(refused), # flake8: noqa + smtpcode = 'n/a', # flake8: noqa + smtpmsg = 'n/a', # flake8: noqa ) template = config.logging.smtp.every if template.lower() != 'no': @@ -145,9 +141,9 @@ def deliver(mlist, msg, msgdata): template = config.logging.smtp.failure if template.lower() != 'no': substitutions.update( - recip = recipient, - smtpcode = code, - smtpmsg = smtp_message, + recip = recipient, # flake8: noqa + smtpcode = code, # flake8: noqa + smtpmsg = smtp_message, # flake8: noqa ) log.info('%s', expand(template, substitutions)) # Return the results diff --git a/src/mailman/mta/exim4.py b/src/mailman/mta/exim4.py index 5824e31e9..7151768a8 100644 --- a/src/mailman/mta/exim4.py +++ b/src/mailman/mta/exim4.py @@ -17,16 +17,12 @@ """Creation/deletion hooks for the Exim4 MTA.""" -__all__ = [ - 'LMTP', - ] - - +from mailman import public from mailman.interfaces.mta import IMailTransportAgentLifecycle from zope.interface import implementer - +@public @implementer(IMailTransportAgentLifecycle) class LMTP: """Connect Mailman to Exim4 via LMTP. diff --git a/src/mailman/mta/null.py b/src/mailman/mta/null.py index ba6adbbd5..165c5f0ee 100644 --- a/src/mailman/mta/null.py +++ b/src/mailman/mta/null.py @@ -20,16 +20,12 @@ Exim one example of an MTA that Just Works. """ -__all__ = [ - 'NullMTA', - ] - - +from mailman import public from mailman.interfaces.mta import IMailTransportAgentLifecycle from zope.interface import implementer - +@public @implementer(IMailTransportAgentLifecycle) class NullMTA: """Null MTA that just satisfies the interface.""" diff --git a/src/mailman/mta/personalized.py b/src/mailman/mta/personalized.py index 5e573a599..7cfbfff43 100644 --- a/src/mailman/mta/personalized.py +++ b/src/mailman/mta/personalized.py @@ -17,21 +17,16 @@ """Personalized delivery.""" -__all__ = [ - 'PersonalizedDelivery', - 'PersonalizedMixin', - ] - - from email.header import Header from email.utils import formataddr +from mailman import public from mailman.interfaces.mailinglist import Personalization from mailman.interfaces.usermanager import IUserManager from mailman.mta.verp import VERPDelivery from zope.component import getUtility - +@public class PersonalizedMixin: """Personalize the message's To header. @@ -63,7 +58,7 @@ class PersonalizedMixin: msg.replace_header('To', formataddr((name, recipient))) - +@public class PersonalizedDelivery(PersonalizedMixin, VERPDelivery): """Personalize the message's To header.""" diff --git a/src/mailman/mta/postfix.py b/src/mailman/mta/postfix.py index 12d7e81a6..ff4b92117 100644 --- a/src/mailman/mta/postfix.py +++ b/src/mailman/mta/postfix.py @@ -17,15 +17,11 @@ """Creation/deletion hooks for the Postfix MTA.""" -__all__ = [ - 'LMTP', - ] - - import os import logging from flufl.lock import Lock +from mailman import public from mailman.config import config from mailman.config.config import external_configuration from mailman.interfaces.listmanager import IListManager @@ -42,17 +38,16 @@ ALIASTMPL = '{0:{2}}lmtp:[{1.mta.lmtp_host}]:{1.mta.lmtp_port}' NL = '\n' - class _FakeList: """Duck-typed list for the `IMailTransportAgentAliases` interface.""" def __init__(self, list_name, mail_host): self.list_name = list_name self.mail_host = mail_host - self.posting_address = '{0}@{1}'.format(list_name, mail_host) + self.posting_address = '{}@{}'.format(list_name, mail_host) - +@public @implementer(IMailTransportAgentLifecycle) class LMTP: """Connect Mailman to Postfix via LMTP.""" diff --git a/src/mailman/mta/tests/test_aliases.py b/src/mailman/mta/tests/test_aliases.py index 4f62d7f49..1bc79df93 100644 --- a/src/mailman/mta/tests/test_aliases.py +++ b/src/mailman/mta/tests/test_aliases.py @@ -17,12 +17,6 @@ """Test the MTA file generating utility.""" -__all__ = [ - 'TestAliases', - 'TestPostfix', - ] - - import os import shutil import tempfile @@ -44,7 +38,6 @@ def _strip_header(contents): return NL.join(lines[7:]) - class TestAliases(unittest.TestCase): layer = ConfigLayer @@ -94,7 +87,7 @@ class TestAliases(unittest.TestCase): def __init__(self, list_name, mail_host): self.list_name = list_name self.mail_host = mail_host - self.posting_address = '{0}@{1}'.format(list_name, mail_host) + self.posting_address = '{}@{}'.format(list_name, mail_host) duck_list = Duck('sample', 'example.net') aliases = list(self.utility.aliases(duck_list)) self.assertEqual(aliases, [ @@ -129,7 +122,6 @@ class TestAliases(unittest.TestCase): ]) - class TestPostfix(unittest.TestCase): """Test the Postfix LMTP alias generator.""" @@ -137,15 +129,13 @@ class TestPostfix(unittest.TestCase): def setUp(self): self.tempdir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, self.tempdir) self.utility = getUtility(IMailTransportAgentAliases) self.mlist = create_list('test@example.com') self.postfix = LMTP() # Let assertMultiLineEqual work without bounds. self.maxDiff = None - def tearDown(self): - shutil.rmtree(self.tempdir) - def test_aliases(self): # Test the format of the Postfix alias generator. self.postfix.regenerate(self.tempdir) diff --git a/src/mailman/mta/tests/test_connection.py b/src/mailman/mta/tests/test_connection.py index 3590808b7..3c4114634 100644 --- a/src/mailman/mta/tests/test_connection.py +++ b/src/mailman/mta/tests/test_connection.py @@ -17,11 +17,6 @@ """Test MTA connections.""" -__all__ = [ - 'TestConnection', - ] - - import unittest from mailman.config import config @@ -30,7 +25,6 @@ from mailman.testing.layers import SMTPLayer from smtplib import SMTPAuthenticationError - class TestConnection(unittest.TestCase): layer = SMTPLayer diff --git a/src/mailman/mta/tests/test_delivery.py b/src/mailman/mta/tests/test_delivery.py index a953f331f..fda74faad 100644 --- a/src/mailman/mta/tests/test_delivery.py +++ b/src/mailman/mta/tests/test_delivery.py @@ -17,11 +17,6 @@ """Test various aspects of email delivery.""" -__all__ = [ - 'TestIndividualDelivery', - ] - - import os import shutil import tempfile @@ -36,10 +31,10 @@ from mailman.testing.helpers import ( from mailman.testing.layers import ConfigLayer - # Global test capture. _deliveries = [] + # Derive this from the default individual delivery class. The point being # that we don't want to *actually* attempt delivery of the message to the MTA, # we just want to capture the messages and metadata dictionaries for @@ -51,7 +46,6 @@ class DeliverTester(Deliver): return [] - class TestIndividualDelivery(unittest.TestCase): """Test personalized delivery details.""" @@ -72,6 +66,7 @@ Subject: test """) # Set up a personalized footer for decoration. self._template_dir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, self._template_dir) path = os.path.join(self._template_dir, 'site', 'en', 'member-footer.txt') os.makedirs(os.path.dirname(path)) @@ -87,15 +82,14 @@ options : $user_optionsurl [paths.testing] template_dir: {0} """.format(self._template_dir)) + self.addCleanup(config.pop, 'templates') self._mlist.footer_uri = 'mailman:///member-footer.txt' # Let assertMultiLineEqual work without bounds. self.maxDiff = None def tearDown(self): - # Free references. + # Free global references. del _deliveries[:] - shutil.rmtree(self._template_dir) - config.pop('templates') def test_member_key(self): # 'personalize' should end up in the metadata dictionary so that diff --git a/src/mailman/mta/verp.py b/src/mailman/mta/verp.py index b4de5474c..87c6609a0 100644 --- a/src/mailman/mta/verp.py +++ b/src/mailman/mta/verp.py @@ -17,14 +17,9 @@ """VERP delivery.""" -__all__ = [ - 'VERPDelivery', - 'VERPMixin', - ] - - import logging +from mailman import public from mailman.config import config from mailman.mta.base import IndividualDelivery from mailman.utilities.email import split_email @@ -35,7 +30,7 @@ DOT = '.' log = logging.getLogger('mailman.smtp') - +@public class VERPMixin: """Mixin for VERP functionality. @@ -90,7 +85,7 @@ class VERPMixin: msg['X-Mailman-Copy'] = 'yes' - +@public class VERPDelivery(VERPMixin, IndividualDelivery): """Deliver a unique message to the MSA for each recipient.""" |
