diff options
Diffstat (limited to 'tests/test_handlers.py')
-rw-r--r-- | tests/test_handlers.py | 188 |
1 files changed, 166 insertions, 22 deletions
diff --git a/tests/test_handlers.py b/tests/test_handlers.py index aa73b3c1..8f6219e8 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2001-2011 by the Free Software Foundation, Inc. +# Copyright (C) 2001-2015 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -76,6 +76,7 @@ class TestAcknowledge(TestBase): # Add a member self._mlist.addNewMember('aperson@dom.ain') self._mlist.personalize = False + self._mlist.dmarc_moderation_action = 0 def tearDown(self): for f in os.listdir(mm_cfg.VIRGINQUEUE_DIR): @@ -591,82 +592,220 @@ Subject: Re: [XTEST] About Mailman... eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 1 + mlist.from_is_list = 0 msg = email.message_from_string("""\ From: aperson@dom.ain """, Message.Message) - CookHeaders.process(mlist, msg, {}) - eq(msg['reply-to'], '_xtest@dom.ain') - eq(msg.get_all('reply-to'), ['_xtest@dom.ain']) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], '_xtest@dom.ain') + eq(msg.get_all('reply-to'), None) + + def test_reply_to_list_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 1 + mlist.from_is_list = 1 + msg = email.message_from_string("""\ +From: aperson@dom.ain + +""", Message.Message) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + '_xtest@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), None) + eq(msg.get_all('cc'), None) def test_reply_to_list_with_strip(self): eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 1 mlist.first_strip_reply_to = 1 + mlist.from_is_list = 0 msg = email.message_from_string("""\ From: aperson@dom.ain Reply-To: bperson@dom.ain """, Message.Message) - CookHeaders.process(mlist, msg, {}) - eq(msg['reply-to'], '_xtest@dom.ain') - eq(msg.get_all('reply-to'), ['_xtest@dom.ain']) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], '_xtest@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + + def test_reply_to_list_with_strip_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 1 + mlist.first_strip_reply_to = 1 + mlist.from_is_list = 1 + msg = email.message_from_string("""\ +From: aperson@dom.ain +Reply-To: bperson@dom.ain + +""", Message.Message) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + '_xtest@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + eq(msg.get_all('cc'), None) + def test_reply_to_explicit(self): eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 2 + mlist.from_is_list = 0 mlist.reply_to_address = 'mlist@dom.ain' msg = email.message_from_string("""\ From: aperson@dom.ain """, Message.Message) - CookHeaders.process(mlist, msg, {}) - eq(msg['reply-to'], 'mlist@dom.ain') - eq(msg.get_all('reply-to'), ['mlist@dom.ain']) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], 'mlist@dom.ain') + eq(msg.get_all('reply-to'), None) + + def test_reply_to_explicit_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 2 + mlist.from_is_list = 1 + mlist.reply_to_address = 'mlist@dom.ain' + msg = email.message_from_string("""\ +From: aperson@dom.ain + +""", Message.Message) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'mlist@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), None) + eq(msg.get_all('cc'), None) def test_reply_to_explicit_with_strip(self): eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 2 mlist.first_strip_reply_to = 1 + mlist.from_is_list = 0 mlist.reply_to_address = 'mlist@dom.ain' msg = email.message_from_string("""\ From: aperson@dom.ain Reply-To: bperson@dom.ain """, Message.Message) - CookHeaders.process(self._mlist, msg, {}) - eq(msg['reply-to'], 'mlist@dom.ain') - eq(msg.get_all('reply-to'), ['mlist@dom.ain']) + msgdata = {} + + CookHeaders.process(self._mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], 'mlist@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + + def test_reply_to_explicit_with_strip_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 2 + mlist.first_strip_reply_to = 1 + mlist.from_is_list = 1 + mlist.reply_to_address = 'mlist@dom.ain' + msg = email.message_from_string("""\ +From: aperson@dom.ain +Reply-To: bperson@dom.ain + +""", Message.Message) + msgdata = {} + + CookHeaders.process(self._mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'mlist@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + eq(msg.get_all('cc'), None) def test_reply_to_extends_to_list(self): eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 1 mlist.first_strip_reply_to = 0 + mlist.from_is_list = 0 msg = email.message_from_string("""\ From: aperson@dom.ain Reply-To: bperson@dom.ain """, Message.Message) - CookHeaders.process(mlist, msg, {}) - eq(msg['reply-to'], 'bperson@dom.ain, _xtest@dom.ain') + msgdata = {} + + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'bperson@dom.ain, _xtest@dom.ain') + + def test_reply_to_extends_to_list_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 1 + mlist.first_strip_reply_to = 0 + mlist.from_is_list = 1 + msg = email.message_from_string("""\ +From: aperson@dom.ain +Reply-To: bperson@dom.ain + +""", Message.Message) + msgdata = {} + + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'bperson@dom.ain, _xtest@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + eq(msg.get_all('cc'), None) def test_reply_to_extends_to_explicit(self): eq = self.assertEqual mlist = self._mlist mlist.reply_goes_to_list = 2 mlist.first_strip_reply_to = 0 + mlist.from_is_list = 0 + mlist.reply_to_address = 'mlist@dom.ain' + msg = email.message_from_string("""\ +From: aperson@dom.ain +Reply-To: bperson@dom.ain + +""", Message.Message) + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'mlist@dom.ain, bperson@dom.ain') + + def test_reply_to_extends_to_explicit_fil(self): + eq = self.assertEqual + mlist = self._mlist + mlist.reply_goes_to_list = 2 + mlist.first_strip_reply_to = 0 + mlist.from_is_list = 1 mlist.reply_to_address = 'mlist@dom.ain' msg = email.message_from_string("""\ From: aperson@dom.ain Reply-To: bperson@dom.ain """, Message.Message) - CookHeaders.process(mlist, msg, {}) - eq(msg['reply-to'], 'mlist@dom.ain, bperson@dom.ain') + msgdata = {} + CookHeaders.process(mlist, msg, msgdata) + eq(msgdata['add_header']['Reply-To'], + 'mlist@dom.ain, bperson@dom.ain') + eq(msgdata['add_header']['Cc'], + 'aperson@dom.ain') + eq(msg.get_all('reply-to'), ['bperson@dom.ain']) + eq(msg.get_all('cc'), None) def test_list_headers_nolist(self): eq = self.assertEqual @@ -704,7 +843,7 @@ From: aperson@dom.ain '<http://www.dom.ain/mailman/listinfo/_xtest>,' '\n\t<mailto:_xtest-request@dom.ain?subject=subscribe>') eq(msg['list-post'], '<mailto:_xtest@dom.ain>') - eq(msg['list-archive'], '<http://www.dom.ain/pipermail/_xtest>') + eq(msg['list-archive'], '<http://www.dom.ain/pipermail/_xtest/>') def test_list_headers_with_description(self): eq = self.assertEqual @@ -862,7 +1001,8 @@ Content-Transfer-Encoding: 7bit Content-Disposition: inline footer ---BOUNDARY--""") +--BOUNDARY-- +""") def test_image(self): eq = self.assertEqual @@ -1221,7 +1361,8 @@ MIME-Version: 1.0 """) MimeDel.process(self._mlist, msg, {}) eq(msg.get_content_type(), 'text/plain') - eq(msg.get_payload(), '\n\n\n') + #eq(msg.get_payload(), '\n\n\n') + eq(msg.get_payload().strip(), '') def test_deep_structure(self): eq = self.assertEqual @@ -1630,7 +1771,8 @@ class TestReplybot(TestBase): class TestSpamDetect(TestBase): def test_short_circuit(self): msgdata = {'approved': 1} - rtn = SpamDetect.process(self._mlist, None, msgdata) + msg = email.message_from_string('') + rtn = SpamDetect.process(self._mlist, msg, msgdata) # Not really a great test, but there's little else to assert self.assertEqual(rtn, None) @@ -1878,7 +2020,9 @@ Here is message %(i)d mlist = self._mlist msg = self._makemsg(99) size = os.path.getsize(self._path) + len(str(msg)) - mlist.digest_size_threshhold = 0 + # Set digest_size_threshhold to a very small value to force a digest. + # Setting to zero no longer works. + mlist.digest_size_threshhold = 0.001 ToDigest.process(mlist, msg, {}) files = self._sb.files() # There should be two files in the queue, one for the MIME digest and |