aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_handlers.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_handlers.py217
1 files changed, 184 insertions, 33 deletions
diff --git a/tests/test_handlers.py b/tests/test_handlers.py
index aa73b3c1..878fd84a 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-2016 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)
+ 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)
- 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(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)
+ 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)
- 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')
+ 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)
- 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')
+
+ 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)
+ 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
@@ -699,12 +838,12 @@ From: aperson@dom.ain
eq(msg['list-help'], '<mailto:_xtest-request@dom.ain?subject=help>')
eq(msg['list-unsubscribe'],
'<http://www.dom.ain/mailman/options/_xtest>,'
- '\n\t<mailto:_xtest-request@dom.ain?subject=unsubscribe>')
+ '\n <mailto:_xtest-request@dom.ain?subject=unsubscribe>')
eq(msg['list-subscribe'],
'<http://www.dom.ain/mailman/listinfo/_xtest>,'
- '\n\t<mailto:_xtest-request@dom.ain?subject=subscribe>')
+ '\n <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
@@ -719,10 +858,10 @@ From: aperson@dom.ain
eq(msg['list-help'], '<mailto:_xtest-request@dom.ain?subject=help>')
eq(msg['list-unsubscribe'],
'<http://www.dom.ain/mailman/options/_xtest>,'
- '\n\t<mailto:_xtest-request@dom.ain?subject=unsubscribe>')
+ '\n <mailto:_xtest-request@dom.ain?subject=unsubscribe>')
eq(msg['list-subscribe'],
'<http://www.dom.ain/mailman/listinfo/_xtest>,'
- '\n\t<mailto:_xtest-request@dom.ain?subject=subscribe>')
+ '\n <mailto:_xtest-request@dom.ain?subject=subscribe>')
eq(msg['list-post'], '<mailto:_xtest@dom.ain>')
@@ -747,7 +886,8 @@ Here is a message.
self.assertEqual(msg.get_payload(), """\
header
Here is a message.
-footer""")
+footer
+""")
def test_no_multipart_template(self):
mlist = self._mlist
@@ -763,7 +903,8 @@ Here is a message.
self.assertEqual(msg.get_payload(), """\
XTest header
Here is a message.
-XTest footer""")
+XTest footer
+""")
def test_no_multipart_type_error(self):
mlist = self._mlist
@@ -779,7 +920,8 @@ Here is a message.
self.assertEqual(msg.get_payload(), """\
%(real_name) header
Here is a message.
-%(real_name) footer""")
+%(real_name) footer
+""")
def test_no_multipart_value_error(self):
mlist = self._mlist
@@ -796,7 +938,8 @@ Here is a message.
self.assertEqual(msg.get_payload(), """\
%(real_name)p header
Here is a message.
-%(real_name)p footer""")
+%(real_name)p footer
+""")
def test_no_multipart_missing_key(self):
mlist = self._mlist
@@ -811,7 +954,8 @@ Here is a message.
self.assertEqual(msg.get_payload(), """\
%(spooge)s header
Here is a message.
-%(spooge)s footer""")
+%(spooge)s footer
+""")
def test_multipart(self):
eq = self.ndiffAssertEqual
@@ -845,6 +989,7 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: inline
header
+
--BOUNDARY
From: aperson@dom.ain
@@ -862,7 +1007,9 @@ Content-Transfer-Encoding: 7bit
Content-Disposition: inline
footer
---BOUNDARY--""")
+
+--BOUNDARY--
+""")
def test_image(self):
eq = self.assertEqual
@@ -1221,7 +1368,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 +1778,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('', Message.Message)
+ rtn = SpamDetect.process(self._mlist, msg, msgdata)
# Not really a great test, but there's little else to assert
self.assertEqual(rtn, None)
@@ -1639,12 +1788,12 @@ class TestSpamDetect(TestBase):
From: aperson@dom.ain
A message.
-""")
+""", Message.Message)
msg2 = email.message_from_string("""\
To: xlist@dom.ain
A message.
-""")
+""", Message.Message)
spammers = mm_cfg.KNOWN_SPAMMERS[:]
try:
mm_cfg.KNOWN_SPAMMERS.append(('from', '.?person'))
@@ -1878,7 +2027,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