diff options
| author | Barry Warsaw | 2017-08-04 01:13:04 +0000 |
|---|---|---|
| committer | Barry Warsaw | 2017-08-04 01:13:04 +0000 |
| commit | 324226f1f859f6be5e932dc9abe638aba268d154 (patch) | |
| tree | f021166b8c82bb02feff82a9360ba61a44b804ee /src/mailman/app | |
| parent | e6326533b78290514ede917ed1cb95804759a45a (diff) | |
| parent | 9cdcffbc1189a19bc2963cf3d5c86a3d4f1f24a6 (diff) | |
| download | mailman-324226f1f859f6be5e932dc9abe638aba268d154.tar.gz mailman-324226f1f859f6be5e932dc9abe638aba268d154.tar.zst mailman-324226f1f859f6be5e932dc9abe638aba268d154.zip | |
Merge branch 'rename-metadata-key' into 'master'
Rename metadata key for clarity
Compose bounce messages so that they can be properly translated
See merge request !304
Diffstat (limited to 'src/mailman/app')
| -rw-r--r-- | src/mailman/app/bounces.py | 16 | ||||
| -rw-r--r-- | src/mailman/app/docs/bounces.rst | 64 |
2 files changed, 64 insertions, 16 deletions
diff --git a/src/mailman/app/bounces.py b/src/mailman/app/bounces.py index 1239c916c..0d9a6ccb9 100644 --- a/src/mailman/app/bounces.py +++ b/src/mailman/app/bounces.py @@ -45,6 +45,7 @@ elog = logging.getLogger('mailman.error') blog = logging.getLogger('mailman.bounce') DOT = '.' +NL = '\n' @public @@ -56,8 +57,12 @@ def bounce_message(mlist, msg, error=None): :param msg: The original message. :type msg: `email.message.Message` :param error: Optional exception causing the bounce. The exception - instance must have a `.message` attribute. - :type error: Exception + instance must have a `.message` attribute. The exception *may* have a + non-None `.reasons` attribute which would be a list of reasons for the + rejection, and it may have a non-None `.substitutions` attribute. The + latter, along with the formatted reasons will be interpolated into the + message (`.reasons` gets put into the `$reasons` placeholder). + :type error: RejectMessage """ # Bounce a message back to the sender, with an error message if provided # in the exception argument. .sender might be None or the empty string. @@ -67,10 +72,9 @@ def bounce_message(mlist, msg, error=None): return subject = msg.get('subject', _('(no subject)')) subject = oneline(subject, mlist.preferred_language.charset) - if error is None: - notice = _('[No bounce details are available]') - else: - notice = _(error.message) + notice = (_('[No bounce details are available]') + if error is None + else str(error)) # Currently we always craft bounces as MIME messages. bmsg = UserNotification(msg.sender, mlist.owner_address, subject, lang=mlist.preferred_language) diff --git a/src/mailman/app/docs/bounces.rst b/src/mailman/app/docs/bounces.rst index 99eae8b2c..b25381031 100644 --- a/src/mailman/app/docs/bounces.rst +++ b/src/mailman/app/docs/bounces.rst @@ -12,12 +12,12 @@ Mailman can bounce messages back to the original sender. This is essentially equivalent to rejecting the message with notification. Mailing lists can bounce a message with an optional error message. - >>> mlist = create_list('text@example.com') + >>> mlist = create_list('ant@example.com') Any message can be bounced. >>> msg = message_from_string("""\ - ... To: text@example.com + ... To: ant@example.com ... From: aperson@example.com ... Subject: Something important ... @@ -36,7 +36,7 @@ to the original message author. 1 >>> print(items[0].msg.as_string()) Subject: Something important - From: text-owner@example.com + From: ant-owner@example.com To: aperson@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="..." @@ -54,7 +54,7 @@ to the original message author. Content-Type: message/rfc822 MIME-Version: 1.0 <BLANKLINE> - To: text@example.com + To: ant@example.com From: aperson@example.com Subject: Something important <BLANKLINE> @@ -63,18 +63,16 @@ to the original message author. --...-- An error message can be given when the message is bounced, and this will be -included in the payload of the text/plain part. The error message must be +included in the payload of the ``text/plain`` part. The error message must be passed in as an instance of a ``RejectMessage`` exception. >>> from mailman.interfaces.pipeline import RejectMessage >>> error = RejectMessage("This wasn't very important after all.") >>> bounce_message(mlist, msg, error) - >>> items = get_queue_messages('virgin') - >>> len(items) - 1 + >>> items = get_queue_messages('virgin', expected_count=1) >>> print(items[0].msg.as_string()) Subject: Something important - From: text-owner@example.com + From: ant-owner@example.com To: aperson@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="..." @@ -92,10 +90,56 @@ passed in as an instance of a ``RejectMessage`` exception. Content-Type: message/rfc822 MIME-Version: 1.0 <BLANKLINE> - To: text@example.com + To: ant@example.com From: aperson@example.com Subject: Something important <BLANKLINE> I sometimes say something important. <BLANKLINE> --...-- + +The ``RejectMessage`` exception can also include a set of reasons, which will +be interpolated into the message using the ``{reasons}`` placeholder. + + >>> error = RejectMessage("""This message is rejected because: + ... + ... $reasons + ... """, [ + ... 'I am not happy', + ... 'You are not happy', + ... 'We are not happy']) + >>> bounce_message(mlist, msg, error) + >>> items = get_queue_messages('virgin', expected_count=1) + >>> print(items[0].msg.as_string()) + Subject: Something important + From: ant-owner@example.com + To: aperson@example.com + MIME-Version: 1.0 + Content-Type: multipart/mixed; boundary="..." + Message-ID: ... + Date: ... + Precedence: bulk + <BLANKLINE> + --... + Content-Type: text/plain; charset="us-ascii" + MIME-Version: 1.0 + Content-Transfer-Encoding: 7bit + <BLANKLINE> + This message is rejected because: + <BLANKLINE> + I am not happy + You are not happy + We are not happy + <BLANKLINE> + --... + Content-Type: message/rfc822 + MIME-Version: 1.0 + <BLANKLINE> + To: ant@example.com + From: aperson@example.com + Subject: Something important + <BLANKLINE> + I sometimes say something important. + <BLANKLINE> + --... + <BLANKLINE> |
