diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-09-10 12:42:44 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-09-10 17:18:21 +0200 |
commit | eb09754af5a606e14df10ef11c38ed1a9f0b7da9 (patch) | |
tree | 7347529dcc697c19c2a55929edb7ac72b8e23d3a | |
parent | 691097a961810da4e058b07f3186de1385fe3803 (diff) | |
download | kittystore-eb09754af5a606e14df10ef11c38ed1a9f0b7da9.tar.gz kittystore-eb09754af5a606e14df10ef11c38ed1a9f0b7da9.tar.xz kittystore-eb09754af5a606e14df10ef11c38ed1a9f0b7da9.zip |
Handle unparseable reference headers
-rw-r--r-- | kittystore/test/test_utils.py | 9 | ||||
-rw-r--r-- | kittystore/utils.py | 6 |
2 files changed, 14 insertions, 1 deletions
diff --git a/kittystore/test/test_utils.py b/kittystore/test/test_utils.py index 8fc0c8b..6b2eafa 100644 --- a/kittystore/test/test_utils.py +++ b/kittystore/test/test_utils.py @@ -19,6 +19,15 @@ class TestUtils(unittest.TestCase): msg, "example-list", store) self.assertEqual(ref_id, "200704070053.46646.other.person@example.com") + def test_wrong_reply_to_format(self): + with open(get_test_file("wrong-in-reply-to-header.txt")) as email_file: + msg = email.message_from_file(email_file) + store = Mock() + store.get_message_by_id_from_list.return_value = None + ref_id, thread_id = kittystore.utils.get_ref_and_thread_id( + msg, "example-list", store) + self.assertEqual(ref_id, None) + def test_non_ascii_payload(self): """utils.payload_to_unicode must handle non-ascii messages""" for enc in ["utf8", "iso8859"]: diff --git a/kittystore/utils.py b/kittystore/utils.py index 28a3e15..9ed0810 100644 --- a/kittystore/utils.py +++ b/kittystore/utils.py @@ -118,7 +118,11 @@ def get_ref_and_thread_id(message, list_name, store): ref_id = ref_id.split()[0].strip() else: ref_id = message.get("In-Reply-To") - ref_id = IN_BRACKETS_RE.match(ref_id).group(1) + ref_id = IN_BRACKETS_RE.match(ref_id) + if ref_id is None: + # Can't parse the reference + return None, None + ref_id = ref_id.group(1) # It's a reply, use the thread_id from the parent email ref_msg = store.get_message_by_id_from_list(list_name, ref_id) if ref_msg is None: |