mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	email_mirror: Give extract_and_validate a more descriptive name.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							90a69ab24f
						
					
				
				
					commit
					89046ea1a9
				
			@@ -46,7 +46,7 @@ def redact_email_address(error_message: str) -> str:
 | 
				
			|||||||
                                                     "{} <Missed message address>".format(email_address))
 | 
					                                                     "{} <Missed message address>".format(email_address))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                target_stream_id = extract_and_validate(email_address)[0].id
 | 
					                target_stream_id = decode_stream_email_address(email_address)[0].id
 | 
				
			||||||
                annotated_address = "{} <Address to stream id: {}>".format(email_address, target_stream_id)
 | 
					                annotated_address = "{} <Address to stream id: {}>".format(email_address, target_stream_id)
 | 
				
			||||||
                redacted_message = error_message.replace(email_address, annotated_address)
 | 
					                redacted_message = error_message.replace(email_address, annotated_address)
 | 
				
			||||||
            except ZulipEmailForwardError:
 | 
					            except ZulipEmailForwardError:
 | 
				
			||||||
@@ -244,7 +244,7 @@ def extract_and_upload_attachments(message: message.Message, realm: Realm) -> st
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return "\n".join(attachment_links)
 | 
					    return "\n".join(attachment_links)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def extract_and_validate(email: str) -> Tuple[Stream, Dict[str, bool]]:
 | 
					def decode_stream_email_address(email: str) -> Tuple[Stream, Dict[str, bool]]:
 | 
				
			||||||
    token, options = decode_email_address(email)
 | 
					    token, options = decode_email_address(email)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
@@ -291,7 +291,7 @@ def process_stream_message(to: str, message: message.Message) -> None:
 | 
				
			|||||||
    subject_header = str(make_header(decode_header(message.get("Subject", ""))))
 | 
					    subject_header = str(make_header(decode_header(message.get("Subject", ""))))
 | 
				
			||||||
    subject = strip_from_subject(subject_header) or "(no topic)"
 | 
					    subject = strip_from_subject(subject_header) or "(no topic)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stream, options = extract_and_validate(to)
 | 
					    stream, options = decode_stream_email_address(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_quotes' not in options:
 | 
					    if 'include_quotes' not in options:
 | 
				
			||||||
        options['include_quotes'] = is_forwarded(subject_header)
 | 
					        options['include_quotes'] = is_forwarded(subject_header)
 | 
				
			||||||
@@ -375,7 +375,7 @@ def validate_to_address(rcpt_to: str) -> None:
 | 
				
			|||||||
        if not mm_address.is_usable():
 | 
					        if not mm_address.is_usable():
 | 
				
			||||||
            raise ZulipEmailForwardError("Missed message address out of uses.")
 | 
					            raise ZulipEmailForwardError("Missed message address out of uses.")
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        extract_and_validate(rcpt_to)
 | 
					        decode_stream_email_address(rcpt_to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def mirror_email_message(data: Dict[str, str]) -> Dict[str, str]:
 | 
					def mirror_email_message(data: Dict[str, str]) -> Dict[str, str]:
 | 
				
			||||||
    rcpt_to = data['recipient']
 | 
					    rcpt_to = data['recipient']
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ from zerver.lib.digest import handle_digest_email
 | 
				
			|||||||
from zerver.lib.send_email import send_future_email, send_email_from_dict, \
 | 
					from zerver.lib.send_email import send_future_email, send_email_from_dict, \
 | 
				
			||||||
    FromAddress, EmailNotDeliveredException, handle_send_email_format_changes
 | 
					    FromAddress, EmailNotDeliveredException, handle_send_email_format_changes
 | 
				
			||||||
from zerver.lib.email_mirror import process_message as mirror_email, rate_limit_mirror_by_realm, \
 | 
					from zerver.lib.email_mirror import process_message as mirror_email, rate_limit_mirror_by_realm, \
 | 
				
			||||||
    is_missed_message_address, extract_and_validate
 | 
					    is_missed_message_address, decode_stream_email_address
 | 
				
			||||||
from zerver.lib.streams import access_stream_by_id
 | 
					from zerver.lib.streams import access_stream_by_id
 | 
				
			||||||
from zerver.tornado.socket import req_redis_key, respond_send_message
 | 
					from zerver.tornado.socket import req_redis_key, respond_send_message
 | 
				
			||||||
from zerver.lib.db import reset_queries
 | 
					from zerver.lib.db import reset_queries
 | 
				
			||||||
@@ -559,7 +559,7 @@ class MirrorWorker(QueueProcessingWorker):
 | 
				
			|||||||
        if not is_missed_message_address(rcpt_to):
 | 
					        if not is_missed_message_address(rcpt_to):
 | 
				
			||||||
            # Missed message addresses are one-time use, so we don't need
 | 
					            # Missed message addresses are one-time use, so we don't need
 | 
				
			||||||
            # to worry about emails to them resulting in message spam.
 | 
					            # to worry about emails to them resulting in message spam.
 | 
				
			||||||
            recipient_realm = extract_and_validate(rcpt_to)[0].realm
 | 
					            recipient_realm = decode_stream_email_address(rcpt_to)[0].realm
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                rate_limit_mirror_by_realm(recipient_realm)
 | 
					                rate_limit_mirror_by_realm(recipient_realm)
 | 
				
			||||||
            except RateLimited:
 | 
					            except RateLimited:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user