Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

email_mirror: Drop missed-message emails which are autogenerated.

Alex Vandiver3538455ca88b
diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py
index e555edf9ca4..4dca3f67c89 100644
--- a/zerver/lib/email_mirror.py
+++ b/zerver/lib/email_mirror.py
@@ -467,6 +467,11 @@ def process_stream_message(to: str, message: EmailMessage) -> None:
def process_missed_message(to: str, message: EmailMessage) -> None:
+ auto_submitted = message.get("Auto-Submitted", "")
+ if auto_submitted in ("auto-replied", "auto-generated"):
+ logger.info("Dropping %s message from %s", auto_submitted, message.get("From"))
+ return
+
mm_address = get_usable_missed_message_address(to)
mm_address.increment_times_used()
diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py
index da0780d388c..df31c5a95be 100644
--- a/zerver/tests/test_email_mirror.py
+++ b/zerver/tests/test_email_mirror.py
@@ -1587,6 +1587,43 @@ class TestMissedMessageEmailMessages(ZulipTestCase):
for i in range(5):
process_missed_message(mm_address, incoming_valid_message)
+ def test_autoreply(self) -> None:
+ self.login("hamlet")
+ othello = self.example_user("othello")
+ result = self.client_post(
+ "/json/messages",
+ {
+ "type": "private",
+ "content": "test_receive_missed_message_email_messages",
+ "to": orjson.dumps([othello.id]).decode(),
+ },
+ )
+ self.assert_json_success(result)
+
+ usermessage = most_recent_usermessage(othello)
+
+ mm_address = create_missed_message_address(othello, usermessage.message)
+
+ incoming_autoreply = EmailMessage()
+ incoming_autoreply.set_content("An auto-reply")
+ incoming_autoreply["Subject"] = "TestMissedMessageEmailMessages subject"
+ incoming_autoreply["From"] = self.example_email("othello")
+ incoming_autoreply["To"] = mm_address
+ incoming_autoreply["Reply-to"] = self.example_email("othello")
+ incoming_autoreply["Auto-Submitted"] = "auto-replied"
+
+ hamlet = self.example_user("hamlet")
+ message = most_recent_message(hamlet)
+ with self.assert_database_query_count(0), self.assertLogs(logger_name, level="INFO") as m:
+ process_message(incoming_autoreply)
+ self.assertEqual(
+ m.output,
+ [f"INFO:{logger_name}:Dropping auto-replied message from [email protected]"],
+ )
+
+ # It should get dropped, so the most recent message is unchanged
+ self.assertEqual(message, most_recent_message(hamlet))
+
class TestEmptyGatewaySetting(ZulipTestCase):
def test_missed_message(self) -> None: