def test_nodecorate_verp(self): # Ensure that verp postings don't get decorated twice. msgdata = {'verp': True} process(self._mlist, self._msg, msgdata, pipeline_name='default-posting-pipeline') payload = self._msg.get_payload() self.assertEqual(payload.count('Test mailing list'), 1)
def _dispose(self, mlist, msg, msgdata): # Process the message through the mailing list's pipeline. pipeline = (mlist.owner_pipeline if msgdata.get('to_owner', False) else mlist.posting_pipeline) process(mlist, msg, msgdata, pipeline) # Do not keep this message queued. return False
def test_rfc2369_headers(self): # Ensure that RFC 2369 List-* headers are added. msgdata = {} process(self._mlist, self._msg, msgdata, pipeline_name='default-posting-pipeline') self.assertEqual(self._msg['list-id'], '<test.example.com>') self.assertEqual(self._msg['list-post'], '<mailto:[email protected]>')
def test_decorate_bulk(self): # Ensure that bulk postings get decorated with the footer. process(self._mlist, self._msg, {}, pipeline_name='default-posting-pipeline') payload = self._msg.get_payload() self.assertIn('Test mailing list', payload)
def test_to_outgoing(self): # The message, with the calculated recipients, gets put in the # outgoing queue. process(self._mlist, self._msg, {}, pipeline_name='default-owner-pipeline') items = get_queue_messages('out', sort_on='to', expected_count=1) self.assertEqual(items[0].msgdata['recipients'], set(('*****@*****.**', '*****@*****.**')))
def _dispose(self, mlist, msg, msgdata): # We need to fast track this message through any pipeline handlers # that touch it, e.g. especially cook-headers. msgdata['_fasttrack'] = True # Use the 'virgin' pipeline. process(mlist, msg, msgdata, 'virgin') # Do not keep this message queued. return False
def test_calculate_recipients(self): # Recipients are the administrators of the mailing list. msgdata = dict(listname='*****@*****.**', to_owner=True) process(self._mlist, self._msg, msgdata, pipeline_name='default-owner-pipeline') self.assertEqual(msgdata['recipients'], set(('*****@*****.**', '*****@*****.**')))
def test_discarding_pipeline(self): # If a handler in the pipeline raises DiscardMessage, the message will # be thrown away, but with a log message. mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-discarding') line = mark.readline()[:-1] self.assertTrue(line.endswith( '<ant> discarded by "test-discarding" pipeline handler ' '"discarding": by test handler'))
def test_rejecting_pipeline(self): # If a handler in the pipeline raises DiscardMessage, the message will # be thrown away, but with a log message. mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-rejecting') line = mark.readline()[:-1] self.assertTrue(line.endswith( '<ant> rejected by "test-rejecting" pipeline handler ' '"rejecting": by test handler')) # In the rejection case, the original message will also be in the # virgin queue. items = get_queue_messages('virgin', expected_count=1) self.assertEqual(str(items[0].msg['subject']), 'a test')
def test_rejecting_pipeline(self): # If a handler in the pipeline raises DiscardMessage, the message will # be thrown away, but with a log message. mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-rejecting') line = mark.readline()[:-1] self.assertTrue( line.endswith( '<ant> rejected by "test-rejecting" pipeline handler ' '"rejecting": by test handler')) # In the rejection case, the original message will also be in the # virgin queue. items = get_queue_messages('virgin', expected_count=1) self.assertEqual(str(items[0].msg['subject']), 'a test')
def test_rejecting_pipeline(self): # If a handler in the pipeline raises RejectMessage, the post will # be bounced with a log message. mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-rejecting') line = mark.readline()[:-1] self.assertEqual( line[-80:], '<ant> rejected by "test-rejecting" pipeline handler ' '"rejecting": by test handler', line) # In the rejection case, the original message will also be in the # virgin queue. items = get_queue_messages('virgin', expected_count=1) self.assertEqual( str(items[0].msg.get_payload(1).get_payload(0)['subject']), 'a test') # The first payload contains the rejection reason. payload = items[0].msg.get_payload(0).get_payload() self.assertEqual(payload, 'by test handler')
def test_only_decorate_output(self): # Ensure that decoration is not done on the archive, digest, or # usenet copy of the message. self.assertTrue(self._mlist.digests_enabled) # Set up NNTP. self._mlist.gateway_to_news = True self._mlist.linked_newsgroup = 'testing' self._mlist.nntp_host = 'news.example.com' # Process the email. process(self._mlist, self._msg, {}, pipeline_name='default-posting-pipeline') for queue in ('archive', 'nntp'): items = get_queue_messages(queue, expected_count=1) payload = items[0].msg.get_payload() self.assertNotIn('Test mailing list', payload) self.assertEqual(len(digest_mbox(self._mlist)), 1) payload = digest_mbox(self._mlist)[0].get_payload() self.assertNotIn('Test mailing list', payload)
def test_rejecting_pipeline_without_message(self): # Similar to above, but without a rejection message. pipeline = config.pipelines['test-rejecting'] message = pipeline.message self.addCleanup(setattr, pipeline, 'message', message) pipeline.message = None mark = LogFileMark('mailman.vette') process(self._mlist, self._msg, {}, 'test-rejecting') line = mark.readline()[:-1] self.assertEqual( line[-91:], '<ant> rejected by "test-rejecting" pipeline handler ' '"rejecting": [No details are available]', line) # In the rejection case, the original message will also be in the # virgin queue. items = get_queue_messages('virgin', expected_count=1) self.assertEqual( str(items[0].msg.get_payload(1).get_payload(0)['subject']), 'a test') # The first payload contains the rejection reason. payload = items[0].msg.get_payload(0).get_payload() self.assertEqual(payload, '[No details are available]')
def test_rfc2369_headers_virgin(self): # Internally crafted messages should get reduced List-* headers. msgdata = {'reduced_list_headers': True} process(self._mlist, self._msg, msgdata, pipeline_name='virgin') self.assertEqual(self._msg['list-id'], '<test.example.com>') self.assertIsNone(self._msg['list-post'])