Example #1
0
 def test_rewrite_headers(self):
     # Some NNTP servers are very strict about duplicate headers.  What we
     # can do is look at some headers and if they is more than one of that
     # header in the message, all the headers are deleted except the first
     # one, and then the other values are moved to the destination header.
     #
     # In this example, we'll create multiple To headers, which will all
     # get moved to X-Original-To.  However, because there will only be one
     # X-Fake header, it doesn't get rewritten.
     self._msg['To'] = '*****@*****.**'
     self._msg['To'] = '*****@*****.**'
     self._msg['X-Fake'] = 'ignore me'
     self.assertEqual(len(self._msg.get_all('to')), 3)
     self.assertEqual(len(self._msg.get_all('x-fake')), 1)
     nntp.prepare_message(self._mlist, self._msg, {})
     tos = self._msg.get_all('to')
     self.assertEqual(len(tos), 1)
     self.assertEqual(tos[0], '*****@*****.**')
     original_tos = self._msg.get_all('x-original-to')
     self.assertEqual(len(original_tos), 2)
     self.assertEqual(original_tos,
                      ['*****@*****.**', '*****@*****.**'])
     fakes = self._msg.get_all('x-fake')
     self.assertEqual(len(fakes), 1)
     self.assertEqual(fakes[0], 'ignore me')
     self.assertEqual(self._msg.get_all('x-original-fake'), None)
Example #2
0
 def test_rewrite_headers(self):
     # Some NNTP servers are very strict about duplicate headers.  What we
     # can do is look at some headers and if they is more than one of that
     # header in the message, all the headers are deleted except the first
     # one, and then the other values are moved to the destination header.
     #
     # In this example, we'll create multiple To headers, which will all
     # get moved to X-Original-To.  However, because there will only be one
     # X-Fake header, it doesn't get rewritten.
     self._msg['To'] = '*****@*****.**'
     self._msg['To'] = '*****@*****.**'
     self._msg['X-Fake'] = 'ignore me'
     self.assertEqual(len(self._msg.get_all('to')), 3)
     self.assertEqual(len(self._msg.get_all('x-fake')), 1)
     nntp.prepare_message(self._mlist, self._msg, {})
     tos = self._msg.get_all('to')
     self.assertEqual(len(tos), 1)
     self.assertEqual(tos[0], '*****@*****.**')
     original_tos = self._msg.get_all('x-original-to')
     self.assertEqual(len(original_tos), 2)
     self.assertEqual(original_tos,
                      ['*****@*****.**', '*****@*****.**'])
     fakes = self._msg.get_all('x-fake')
     self.assertEqual(len(fakes), 1)
     self.assertEqual(fakes[0], 'ignore me')
     self.assertEqual(self._msg.get_all('x-original-fake'), None)
Example #3
0
 def test_open_moderation_removes_previous_approved_header(self):
     # Any existing Approved header is removed from moderated messages.
     self._msg['Approved'] = 'a bogus approval'
     self._mlist.newsgroup_moderation = NewsgroupModeration.open_moderated
     nntp.prepare_message(self._mlist, self._msg, {})
     headers = self._msg.get_all('approved')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], '*****@*****.**')
Example #4
0
 def test_moderated_approved_header(self):
     # When the mailing list is moderated , the message will get an
     # Approved header, which NNTP software uses to forward to the
     # newsgroup.  The message would not have gotten to the mailing list if
     # it wasn't already approved.
     self._mlist.news_moderation = NewsModeration.moderated
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['approved'], '*****@*****.**')
Example #5
0
 def test_open_moderation_removes_previous_approved_header(self):
     # Any existing Approved header is removed from moderated messages.
     self._msg['Approved'] = 'a bogus approval'
     self._mlist.newsgroup_moderation = NewsgroupModeration.open_moderated
     nntp.prepare_message(self._mlist, self._msg, {})
     headers = self._msg.get_all('approved')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], '*****@*****.**')
Example #6
0
 def test_open_moderated_approved_header(self):
     # When the mailing list is moderated using an open posting policy, the
     # message will get an Approved header, which NNTP software uses to
     # forward to the newsgroup.  The message would not have gotten to the
     # mailing list if it wasn't already approved.
     self._mlist.newsgroup_moderation = NewsgroupModeration.open_moderated
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['approved'], '*****@*****.**')
Example #7
0
 def test_open_moderated_approved_header(self):
     # When the mailing list is moderated using an open posting policy, the
     # message will get an Approved header, which NNTP software uses to
     # forward to the newsgroup.  The message would not have gotten to the
     # mailing list if it wasn't already approved.
     self._mlist.newsgroup_moderation = NewsgroupModeration.open_moderated
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['approved'], '*****@*****.**')
Example #8
0
 def test_add_newsgroups_header_to_existing(self):
     # If the message already has a Newsgroups header, the linked newsgroup
     # gets appended to that value, using comma-space separated lists.
     self._msg['Newsgroups'] = 'foo.test, bar.test'
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     headers = self._msg.get_all('newsgroups')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], 'foo.test, bar.test, example.test')
Example #9
0
 def test_add_newsgroups_header_to_existing(self):
     # If the message already has a Newsgroups header, the linked newsgroup
     # gets appended to that value, using comma-space separated lists.
     self._msg['Newsgroups'] = 'foo.test, bar.test'
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     headers = self._msg.get_all('newsgroups')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], 'foo.test, bar.test, example.test')
Example #10
0
 def test_odd_duplicates(self):
     # This is just a corner case, where there is an odd number of rewrite
     # headers.  In that case, the odd-one-out does not get rewritten.
     self._msg['x-fake'] = 'one'
     self._msg['x-fake'] = 'two'
     self._msg['x-fake'] = 'three'
     self.assertEqual(len(self._msg.get_all('x-fake')), 3)
     nntp.prepare_message(self._mlist, self._msg, {})
     fakes = self._msg.get_all('x-fake')
     self.assertEqual(len(fakes), 3)
     self.assertEqual(fakes, ['one', 'two', 'three'])
Example #11
0
 def test_odd_duplicates(self):
     # This is just a corner case, where there is an odd number of rewrite
     # headers.  In that case, the odd-one-out does not get rewritten.
     self._msg['x-fake'] = 'one'
     self._msg['x-fake'] = 'two'
     self._msg['x-fake'] = 'three'
     self.assertEqual(len(self._msg.get_all('x-fake')), 3)
     nntp.prepare_message(self._mlist, self._msg, {})
     fakes = self._msg.get_all('x-fake')
     self.assertEqual(len(fakes), 3)
     self.assertEqual(fakes, ['one', 'two', 'three'])
Example #12
0
 def test_original_subject_prefix_okay(self):
     # The cook-headers handler adds the original and/or stripped (of the
     # prefix) subject to the metadata.  Assume that handler's been run;
     # check the Subject header.
     self._mlist.nntp_prefix_subject_too = True
     del self._msg['subject']
     self._msg['subject'] = 'Re: Your test'
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     headers = self._msg.get_all('subject')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], 'Re: Your test')
Example #13
0
 def test_original_subject(self):
     # The cook-headers handler adds the original and/or stripped (of the
     # prefix) subject to the metadata.  Assume that handler's been run;
     # check the Subject header.
     self._mlist.nntp_prefix_subject_too = False
     del self._msg['subject']
     self._msg['subject'] = 'Re: Your test'
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     headers = self._msg.get_all('subject')
     self.assertEqual(len(headers), 1)
     self.assertEqual(headers[0], 'Your test')
Example #14
0
 def test_remove_headers(self):
     # During preparation, headers which cause problems with certain NNTP
     # servers such as INN get removed.
     self._msg['X-Complaints-To'] = '*****@*****.**'
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['x-complaints-to'], None)
Example #15
0
 def test_the_message_has_been_prepared(self):
     # A key gets added to the metadata so that a retry won't try to
     # re-apply all the preparations.
     msgdata = {}
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     self.assertTrue(msgdata.get('prepped'))
Example #16
0
 def test_add_lines_header(self):
     # A Lines: header seems useful.
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['lines'], '1')
Example #17
0
 def test_remove_headers(self):
     # During preparation, headers which cause problems with certain NNTP
     # servers such as INN get removed.
     self._msg['X-Complaints-To'] = '*****@*****.**'
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['x-complaints-to'], None)
Example #18
0
 def test_add_newsgroups_header(self):
     # Prepared messages get a Newsgroups header.
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     self.assertEqual(self._msg['newsgroups'], 'example.test')
Example #19
0
 def test_add_lines_header(self):
     # A Lines: header seems useful.
     nntp.prepare_message(self._mlist, self._msg, {})
     self.assertEqual(self._msg['lines'], '1')
Example #20
0
 def test_add_newsgroups_header(self):
     # Prepared messages get a Newsgroups header.
     msgdata = dict(original_subject='Your test')
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     self.assertEqual(self._msg['newsgroups'], 'example.test')
Example #21
0
 def test_the_message_has_been_prepared(self):
     # A key gets added to the metadata so that a retry won't try to
     # re-apply all the preparations.
     msgdata = {}
     nntp.prepare_message(self._mlist, self._msg, msgdata)
     self.assertTrue(msgdata.get('prepped'))