email_mirror: Rename include-quotations to include-quotes.

This commit is contained in:
Mateusz Mandera
2019-07-14 03:51:53 +02:00
committed by Tim Abbott
parent 519ed41803
commit f1b135bd16
3 changed files with 15 additions and 15 deletions

View File

@@ -153,8 +153,8 @@ def mark_missed_message_address_as_used(address: str) -> None:
raise ZulipEmailForwardError('Missed message address has already been used') raise ZulipEmailForwardError('Missed message address has already been used')
def construct_zulip_body(message: message.Message, realm: Realm, show_sender: bool=False, def construct_zulip_body(message: message.Message, realm: Realm, show_sender: bool=False,
include_quotations: bool=False, include_footer: bool=False) -> str: include_quotes: bool=False, include_footer: bool=False) -> str:
body = extract_body(message, include_quotations) body = extract_body(message, include_quotes)
# Remove null characters, since Zulip will reject # Remove null characters, since Zulip will reject
body = body.replace("\x00", "") body = body.replace("\x00", "")
if not include_footer: if not include_footer:
@@ -243,7 +243,7 @@ def get_message_part_by_type(message: message.Message, content_type: str) -> Opt
return None return None
talon_initialized = False 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 import talon
global talon_initialized global talon_initialized
if not talon_initialized: if not talon_initialized:
@@ -254,7 +254,7 @@ def extract_body(message: message.Message, include_quotations: bool=False) -> st
# that. # that.
plaintext_content = get_message_part_by_type(message, "text/plain") plaintext_content = get_message_part_by_type(message, "text/plain")
if plaintext_content: if plaintext_content:
if include_quotations: if include_quotes:
return plaintext_content return plaintext_content
else: else:
return talon.quotations.extract_from_plain(plaintext_content) 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. # If we only have an HTML version, try to make that look nice.
html_content = get_message_part_by_type(message, "text/html") html_content = get_message_part_by_type(message, "text/html")
if html_content: if html_content:
if include_quotations: if include_quotes:
return convert_html_to_markdown(html_content) return convert_html_to_markdown(html_content)
else: else:
return convert_html_to_markdown(talon.quotations.extract_from_html(html_content)) 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) stream, options = extract_and_validate(to)
# Don't remove quotations if message is forwarded, unless otherwise specified: # Don't remove quotations if message is forwarded, unless otherwise specified:
if 'include_quotations' not in options: if 'include_quotes' not in options:
options['include_quotations'] = is_forwarded(subject_header) options['include_quotes'] = is_forwarded(subject_header)
body = construct_zulip_body(message, stream.realm, **options) body = construct_zulip_body(message, stream.realm, **options)
send_zulip(settings.EMAIL_GATEWAY_BOT, stream, subject, body) send_zulip(settings.EMAIL_GATEWAY_BOT, stream, subject, body)

View File

@@ -7,7 +7,7 @@ from zerver.models import Stream
from typing import Dict, Tuple 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): class ZulipEmailForwardError(Exception):
pass pass

View File

@@ -59,10 +59,10 @@ from typing import Any, Callable, Dict, Mapping, Union, Optional
class TestEncodeDecode(ZulipTestCase): class TestEncodeDecode(ZulipTestCase):
def _assert_options(self, options: Dict[str, bool], show_sender: bool=False, 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(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_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: def test_encode_decode(self) -> None:
realm = get_realm('zulip') realm = get_realm('zulip')
@@ -77,10 +77,10 @@ class TestEncodeDecode(ZulipTestCase):
parts = email_address.split('@') parts = email_address.split('@')
# Use a mix of + and . as separators, to test that it works: # 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) email_address_all_options = '@'.join(parts)
token, options = decode_email_address(email_address_all_options) 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) self.assertEqual(token, stream.email_token)
email_address = email_address.replace('@testserver', '@zulip.org') email_address = email_address.replace('@testserver', '@zulip.org')
@@ -97,7 +97,7 @@ class TestEncodeDecode(ZulipTestCase):
self.assertEqual(token, stream.email_token) self.assertEqual(token, stream.email_token)
token, options = decode_email_address(email_address_all_options) 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) self.assertEqual(token, stream.email_token)
with self.assertRaises(ZulipEmailForwardError): with self.assertRaises(ZulipEmailForwardError):
@@ -335,7 +335,7 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
self.assertEqual(get_display_recipient(message.recipient), stream.name) self.assertEqual(get_display_recipient(message.recipient), stream.name)
self.assertEqual(message.topic_name(), incoming_valid_message['Subject']) 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') user_profile = self.example_user('hamlet')
self.login(user_profile.email) self.login(user_profile.email)
self.subscribe(user_profile, "Denmark") self.subscribe(user_profile, "Denmark")
@@ -343,7 +343,7 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
parts = stream_to_address.split('@') parts = stream_to_address.split('@')
parts[0] += "+include-quotations" parts[0] += "+include-quotes"
stream_to_address = '@'.join(parts) stream_to_address = '@'.join(parts)
text = """Reply text = """Reply