email_mirror: Improve filter_footer delimiter detection

This commit is contained in:
Carlos Bederian 2021-03-12 00:27:19 -03:00 committed by Tim Abbott
parent 06c0a29e47
commit 1b51792459
2 changed files with 7 additions and 2 deletions

View File

@ -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:

View File

@ -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