diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index bc51a69559..c387fc94b8 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -322,7 +322,7 @@ def filter_footer(text: str) -> str: # isn't a trivial footer structure. return text - return text.partition("--")[0].strip() + return re.split(r"^\s*--\s*$", text, 1, flags=re.MULTILINE)[0].strip() def extract_and_upload_attachments(message: EmailMessage, realm: Realm) -> str: diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index 3b10691285..a91d213825 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -211,10 +211,15 @@ class TestGetMissedMessageToken(ZulipTestCase): class TestFilterFooter(ZulipTestCase): def test_filter_footer(self) -> None: text = """Test message + --Not a delimiter-- + More message -- Footer""" + expected_output = """Test message + --Not a delimiter-- + More message""" result = filter_footer(text) - self.assertEqual(result, "Test message") + self.assertEqual(result, expected_output) def test_filter_footer_many_parts(self) -> None: text = """Test message