def test_dispose_bounce(self):
     self._mlist.filter_action = FilterAction.reject
     with self.assertRaises(RejectMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'rejecting')
     self.assertEqual(cm.exception.message, 'rejecting')
     # There should be no messages in the 'bad' queue.
     get_queue_messages('bad', expected_count=0)
Exemple #2
0
 def test_dispose_discard(self):
     self._mlist.filter_action = FilterAction.discard
     with self.assertRaises(DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'discarding')
     self.assertEqual(cm.exception.message, 'discarding')
     # There should be no messages in the 'bad' queue.
     get_queue_messages('bad', expected_count=0)
Exemple #3
0
 def test_dispose_discard(self):
     self._mlist.filter_action = FilterAction.discard
     with self.assertRaises(errors.DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'discarding')
     self.assertEqual(cm.exception.message, 'discarding')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
Exemple #4
0
 def test_dispose_bounce(self):
     self._mlist.filter_action = FilterAction.reject
     with self.assertRaises(errors.RejectMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'rejecting')
     self.assertEqual(cm.exception.message, 'rejecting')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
Exemple #5
0
 def test_dispose_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages can be
     # preserved, then this is similar to discarding the message except
     # that a copy is preserved in the 'bad' queue.
     self._mlist.filter_action = FilterAction.preserve
     config.push('preservable', """
     [mailman]
     filtered_messages_are_preservable: yes
     """)
     try:
         mime_delete.dispose(self._mlist, self._msg, {}, 'preserved')
     except errors.DiscardMessage as error:
         pass
     else:
         raise AssertionError('DiscardMessage exception expected')
     finally:
         config.pop('preservable')
     self.assertEqual(error.message, 'preserved')
     # There should be no messages in the 'bad' queue.
     messages = get_queue_messages('bad')
     self.assertEqual(len(messages), 1)
     message = messages[0].msg
     self.assertEqual(message['subject'], 'A disposable message')
     self.assertEqual(message['message-id'], '<ant>')
 def test_dispose_non_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages cannot be
     # preserved, then this is the same as discarding them.
     self._mlist.filter_action = FilterAction.preserve
     with self.assertRaises(DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'not preserved')
     self.assertEqual(cm.exception.message, 'not preserved')
     # There should be no messages in the 'bad' queue.
     get_queue_messages('bad', expected_count=0)
Exemple #7
0
 def test_dispose_non_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages cannot be
     # preserved, then this is the same as discarding them.
     self._mlist.filter_action = FilterAction.preserve
     with self.assertRaises(errors.DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'not preserved')
     self.assertEqual(cm.exception.message, 'not preserved')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
Exemple #8
0
 def test_dispose_bounce(self):
     self._mlist.filter_action = FilterAction.reject
     try:
         mime_delete.dispose(self._mlist, self._msg, {}, 'rejecting')
     except errors.RejectMessage as error:
         pass
     else:
         raise AssertionError('RejectMessage exception expected')
     self.assertEqual(error.message, 'rejecting')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
 def test_dispose_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages can be
     # preserved, then this is similar to discarding the message except
     # that a copy is preserved in the 'bad' queue.
     self._mlist.filter_action = FilterAction.preserve
     with self.assertRaises(DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'preserved')
     self.assertEqual(cm.exception.message, 'preserved')
     # There should be no messages in the 'bad' queue.
     items = get_queue_messages('bad', expected_count=1)
     message = items[0].msg
     self.assertEqual(message['subject'], 'A disposable message')
     self.assertEqual(message['message-id'], '<ant>')
Exemple #10
0
 def test_dispose_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages can be
     # preserved, then this is similar to discarding the message except
     # that a copy is preserved in the 'bad' queue.
     self._mlist.filter_action = FilterAction.preserve
     with self.assertRaises(DiscardMessage) as cm:
         mime_delete.dispose(self._mlist, self._msg, {}, 'preserved')
     self.assertEqual(cm.exception.message, 'preserved')
     # There should be no messages in the 'bad' queue.
     items = get_queue_messages('bad', expected_count=1)
     message = items[0].msg
     self.assertEqual(message['subject'], 'A disposable message')
     self.assertEqual(message['message-id'], '<ant>')
Exemple #11
0
    def test_dispose_forward(self):
        # The disposed message gets forwarded to the list moderators.  So
        # first add some moderators.
        user_manager = getUtility(IUserManager)
        anne = user_manager.create_address('*****@*****.**')
        bart = user_manager.create_address('*****@*****.**')
        self._mlist.subscribe(anne, MemberRole.moderator)
        self._mlist.subscribe(bart, MemberRole.moderator)
        # Now set the filter action and dispose the message.
        self._mlist.filter_action = FilterAction.forward
        try:
            mime_delete.dispose(self._mlist, self._msg, {}, 'forwarding')
        except errors.DiscardMessage as error:
            pass
        else:
            raise AssertionError('DiscardMessage exception expected')
        self.assertEqual(error.message, 'forwarding')
        # There should now be a multipart message in the virgin queue destined
        # for the mailing list owners.
        messages = get_queue_messages('virgin')
        self.assertEqual(len(messages), 1)
        message = messages[0].msg
        self.assertEqual(message.get_content_type(), 'multipart/mixed')
        # Anne and Bart should be recipients of the message, but it will look
        # like the message is going to the list owners.
        self.assertEqual(message['to'], '*****@*****.**')
        self.assertEqual(message.recipients,
                         set(['*****@*****.**', '*****@*****.**']))
        # The list owner should be the sender.
        self.assertEqual(message['from'], '*****@*****.**')
        self.assertEqual(message['subject'],
                         'Content filter message notification')
        # The body of the first part provides the moderators some details.
        part0 = message.get_payload(0)
        self.assertEqual(part0.get_content_type(), 'text/plain')
        self.eq(part0.get_payload(), """\
The attached message matched the Test mailing list's content
filtering rules and was prevented from being forwarded on to the list
membership.  You are receiving the only remaining copy of the discarded
message.

""")
        # The second part is the container for the original message.
        part1 = message.get_payload(1)
        self.assertEqual(part1.get_content_type(), 'message/rfc822')
        # And the first part of *that* message will be the original message.
        original = part1.get_payload(0)
        self.assertEqual(original['subject'], 'A disposable message')
        self.assertEqual(original['message-id'], '<ant>')
Exemple #12
0
 def test_bad_action(self):
     # This should never happen, but what if it does?
     # FilterAction.accept, FilterAction.hold, and FilterAction.defer are
     # not valid.  They are treated as discard actions, but the problem is
     # also logged.
     for action in (FilterAction.accept, FilterAction.hold,
                    FilterAction.defer):
         self._mlist.filter_action = action
         mark = LogFileMark('mailman.error')
         with self.assertRaises(errors.DiscardMessage) as cm:
             mime_delete.dispose(self._mlist, self._msg, {}, 'bad action')
         self.assertEqual(cm.exception.message, 'bad action')
         line = mark.readline()[:-1]
         self.assertTrue(
             line.endswith('{0} invalid FilterAction: [email protected].  '
                           'Treating as discard'.format(action.name)))
Exemple #13
0
    def test_dispose_forward(self):
        # The disposed message gets forwarded to the list moderators.  So
        # first add some moderators.
        user_manager = getUtility(IUserManager)
        anne = user_manager.create_address('*****@*****.**')
        bart = user_manager.create_address('*****@*****.**')
        self._mlist.subscribe(anne, MemberRole.moderator)
        self._mlist.subscribe(bart, MemberRole.moderator)
        # Now set the filter action and dispose the message.
        self._mlist.filter_action = FilterAction.forward
        with self.assertRaises(errors.DiscardMessage) as cm:
            mime_delete.dispose(self._mlist, self._msg, {}, 'forwarding')
        self.assertEqual(cm.exception.message, 'forwarding')
        # There should now be a multipart message in the virgin queue destined
        # for the mailing list owners.
        messages = get_queue_messages('virgin')
        self.assertEqual(len(messages), 1)
        message = messages[0].msg
        self.assertEqual(message.get_content_type(), 'multipart/mixed')
        # Anne and Bart should be recipients of the message, but it will look
        # like the message is going to the list owners.
        self.assertEqual(message['to'], '*****@*****.**')
        self.assertEqual(message.recipients,
                         set(['*****@*****.**', '*****@*****.**']))
        # The list owner should be the sender.
        self.assertEqual(message['from'], '*****@*****.**')
        self.assertEqual(message['subject'],
                         'Content filter message notification')
        # The body of the first part provides the moderators some details.
        part0 = message.get_payload(0)
        self.assertEqual(part0.get_content_type(), 'text/plain')
        self.assertMultiLineEqual(
            part0.get_payload(), """\
The attached message matched the Test mailing list's content
filtering rules and was prevented from being forwarded on to the list
membership.  You are receiving the only remaining copy of the discarded
message.

""")
        # The second part is the container for the original message.
        part1 = message.get_payload(1)
        self.assertEqual(part1.get_content_type(), 'message/rfc822')
        # And the first part of *that* message will be the original message.
        original = part1.get_payload(0)
        self.assertEqual(original['subject'], 'A disposable message')
        self.assertEqual(original['message-id'], '<ant>')
Exemple #14
0
 def test_bad_action(self):
     # This should never happen, but what if it does?
     # FilterAction.accept, FilterAction.hold, and FilterAction.defer are
     # not valid.  They are treated as discard actions, but the problem is
     # also logged.
     for action in (FilterAction.accept,
                    FilterAction.hold,
                    FilterAction.defer):
         self._mlist.filter_action = action
         mark = LogFileMark('mailman.error')
         with self.assertRaises(errors.DiscardMessage) as cm:
             mime_delete.dispose(self._mlist, self._msg, {}, 'bad action')
         self.assertEqual(cm.exception.message, 'bad action')
         line = mark.readline()[:-1]
         self.assertTrue(line.endswith(
             '{0} invalid FilterAction: [email protected].  '
             'Treating as discard'.format(action.name)))
Exemple #15
0
 def test_dispose_non_preservable(self):
     # Two actions can happen here, depending on a site-wide setting.  If
     # the site owner has indicated that filtered messages cannot be
     # preserved, then this is the same as discarding them.
     self._mlist.filter_action = FilterAction.preserve
     config.push('non-preservable', """
     [mailman]
     filtered_messages_are_preservable: no
     """)
     try:
         mime_delete.dispose(self._mlist, self._msg, {}, 'not preserved')
     except errors.DiscardMessage as error:
         pass
     else:
         raise AssertionError('DiscardMessage exception expected')
     finally:
         config.pop('non-preservable')
     self.assertEqual(error.message, 'not preserved')
     # There should be no messages in the 'bad' queue.
     self.assertEqual(len(get_queue_messages('bad')), 0)
Exemple #16
0
 def test_dispose_discard_no_spurious_log(self):
     self._mlist.filter_action = FilterAction.discard
     mark = LogFileMark('mailman.error')
     with self.assertRaises(DiscardMessage):
         mime_delete.dispose(self._mlist, self._msg, {}, 'discarding')
     self.assertEqual(mark.readline(), '')