diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-12-14 14:25:27 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-12-14 14:25:27 +0100 |
commit | 8ea86d9987a3142b6e83596d6a0d1df8f6d14af7 (patch) | |
tree | bc16e9e570b34e7e5f97d61bd4b15a30c3d1ec05 | |
parent | 876b6c36f289f7523f2d4d157e1e70a282c6bcf8 (diff) | |
download | kittystore-8ea86d9987a3142b6e83596d6a0d1df8f6d14af7.tar.gz kittystore-8ea86d9987a3142b6e83596d6a0d1df8f6d14af7.tar.xz kittystore-8ea86d9987a3142b6e83596d6a0d1df8f6d14af7.zip |
Change the reply detection system
- The In-Reply-To header has the priority
- The last message-id in the Reference header is used, not the first
one
-rw-r--r-- | kittystore/test/test_utils.py | 26 | ||||
-rw-r--r-- | kittystore/utils.py | 12 |
2 files changed, 31 insertions, 7 deletions
diff --git a/kittystore/test/test_utils.py b/kittystore/test/test_utils.py index 7662e81..8e78d5b 100644 --- a/kittystore/test/test_utils.py +++ b/kittystore/test/test_utils.py @@ -33,6 +33,30 @@ class TestUtils(unittest.TestCase): msg, "example-list", store)[0] self.assertEqual(ref_id, None) + def test_in_reply_to(self): + msg = Message() + msg["From"] = "dummy@example.com" + msg["Message-ID"] = "<dummy>" + msg["In-Reply-To"] = " <ref-1> " + msg.set_payload("Dummy message") + store = Mock() + ref_id = kittystore.utils.get_ref_and_thread_id( + msg, "example-list", store)[0] + self.assertEqual(ref_id, "ref-1") + + def test_in_reply_to_and_reference(self): + """The In-Reply-To header should win over References""" + msg = Message() + msg["From"] = "dummy@example.com" + msg["Message-ID"] = "<dummy>" + msg["In-Reply-To"] = " <ref-1> " + msg["References"] = " <ref-2> " + msg.set_payload("Dummy message") + store = Mock() + ref_id = kittystore.utils.get_ref_and_thread_id( + msg, "example-list", store)[0] + self.assertEqual(ref_id, "ref-1") + def test_single_reference(self): msg = Message() msg["From"] = "dummy@example.com" @@ -53,7 +77,7 @@ class TestUtils(unittest.TestCase): store = Mock() ref_id = kittystore.utils.get_ref_and_thread_id( msg, "example-list", store)[0] - self.assertEqual(ref_id, "ref-1") + self.assertEqual(ref_id, "ref-2") def test_empty_reference(self): msg = Message() diff --git a/kittystore/utils.py b/kittystore/utils.py index badf5af..d98537f 100644 --- a/kittystore/utils.py +++ b/kittystore/utils.py @@ -110,12 +110,12 @@ def get_ref_and_thread_id(message, list_name, store): and not message.has_key("In-Reply-To")): return None, None # It's a reply, use the thread_id from the parent email - ref_id = message.get("References") - if ref_id is not None and ref_id.strip(): - # There can be multiple references, use the first one - ref_id = ref_id.split()[0].strip() - else: - ref_id = message.get("In-Reply-To") + ref_id = message.get("In-Reply-To") + if ref_id is None or not ref_id.strip(): + ref_id = message.get("References") + if ref_id is not None and ref_id.strip(): + # There can be multiple references, use the last one + ref_id = ref_id.split()[-1].strip() if ref_id is not None: ref_id = IN_BRACKETS_RE.match(ref_id) if ref_id is None: |