mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 01:47:41 +00:00
email_mirror: Rename include-quotations to include-quotes.
This commit is contained in:
committed by
Tim Abbott
parent
519ed41803
commit
f1b135bd16
@@ -153,8 +153,8 @@ def mark_missed_message_address_as_used(address: str) -> None:
|
||||
raise ZulipEmailForwardError('Missed message address has already been used')
|
||||
|
||||
def construct_zulip_body(message: message.Message, realm: Realm, show_sender: bool=False,
|
||||
include_quotations: bool=False, include_footer: bool=False) -> str:
|
||||
body = extract_body(message, include_quotations)
|
||||
include_quotes: bool=False, include_footer: bool=False) -> str:
|
||||
body = extract_body(message, include_quotes)
|
||||
# Remove null characters, since Zulip will reject
|
||||
body = body.replace("\x00", "")
|
||||
if not include_footer:
|
||||
@@ -243,7 +243,7 @@ def get_message_part_by_type(message: message.Message, content_type: str) -> Opt
|
||||
return None
|
||||
|
||||
talon_initialized = False
|
||||
def extract_body(message: message.Message, include_quotations: bool=False) -> str:
|
||||
def extract_body(message: message.Message, include_quotes: bool=False) -> str:
|
||||
import talon
|
||||
global talon_initialized
|
||||
if not talon_initialized:
|
||||
@@ -254,7 +254,7 @@ def extract_body(message: message.Message, include_quotations: bool=False) -> st
|
||||
# that.
|
||||
plaintext_content = get_message_part_by_type(message, "text/plain")
|
||||
if plaintext_content:
|
||||
if include_quotations:
|
||||
if include_quotes:
|
||||
return plaintext_content
|
||||
else:
|
||||
return talon.quotations.extract_from_plain(plaintext_content)
|
||||
@@ -262,7 +262,7 @@ def extract_body(message: message.Message, include_quotations: bool=False) -> st
|
||||
# If we only have an HTML version, try to make that look nice.
|
||||
html_content = get_message_part_by_type(message, "text/html")
|
||||
if html_content:
|
||||
if include_quotations:
|
||||
if include_quotes:
|
||||
return convert_html_to_markdown(html_content)
|
||||
else:
|
||||
return convert_html_to_markdown(talon.quotations.extract_from_html(html_content))
|
||||
@@ -359,8 +359,8 @@ def process_stream_message(to: str, message: message.Message) -> None:
|
||||
|
||||
stream, options = extract_and_validate(to)
|
||||
# Don't remove quotations if message is forwarded, unless otherwise specified:
|
||||
if 'include_quotations' not in options:
|
||||
options['include_quotations'] = is_forwarded(subject_header)
|
||||
if 'include_quotes' not in options:
|
||||
options['include_quotes'] = is_forwarded(subject_header)
|
||||
|
||||
body = construct_zulip_body(message, stream.realm, **options)
|
||||
send_zulip(settings.EMAIL_GATEWAY_BOT, stream, subject, body)
|
||||
|
||||
@@ -7,7 +7,7 @@ from zerver.models import Stream
|
||||
|
||||
from typing import Dict, Tuple
|
||||
|
||||
optional_address_tokens = ["show-sender", "include-footer", "include-quotations"]
|
||||
optional_address_tokens = ["show-sender", "include-footer", "include-quotes"]
|
||||
|
||||
class ZulipEmailForwardError(Exception):
|
||||
pass
|
||||
|
||||
@@ -59,10 +59,10 @@ from typing import Any, Callable, Dict, Mapping, Union, Optional
|
||||
|
||||
class TestEncodeDecode(ZulipTestCase):
|
||||
def _assert_options(self, options: Dict[str, bool], show_sender: bool=False,
|
||||
include_footer: bool=False, include_quotations: bool=False) -> None:
|
||||
include_footer: bool=False, include_quotes: bool=False) -> None:
|
||||
self.assertEqual(show_sender, ('show_sender' in options) and options['show_sender'])
|
||||
self.assertEqual(include_footer, ('include_footer' in options) and options['include_footer'])
|
||||
self.assertEqual(include_quotations, ('include_quotations' in options) and options['include_quotations'])
|
||||
self.assertEqual(include_quotes, ('include_quotes' in options) and options['include_quotes'])
|
||||
|
||||
def test_encode_decode(self) -> None:
|
||||
realm = get_realm('zulip')
|
||||
@@ -77,10 +77,10 @@ class TestEncodeDecode(ZulipTestCase):
|
||||
|
||||
parts = email_address.split('@')
|
||||
# Use a mix of + and . as separators, to test that it works:
|
||||
parts[0] += "+include-footer.show-sender+include-quotations"
|
||||
parts[0] += "+include-footer.show-sender+include-quotes"
|
||||
email_address_all_options = '@'.join(parts)
|
||||
token, options = decode_email_address(email_address_all_options)
|
||||
self._assert_options(options, show_sender=True, include_footer=True, include_quotations=True)
|
||||
self._assert_options(options, show_sender=True, include_footer=True, include_quotes=True)
|
||||
self.assertEqual(token, stream.email_token)
|
||||
|
||||
email_address = email_address.replace('@testserver', '@zulip.org')
|
||||
@@ -97,7 +97,7 @@ class TestEncodeDecode(ZulipTestCase):
|
||||
self.assertEqual(token, stream.email_token)
|
||||
|
||||
token, options = decode_email_address(email_address_all_options)
|
||||
self._assert_options(options, show_sender=True, include_footer=True, include_quotations=True)
|
||||
self._assert_options(options, show_sender=True, include_footer=True, include_quotes=True)
|
||||
self.assertEqual(token, stream.email_token)
|
||||
|
||||
with self.assertRaises(ZulipEmailForwardError):
|
||||
@@ -335,7 +335,7 @@ 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_include_quotations_success(self) -> None:
|
||||
def test_receive_stream_email_include_quotes_success(self) -> None:
|
||||
user_profile = self.example_user('hamlet')
|
||||
self.login(user_profile.email)
|
||||
self.subscribe(user_profile, "Denmark")
|
||||
@@ -343,7 +343,7 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
|
||||
|
||||
stream_to_address = encode_email_address(stream)
|
||||
parts = stream_to_address.split('@')
|
||||
parts[0] += "+include-quotations"
|
||||
parts[0] += "+include-quotes"
|
||||
stream_to_address = '@'.join(parts)
|
||||
|
||||
text = """Reply
|
||||
|
||||
Reference in New Issue
Block a user