Exemplo n.º 1
0
 def test_no_from(self):
     msg = Message()
     msg.set_payload("Dummy message")
     try:
         name, email = kittystore.utils.parseaddr(msg["From"])
     except AttributeError, e:
         self.fail(e)
Exemplo n.º 2
0
 def test_on_new_message_userid(self):
     # Check that the user_id is set on a new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     # setup Mailman's reply
     new_user_id = FakeMMUser()
     uid = uuid.uuid1()
     new_user_id.user_id = uid.int
     self.mm_client.get_user.side_effect = lambda addr: new_user_id
     # check the User does not exist yet
     self.assertEqual(0,
             self.store.get_message_count_by_user_id(uid))
     # do the test and check
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list(
             "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, uid)
     self.assertTrue(dbmsg.sender.user is not None,
             "A 'User' instance was not created")
     self.assertEqual(dbmsg.sender.user.id, uid)
     self.assertEqual(1,
             self.store.get_message_count_by_user_id(uid))
     self.assertEqual(self.store.get_users_count(), 1)
Exemplo n.º 3
0
 def test_add_in_classical_thread(self):
     # msg1
     # |-msg2
     # | `-msg4
     # `-msg3
     ml = FakeList("example-list")
     msgs = []
     for num in range(1, 5):
         msg = Message()
         msg["From"] = "*****@*****.**" % num
         msg["Message-ID"] = "<msg%d>" % num
         msg.set_payload("message %d" % num)
         msgs.append(msg)
     msgs[1]["In-Reply-To"] = "<msg1>"
     msgs[2]["In-Reply-To"] = "<msg1>"
     msgs[3]["In-Reply-To"] = "<msg2>"
     for msg in msgs:
         self.store.add_to_list(ml, msg)
     msgs = []
     for num in range(1, 5):
         msg = self.store.get_message_by_id_from_list(
             "example-list", "msg%d" % num)
         msgs.append(msg)
     msg1, msg2, msg3, msg4 = msgs
     self.assertEqual(msg1.thread_order, 0)
     self.assertEqual(msg1.thread_depth, 0)
     self.assertEqual(msg2.thread_order, 1)
     self.assertEqual(msg2.thread_depth, 1)
     self.assertEqual(msg3.thread_order, 3)
     self.assertEqual(msg3.thread_depth, 1)
     self.assertEqual(msg4.thread_order, 2)
     self.assertEqual(msg4.thread_depth, 2)
Exemplo n.º 4
0
 def test_sync_mailman_user(self):
     # Check that the user_id is set when sync_mailman_user is run
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list(
             "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, None)
     # setup Mailman's reply
     uid = uuid.uuid1()
     new_user_id = FakeMMUser()
     new_user_id.user_id = uid.int
     self.mm_client.get_user.side_effect = lambda addr: new_user_id
     # do the test and check
     mailman_user.sync_mailman_user(self.store)
     #dbmsg = self.store.get_message_by_id_from_list(
     #        "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, uid)
     self.assertTrue(dbmsg.sender.user is not None,
             "A 'User' instance was not created")
     self.assertEqual(dbmsg.sender.user.id, uid)
     self.assertEqual(1,
             self.store.get_message_count_by_user_id(uid))
Exemplo n.º 5
0
 def setUp(self):
     self.user = User.objects.create_user('testuser', '*****@*****.**',
                                          'testPass')
     self.user.is_staff = True
     self.user.save()
     self.client.login(username='******', password='******')
     self.store = kittystore.get_store(SettingsModule(),
                                       debug=False,
                                       auto_create=True)
     self.client.defaults = {
         "kittystore.store": self.store,
         "HTTP_USER_AGENT": "testbot",
     }
     ml = FakeList("*****@*****.**")
     ml.subject_prefix = u"[example] "
     # Create 2 threads
     self.messages = []
     for msgnum in range(2):
         msg = Message()
         msg["From"] = "*****@*****.**"
         msg["Message-ID"] = "<id%d>" % (msgnum + 1)
         msg["Subject"] = "Dummy message"
         msg.set_payload("Dummy message")
         msg["Message-ID-Hash"] = self.store.add_to_list(ml, msg)
         self.messages.append(msg)
Exemplo n.º 6
0
 def test_properties_on_new_message(self):
     ml = FakeList("example-list")
     ml.display_name = u"name 1"
     ml.subject_prefix = u"[prefix 1]"
     ml.description = u"desc 1"
     kittystore.utils.MM_CLIENT.get_list.side_effect = lambda n: ml
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     ml_db = self.store.get_lists()[0]
     self.assertEqual(ml_db.display_name, "name 1")
     self.assertEqual(ml_db.subject_prefix, "[prefix 1]")
     ml.display_name = u"name 2"
     ml.subject_prefix = u"[prefix 2]"
     ml.description = u"desc 2"
     ml.archive_policy = "private"
     msg.replace_header("Message-ID", "<dummy2>")
     self.store.add_to_list("example-list", msg)
     ml_db = self.store.get_lists()[0]
     #ml_db = self.store.db.find(List).one()
     self.assertEqual(ml_db.display_name, "name 2")
     self.assertEqual(ml_db.subject_prefix, "[prefix 2]")
     self.assertEqual(ml_db.description, "desc 2")
     self.assertEqual(ml_db.archive_policy, ArchivePolicy.private)
 def test_list_complex_rule_deletion(self):
     # Test that the mailing-list header-match complex rules are read
     # properly after deletion.
     chain = config.chains['header-match']
     header_matches = IHeaderMatchList(self._mlist)
     header_matches.append('Foo', 'a+', 'reject')
     header_matches.append('Bar', 'b+', 'discard')
     header_matches.append('Baz', 'z+', 'accept')
     links = [
         link for link in chain.get_links(self._mlist, Message(), {})
         if link.rule.name != 'any'
     ]
     self.assertEqual(len(links), 3)
     self.assertEqual([
         (link.rule.header, link.rule.pattern, link.action, link.chain.name)
         for link in links
     ], [
         ('foo', 'a+', LinkAction.jump, 'reject'),
         ('bar', 'b+', LinkAction.jump, 'discard'),
         ('baz', 'z+', LinkAction.jump, 'accept'),
     ])  # noqa: E124
     del header_matches[0]
     links = [
         link for link in chain.get_links(self._mlist, Message(), {})
         if link.rule.name != 'any'
     ]
     self.assertEqual(len(links), 2)
     self.assertEqual([
         (link.rule.header, link.rule.pattern, link.action, link.chain.name)
         for link in links
     ], [
         ('bar', 'b+', LinkAction.jump, 'discard'),
         ('baz', 'z+', LinkAction.jump, 'accept'),
     ])  # noqa: E124
Exemplo n.º 8
0
 def _get_msg(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Message-ID-Hash"] = "QKODQBCADMDSP5YPOPKECXQWEQAMXZL3"
     msg.set_payload("Dummy message")
     return msg
Exemplo n.º 9
0
 def test_add_in_classical_thread(self):
     # msg1
     # |-msg2
     # | `-msg4
     # `-msg3
     ml = FakeList("example-list")
     msgs = []
     for num in range(1, 5):
         msg = Message()
         msg["From"] = "*****@*****.**" % num
         msg["Message-ID"] = "<msg%d>" % num
         msg.set_payload("message %d" % num)
         msgs.append(msg)
     msgs[1]["In-Reply-To"] = "<msg1>"
     msgs[2]["In-Reply-To"] = "<msg1>"
     msgs[3]["In-Reply-To"] = "<msg2>"
     for msg in msgs:
         self.store.add_to_list(ml, msg)
     msgs = []
     for num in range(1, 5):
         msg = self.store.get_message_by_id_from_list(
                 "example-list", "msg%d" % num)
         msgs.append(msg)
     msg1, msg2, msg3, msg4 = msgs
     self.assertEqual(msg1.thread_order, 0)
     self.assertEqual(msg1.thread_depth, 0)
     self.assertEqual(msg2.thread_order, 1)
     self.assertEqual(msg2.thread_depth, 1)
     self.assertEqual(msg3.thread_order, 3)
     self.assertEqual(msg3.thread_depth, 1)
     self.assertEqual(msg4.thread_order, 2)
     self.assertEqual(msg4.thread_depth, 2)
Exemplo n.º 10
0
 def _get_msg(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Message-ID-Hash"] = "QKODQBCADMDSP5YPOPKECXQWEQAMXZL3"
     msg.set_payload("Dummy message")
     return msg
Exemplo n.º 11
0
 def test_on_new_message_invalidate(self):
     # Check that the cache is invalidated on new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     today = datetime.datetime.utcnow().date() # don't use datetime.date.today(), we need UTC
     self.store.add_to_list("example-list", msg)
     # calls to cache.delete() -- invalidation
     delete_args = [ call[0][0] for call in
                     self.store.db.cache.delete.call_args_list ]
     #from pprint import pprint; pprint(delete_args)
     self.assertEqual(set(delete_args), set([
         u'list:example-list:recent_participants_count',
         u'list:example-list:recent_threads_count',
         u'list:example-list:participants_count:%d:%d' % (today.year, today.month),
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:emails_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:participants_count'
         ]))
     # calls to cache.get_or_create() -- repopulation
     goc_args = [ call[0][0] for call in
                  self.store.db.cache.get_or_create.call_args_list ]
     #from pprint import pprint; pprint(goc_args)
     self.assertEqual(set(goc_args), set([
         u'list:example-list:recent_participants_count',
         u'list:example-list:recent_threads_count',
         u'list:example-list:participants_count:%d:%d' % (today.year, today.month),
         u'list:example-list:threads_count:%d:%d' % (today.year, today.month),
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:emails_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:participants_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:starting_email_id',
         ]))
Exemplo n.º 12
0
 def test_on_new_message_userid(self):
     # Check that the user_id is set on a new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     # setup Mailman's reply
     new_user_id = FakeMMUser()
     uid = uuid.uuid1()
     new_user_id.user_id = uid.int
     self.mm_client.get_user.side_effect = lambda addr: new_user_id
     # check the User does not exist yet
     self.assertEqual(0,
             self.store.get_message_count_by_user_id(uid))
     # do the test and check
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list(
             "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, uid)
     self.assertTrue(dbmsg.sender.user is not None,
             "A 'User' instance was not created")
     self.assertEqual(dbmsg.sender.user.id, uid)
     self.assertEqual(1,
             self.store.get_message_count_by_user_id(uid))
     self.assertEqual(self.store.get_users_count(), 1)
Exemplo n.º 13
0
 def test_vote_cancel(self):
     ml = FakeList("*****@*****.**")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<msg1>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(ml, msg)
     msg.replace_header("Message-ID", "<msg2>")
     self.store.add_to_list(ml, msg)
     msg1 = self.store.get_message_by_id_from_list("*****@*****.**", "msg1")
     msg1.vote(1, u"testuser")
     msg2 = self.store.get_message_by_id_from_list("*****@*****.**", "msg2")
     msg2.vote(-1, u"testuser")
     self.assertEqual(msg1.likes, 1)
     self.assertEqual(msg2.dislikes, 1)
     for msg in (msg1, msg2):
         url = reverse('message_vote', args=("*****@*****.**",
                       msg.message_id_hash))
         resp = self.client.post(url, {"vote": "0"})
         self.assertEqual(resp.status_code, 200)
         self.assertEqual(msg.likes, 0)
         self.assertEqual(msg.dislikes, 0)
         result = json.loads(resp.content)
         self.assertEqual(result["like"], 0)
         self.assertEqual(result["dislike"], 0)
Exemplo n.º 14
0
 def test_sync_mailman_user(self):
     # Check that the user_id is set when sync_mailman_user is run
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list(
             "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, None)
     # setup Mailman's reply
     uid = uuid.uuid1()
     new_user_id = FakeMMUser()
     new_user_id.user_id = uid.int
     self.mm_client.get_user.side_effect = lambda addr: new_user_id
     # do the test and check
     mailman_user.sync_mailman_user(self.store)
     #dbmsg = self.store.get_message_by_id_from_list(
     #        "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, uid)
     self.assertTrue(dbmsg.sender.user is not None,
             "A 'User' instance was not created")
     self.assertEqual(dbmsg.sender.user.id, uid)
     self.assertEqual(1,
             self.store.get_message_count_by_user_id(uid))
Exemplo n.º 15
0
 def test_non_ascii_message(self):
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['To'] = '*****@*****.**'
     msg['Content-Type'] = 'multipart/mixed'
     msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
                         'plain', 'utf-8'))
     mbox = digest_mbox(self._mlist)
     mbox_path = os.path.join(self._mlist.data_path, 'digest.mmdf')
     mbox.add(msg.as_string())
     self._digestq.enqueue(
         msg,
         listname=self._mlist.fqdn_listname,
         digest_path=mbox_path,
         volume=1, digest_number=1)
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     self._runner.run()
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     # There are two messages in the virgin queue: the digest as plain-text
     # and as multipart.
     messages = get_queue_messages('virgin')
     self.assertEqual(len(messages), 2)
     self.assertEqual(
         sorted(item.msg.get_content_type() for item in messages),
         ['multipart/mixed', 'text/plain'])
     for item in messages:
         self.assertEqual(item.msg['subject'],
                          'Test Digest, Vol 1, Issue 1')
Exemplo n.º 16
0
 def test_on_new_message_invalidate(self):
     # Check that the cache is invalidated on new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     today = datetime.datetime.utcnow().date() # don't use datetime.date.today(), we need UTC
     self.store.add_to_list("example-list", msg)
     # calls to cache.delete() -- invalidation
     delete_args = [ call[0][0] for call in
                     self.store.db.cache.delete.call_args_list ]
     #from pprint import pprint; pprint(delete_args)
     self.assertEqual(set(delete_args), set([
         u'list:example-list:recent_participants_count',
         u'list:example-list:recent_threads_count',
         u'list:example-list:participants_count:%d:%d' % (today.year, today.month),
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:emails_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:participants_count'
         ]))
     # calls to cache.get_or_create() -- repopulation
     goc_args = [ call[0][0] for call in
                  self.store.db.cache.get_or_create.call_args_list ]
     #from pprint import pprint; pprint(goc_args)
     self.assertEqual(set(goc_args), set([
         u'list:example-list:recent_participants_count',
         u'list:example-list:recent_threads_count',
         u'list:example-list:participants_count:%d:%d' % (today.year, today.month),
         u'list:example-list:threads_count:%d:%d' % (today.year, today.month),
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:emails_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:participants_count',
         u'list:example-list:thread:QKODQBCADMDSP5YPOPKECXQWEQAMXZL3:starting_email_id',
         ]))
Exemplo n.º 17
0
 def test_multiple_reference(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["References"] = " <ref-1> <ref-2> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-2")
Exemplo n.º 18
0
 def test_in_reply_to(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["In-Reply-To"] = " <ref-1> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-1")
Exemplo n.º 19
0
 def test_multiple_reference(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["References"] = " <ref-1> <ref-2> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-2")
Exemplo n.º 20
0
 def test_in_reply_to(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["In-Reply-To"] = " <ref-1> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-1")
Exemplo n.º 21
0
 def setUp(self):
     # Create the list by adding a dummy message
     ml = FakeList("*****@*****.**")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<msg>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(ml, msg)
Exemplo n.º 22
0
 def _create_email(self, num, reply_to=None):
     ml = FakeList("example-list")
     msg = Message()
     msg["From"] = "*****@*****.**" % num
     msg["Message-ID"] = "<msg%d>" % num
     msg.set_payload("message %d" % num)
     if reply_to is not None:
         msg["In-Reply-To"] = "<msg%d>" % reply_to
     self.store.add_to_list(ml, msg)
 def test_on_new_message_no_reply_from_mailman(self):
     # Check that the user_id is set on a new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list("example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, None)
Exemplo n.º 24
0
 def test_get_sender_name(self):
     msg = Message()
     msg["From"] = "Sender Name <*****@*****.**>"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(FakeList("example-list"), msg)
     stored_msg = self.store.db.query(Email).one()
     user_id = stored_msg.sender.user_id
     self.assertEqual(self.store.get_sender_name(user_id), "Sender Name")
Exemplo n.º 25
0
 def test_empty_reference(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["References"] = " "
     msg.set_payload("Dummy message")
     try:
         ref_id = kittystore.utils.get_ref(msg)
     except IndexError, e:
         self.fail("Empty 'References' tag should be handled")
Exemplo n.º 26
0
 def test_date_aware(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Date"] = "Fri, 02 Nov 2012 16:07:54 +0100"
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except IntegrityError, e:
         self.fail(e)
Exemplo n.º 27
0
 def test_no_date(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     now = datetime.datetime.utcnow()
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except IntegrityError, e:
         self.fail(e)
Exemplo n.º 28
0
 def test_no_date(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     now = datetime.datetime.utcnow()
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except IntegrityError, e:
         self.fail(e)
Exemplo n.º 29
0
 def test_duplicate(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(FakeList("example-list"), msg)
     self.assertEqual(self.store.get_list_size("example-list"), 1)
     self.assertTrue(self.store.is_message_in_list("example-list", "dummy"))
     self.store.add_to_list(FakeList("example-list"), msg)
     self.assertEqual(self.store.get_list_size("example-list"), 1)
Exemplo n.º 30
0
 def test_in_reply_to_and_reference(self):
     """The In-Reply-To header should win over References"""
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["In-Reply-To"] = " <ref-1> "
     msg["References"] = " <ref-2> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-1")
Exemplo n.º 31
0
 def test_date_aware(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Date"] = "Fri, 02 Nov 2012 16:07:54 +0100"
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except IntegrityError, e:
         self.fail(e)
Exemplo n.º 32
0
 def test_non_ascii_email_address(self):
     """Non-ascii email addresses should raise a ValueError exception"""
     msg = Message()
     msg["From"] = b"dummy-non-ascii-\xc3\[email protected]"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except ValueError, e:
         self.assertEqual(e.__class__.__name__, "ValueError")
Exemplo n.º 33
0
 def test_empty_reference(self):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["References"] = " "
     msg.set_payload("Dummy message")
     try:
         kittystore.utils.get_ref(msg)
     except IndexError:
         self.fail("Empty 'References' tag should be handled")
Exemplo n.º 34
0
 def _make_msg(self, msgid, reply_to=None):
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<%s>" % msgid
     msg["Subject"] = "Dummy message"
     msg.set_payload("Dummy message")
     if reply_to is not None:
         msg["In-Reply-To"] = "<%s>" % reply_to
     msg["Message-ID-Hash"] = self.store.add_to_list(self.ml, msg)
     return msg
Exemplo n.º 35
0
 def test_on_new_message_no_reply_from_mailman(self):
     # Check that the user_id is set on a new message
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     dbmsg = self.store.get_message_by_id_from_list(
             "example-list", "dummy")
     self.assertEqual(dbmsg.sender.user_id, None)
Exemplo n.º 36
0
 def test_in_reply_to_and_reference(self):
     """The In-Reply-To header should win over References"""
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["In-Reply-To"] = " <ref-1> "
     msg["References"] = " <ref-2> "
     msg.set_payload("Dummy message")
     ref_id = kittystore.utils.get_ref(msg)
     self.assertEqual(ref_id, "ref-1")
Exemplo n.º 37
0
 def test_on_new_message_bad_reply_from_mailman(self):
     # Check that errors from mailmanclient are handled gracefully
     self.mm_client.get_user.side_effect = ValueError
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list("example-list", msg)
     except ValueError, e:
         self.fail("Errors from mailmanclient should be handled gracefully")
Exemplo n.º 38
0
 def test_subject(self):
     ml = FakeList("example-list")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummymsg>"
     msg["Date"] = "Fri, 02 Nov 2012 16:07:54 +0000"
     msg["Subject"] = "Dummy subject"
     msg.set_payload("Dummy message")
     self.store.add_to_list(ml, msg)
     thread = self.store.db.query(Thread).one()
     self.assertEqual(thread.subject, "Dummy subject")
Exemplo n.º 39
0
 def test_on_new_message_bad_reply_from_mailman(self):
     # Check that errors from mailmanclient are handled gracefully
     self.mm_client.get_user.side_effect = ValueError
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list("example-list", msg)
     except ValueError, e:
         self.fail("Errors from mailmanclient should be handled gracefully")
Exemplo n.º 40
0
 def test_subject(self):
     ml = FakeList("example-list")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummymsg>"
     msg["Date"] = "Fri, 02 Nov 2012 16:07:54 +0000"
     msg["Subject"] = "Dummy subject"
     msg.set_payload("Dummy message")
     self.store.add_to_list(ml, msg)
     thread = self.store.db.find(Thread).one()
     self.assertEqual(thread.subject, "Dummy subject")
Exemplo n.º 41
0
 def test_private_list(self):
     # emails on private lists must not be found by a search on all lists
     ml = FakeList("example-list")
     ml.archive_policy = ArchivePolicy.private
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(ml, msg)
     result = self.store.search("dummy")
     self.assertEqual(result["total"], 0)
 def test_on_old_message(self):
     kittystore.utils.MM_CLIENT = None
     olddate = datetime.datetime.utcnow() - datetime.timedelta(days=40)
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Date"] = olddate.isoformat()
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     ml_db = self.store.get_lists()[0]
     self.assertEqual(ml_db.recent_participants_count, 0)
     self.assertEqual(ml_db.recent_threads_count, 0)
Exemplo n.º 43
0
 def test_on_old_message(self):
     kittystore.utils.MM_CLIENT = None
     olddate = datetime.datetime.utcnow() - datetime.timedelta(days=40)
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg["Date"] = olddate.isoformat()
     msg.set_payload("Dummy message")
     self.store.add_to_list("example-list", msg)
     ml_db = self.store.get_lists()[0]
     self.assertEqual(ml_db.recent_participants_count, 0)
     self.assertEqual(ml_db.recent_threads_count, 0)
Exemplo n.º 44
0
 def test_long_message_id(self):
     # Some message-ids are more than 255 chars long
     # Check with assert here because SQLite will not enforce the limit
     # (http://www.sqlite.org/faq.html#q9)
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "X" * 260
     msg.set_payload("Dummy message")
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except IntegrityError, e:
         self.fail(e)
Exemplo n.º 45
0
    def add_fetch_data(self):
        msg = Message()
        msg["From"] = "*****@*****.**"
        msg["Subject"] = "Fake Subject"
        msg["Message-ID"] = "<dummy>"
        msg["Date"] = "Fri, 02 Nov 2012 16:07:54"
        msg.set_payload("Fake Message")

        ml = FakeList("example-list")
        ml.display_name = u"name 1"
        ml.subject_prefix = u"[prefix 1]"

        return ml.fqdn_listname, self.store.add_to_list(ml, msg)
Exemplo n.º 46
0
    def add_fetch_data(self):
        msg = Message()
        msg["From"] = "*****@*****.**"
        msg["Subject"] = "Fake Subject"
        msg["Message-ID"] = "<dummy>"
        msg["Date"] = "Fri, 02 Nov 2012 16:07:54"
        msg.set_payload("Fake Message")

        ml = FakeList("example-list")
        ml.display_name = u"name 1"
        ml.subject_prefix = u"[prefix 1]"

        return ml.fqdn_listname, self.store.add_to_list(ml, msg)
Exemplo n.º 47
0
 def test_duplicate_nonascii(self):
     msg = Message()
     msg["From"] = b"*****@*****.**"
     msg["Message-ID"] = "<dummy>"
     msg.set_payload("Dummy message")
     self.store.add_to_list(FakeList("example-list"), msg)
     self.assertEqual(self.store.get_list_size("example-list"), 1)
     self.assertTrue(self.store.is_message_in_list("example-list", "dummy"))
     msg.replace_header("From", b"dummy-non-ascii\xc3\[email protected]")
     try:
         self.store.add_to_list(FakeList("example-list"), msg)
     except UnicodeDecodeError, e:
         self.fail("Died on a non-ascii header message: %s" % unicode(e))
Exemplo n.º 48
0
 def setUp(self):
     store = kittystore.get_store(SettingsModule(),
                                  debug=False, auto_create=True)
     self.client.defaults = {"kittystore.store": store,
                             "HTTP_USER_AGENT": "testbot",
                             }
     # Create the list by adding a dummy message
     ml = FakeList("*****@*****.**")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<msg>"
     msg.set_payload("Dummy message")
     store.add_to_list(ml, msg)
Exemplo n.º 49
0
 def setUp(self):
     self.user = User.objects.create_user('testuser', '*****@*****.**',
                                          'testPass')
     self.client.login(username='******', password='******')
     store = kittystore.get_store(SettingsModule(), debug=False)
     ml = FakeList("*****@*****.**")
     ml.subject_prefix = u"[example] "
     # Create 3 threads
     messages = []
     for msgnum in range(3):
         msg = Message()
         msg["From"] = "*****@*****.**"
         msg["Message-ID"] = "<id%d>" % (msgnum + 1)
         msg["Subject"] = "Dummy message"
         msg.set_payload("Dummy message")
         store.add_to_list(ml, msg)
         messages.append(msg)
     # 1st is unread, 2nd is read, 3rd is updated
     LastView.objects.create(list_address="*****@*****.**",
                             user=self.user,
                             threadid=get_message_id_hash("<id2>"))
     LastView.objects.create(list_address="*****@*****.**",
                             user=self.user,
                             threadid=get_message_id_hash("<id3>"))
     msg4 = Message()
     msg4["From"] = "*****@*****.**"
     msg4["Message-ID"] = "<id4>"
     msg4["Subject"] = "Dummy message"
     msg4["In-Reply-To"] = "<id3>"
     msg4.set_payload("Dummy message")
     store.add_to_list(ml, msg4)
     # Factory
     defaults = {"kittystore.store": store, "HTTP_USER_AGENT": "testbot"}
     self.factory = RequestFactory(**defaults)
Exemplo n.º 50
0
 def setUp(self):
     store = kittystore.get_store(SettingsModule(),
                                  debug=False,
                                  auto_create=True)
     self.client.defaults = {
         "kittystore.store": store,
         "HTTP_USER_AGENT": "testbot",
     }
     # Create the list by adding a dummy message
     ml = FakeList("*****@*****.**")
     msg = Message()
     msg["From"] = "*****@*****.**"
     msg["Message-ID"] = "<msg>"
     msg.set_payload("Dummy message")
     store.add_to_list(ml, msg)
Exemplo n.º 51
0
 def test_non_ascii_message(self):
     msg = Message()
     msg['From'] = '*****@*****.**'
     msg['To'] = '*****@*****.**'
     msg['Content-Type'] = 'multipart/mixed'
     msg.attach(MIMEText('message with non-ascii chars: \xc3\xa9',
                         'plain', 'utf-8'))
     mbox = digest_mbox(self._mlist)
     mbox.add(msg.as_string())
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
Exemplo n.º 52
0
 def test_prefix_only_mixed(self):
     # Incoming subject is only the prefix.
     msg = Message()
     msg['Subject'] = '=?utf-8?Q?[Test]_?='
     self._process(self._mlist, msg, {})
     subject = msg['subject']
     self.assertEqual(str(subject), '[Test] ')
Exemplo n.º 53
0
 def test_bad_configuration_line(self):
     # Take a mark on the error log file.
     mark = LogFileMark('mailman.error')
     # A bad value in [antispam]header_checks should just get ignored, but
     # with an error message logged.
     chain = config.chains['header-match']
     # The links are created dynamically; the rule names will all start
     # with the same prefix, but have a variable suffix.  The actions will
     # all be to jump to the named chain.  Do these checks now, while we
     # collect other useful information.
     post_checks = []
     saw_any_rule = False
     for link in chain.get_links(self._mlist, Message(), {}):
         if link.rule.name == 'any':
             saw_any_rule = True
             self.assertEqual(link.action, LinkAction.jump)
         elif saw_any_rule:
             raise AssertionError("'any' rule was not last")
         else:
             self.assertEqual(link.rule.name[:13], 'header-match-')
             self.assertEqual(link.action, LinkAction.defer)
             post_checks.append((link.rule.header, link.rule.pattern))
     self.assertListEqual(post_checks, [
         ('Foo', 'foo'),
         ('Bar', 'bar'),
         ])
     # Check the error log.
     self.assertEqual(mark.readline()[-77:-1],
                      'Configuration error: [antispam]header_checks '
                      'contains bogus line: A-bad-line')
Exemplo n.º 54
0
 def test_isdigest(self):
     # If the message is destined for the digest, the Subject header does
     # not get touched.
     msg = Message()
     msg['Subject'] = 'A test message'
     self._process(self._mlist, msg, dict(isdigest=True))
     self.assertEqual(str(msg['subject']), 'A test message')
Exemplo n.º 55
0
 def test_fasttrack(self):
     # Messages internally crafted are 'fast tracked' and don't get their
     # Subjects prefixed either.
     msg = Message()
     msg['Subject'] = 'A test message'
     self._process(self._mlist, msg, dict(_fasttrack=True))
     self.assertEqual(str(msg['subject']), 'A test message')
Exemplo n.º 56
0
 def test_whitespace_only_prefix(self):
     # If the Subject prefix only contains whitespace, ignore it.
     self._mlist.subject_prefix = '    '
     msg = Message()
     msg['Subject'] = 'A test message'
     self._process(self._mlist, msg, {})
     self.assertEqual(str(msg['subject']), 'A test message')
Exemplo n.º 57
0
 def test_prefix(self):
     # The Subject gets prefixed.  The prefix gets automatically set by the
     # list style when the list gets created.
     msg = Message()
     msg['Subject'] = 'A test message'
     self._process(self._mlist, msg, {})
     self.assertEqual(str(msg['subject']), '[Test] A test message')
Exemplo n.º 58
0
 def test_re_prefix(self):
     # The subject has a Re: prefix.  Make sure that gets preserved, but
     # after the list prefix.
     msg = Message()
     msg['Subject'] = 'Re: [Test] A test message'
     self._process(self._mlist, msg, {})
     self.assertEqual(str(msg['subject']), '[Test] Re: A test message')
 def test_join_bad_argument_no_equal(self):
     # Try to subscribe a member with a bad argument via join.
     msg = Message()
     msg['From'] = '*****@*****.**'
     results = Results()
     self._command.process(self._mlist, msg, {}, ('digest', ), results)
     self.assertIn('bad argument: digest', str(results))
Exemplo n.º 60
0
 def test_re_only_mixed(self):
     # Incoming subject is only Re:.
     msg = Message()
     msg['Subject'] = '=?utf-8?Q?Re:?='
     self._process(self._mlist, msg, {})
     subject = msg['subject']
     self.assertEqual(str(subject), '[Test] Re: ')