mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 19:43:47 +00:00 
			
		
		
		
	email_mirror: Fix handling of empty topic.
Also fixs some corner cases around pure-whitespace topics, and migrates from the years-obsolete "no subject". Fixes #9207.
This commit is contained in:
		| @@ -314,7 +314,9 @@ def process_missed_message(to: Text, message: message.Message, pre_checked: bool | ||||
|     send_to_missed_message_address(to, message) | ||||
|  | ||||
| def process_message(message: message.Message, rcpt_to: Optional[Text]=None, pre_checked: bool=False) -> None: | ||||
|     subject_header = message.get("Subject", "(no subject)") | ||||
|     subject_header = str(message.get("Subject", "")).strip() | ||||
|     if subject_header == "": | ||||
|         subject_header = "(no topic)" | ||||
|     encoded_subject, encoding = decode_header(subject_header)[0] | ||||
|     if encoding is None: | ||||
|         subject = force_text(encoded_subject)  # encoded_subject has type str when encoding is None | ||||
|   | ||||
| @@ -101,6 +101,30 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase): | ||||
|         self.assertEqual(get_display_recipient(message.recipient), stream.name) | ||||
|         self.assertEqual(message.topic_name(), incoming_valid_message['Subject']) | ||||
|  | ||||
|     def test_receive_stream_email_messages_blank_subject_success(self) -> None: | ||||
|         user_profile = self.example_user('hamlet') | ||||
|         self.login(user_profile.email) | ||||
|         self.subscribe(user_profile, "Denmark") | ||||
|         stream = get_stream("Denmark", user_profile.realm) | ||||
|  | ||||
|         stream_to_address = encode_email_address(stream) | ||||
|  | ||||
|         incoming_valid_message = MIMEText('TestStreamEmailMessages Body')  # type: Any # https://github.com/python/typeshed/issues/275 | ||||
|  | ||||
|         incoming_valid_message['Subject'] = '' | ||||
|         incoming_valid_message['From'] = self.example_email('hamlet') | ||||
|         incoming_valid_message['To'] = stream_to_address | ||||
|         incoming_valid_message['Reply-to'] = self.example_email('othello') | ||||
|  | ||||
|         process_message(incoming_valid_message) | ||||
|  | ||||
|         # Hamlet is subscribed to this stream so should see the email message from Othello. | ||||
|         message = most_recent_message(user_profile) | ||||
|  | ||||
|         self.assertEqual(message.content, "TestStreamEmailMessages Body") | ||||
|         self.assertEqual(get_display_recipient(message.recipient), stream.name) | ||||
|         self.assertEqual(message.topic_name(), "(no topic)") | ||||
|  | ||||
| class TestStreamEmailMessagesEmptyBody(ZulipTestCase): | ||||
|     def test_receive_stream_email_messages_empty_body(self) -> None: | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user