Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
bd861e89 by Mark Sapiro at 2021-04-18T14:29:59-07:00
Pend a msgid when saving a DSN to avoid premature deletion.

- - - - -
a767e0db by Mark Sapiro at 2021-04-18T21:53:16+00:00
Merge branch 'dsn' into 'master'

Pend a msgid when saving a DSN to avoid premature deletion.

See merge request mailman/mailman!837
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/runners/bounce.py
- src/mailman/runners/tests/test_bounce.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -38,6 +38,7 @@ Bugs
   pagination in database layer. (Closes #876)
 * Attempts to get a message from the message store with a missing file are
   now handled.  (Closes #877)
+* The task runner no longer prematurely deletes saved DSNs.  (Closes #878)
 
 Command line
 ------------


=====================================
src/mailman/runners/bounce.py
=====================================
@@ -21,11 +21,14 @@ import logging
 
 from email.utils import make_msgid
 from flufl.bounce import all_failures
-from mailman.app.bounces import ProbeVERP, StandardVERP, maybe_forward
+from lazr.config import as_timedelta
+from mailman.app.bounces import (
+    PENDABLE_LIFETIME, ProbeVERP, StandardVERP, _ProbePendable, maybe_forward)
 from mailman.core.runner import Runner
 from mailman.interfaces.bounce import (
     BounceContext, IBounceProcessor, InvalidBounceEvent)
 from mailman.interfaces.messages import IMessageStore
+from mailman.interfaces.pending import IPendings
 from public import public
 from zope.component import getUtility
 
@@ -94,6 +97,14 @@ class BounceRunner(Runner):
                 if msg.get('message-id') is None:
                     msg['Message-ID'] = make_msgid          # pragma: nocover
                 getUtility(IMessageStore).add(msg)
+                # We also need to pend a token for this or the message will be
+                # removed as an orphan by the task runner.  We don't need much
+                # from this.  We pend the msgid as _mod_message_id for the
+                # task runner.
+                pendable = _ProbePendable(
+                    _mod_message_id=msg.get('message-id'))
+                getUtility(IPendings).add(
+                    pendable, lifetime=as_timedelta(PENDABLE_LIFETIME))
                 self._processor.register(mlist, address, msg, context)
         else:
             log.info('Bounce message w/no discernable addresses: %s',


=====================================
src/mailman/runners/tests/test_bounce.py
=====================================
@@ -28,6 +28,7 @@ from mailman.interfaces.bounce import (
     BounceContext, IBounceProcessor, UnrecognizedBounceDisposition)
 from mailman.interfaces.languages import ILanguageManager
 from mailman.interfaces.member import DeliveryStatus, MemberRole
+from mailman.interfaces.pending import IPendings
 from mailman.interfaces.styles import IStyle, IStyleManager
 from mailman.interfaces.usermanager import IUserManager
 from mailman.runners.bounce import BounceRunner
@@ -61,6 +62,7 @@ Message-Id: <first>
 """)
         self._msgdata = dict(listid='test.example.com')
         self._processor = getUtility(IBounceProcessor)
+        self._pendings = getUtility(IPendings)
         config.push('site owner', """
         [mailman]
         site_owner: postmas...@example.com
@@ -245,6 +247,24 @@ Message-Id: <third>
         items = get_queue_messages('virgin', expected_count=1)
         self.assertEqual(items[0].msg['to'], 'postmas...@example.com')
 
+    def test_saving_dsn_pends_msgid(self):
+        # When we save a DSN for notices, we have to pend its msgid so task
+        # Runner won't remove it as an orphan.
+        self._bounceq.enqueue(self._msg, self._msgdata)
+        self._runner.run()
+        get_queue_messages('bounces', expected_count=0)
+        events = list(self._processor.events)
+        self.assertEqual(len(events), 1)
+        self.assertEqual(events[0].email, 'a...@example.com')
+        self.assertEqual(events[0].list_id, 'test.example.com')
+        self.assertEqual(events[0].message_id, '<first>')
+        self.assertEqual(events[0].context, BounceContext.normal)
+        self.assertEqual(events[0].processed, True)
+        # Check for a pended item with the msgid.
+        self.assertEqual(self._pendings.count(), 1)
+        token, pended = list(self._pendings)[0]
+        self.assertEqual(pended['_mod_message_id'], '<first>')
+
     def test_bounce_increment_notice_sent_with_dsn(self):
         # Test that bounce_notify_owner_on_bounce_increment sends a notice
         # and the notice contains the DSN.



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/d711ba42c1d0dfb3aed48f923d69853275c652d2...a767e0db48891aa8be48977abd6b7b2be7ac052e

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/d711ba42c1d0dfb3aed48f923d69853275c652d2...a767e0db48891aa8be48977abd6b7b2be7ac052e
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list -- mailman-checkins@python.org
To unsubscribe send an email to mailman-checkins-le...@python.org
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: arch...@jab.org

Reply via email to