refactor: Separate get channel email token logic from email encoding.

This commit extracts the logic for creating or retrieving a channel
email token into a dedicated `get_channel_email_token` function.

This improves code clarity by decoupling token generation from
the email encoding process.
This commit is contained in:
Prakhar Pratyush
2024-12-25 13:57:36 +05:30
committed by Tim Abbott
parent 864a2a067e
commit 2bb4b70121
6 changed files with 100 additions and 65 deletions

View File

@@ -48,17 +48,17 @@ def get_email_gateway_message_string_from_address(address: str) -> str:
return msg_string
def encode_email_address(stream: Stream, show_sender: bool = False) -> str:
def get_channel_email_token(stream: Stream) -> str:
channel_email_address, ignored = ChannelEmailAddress.objects.get_or_create(
realm=stream.realm,
channel=stream,
creator=stream.creator,
sender=get_system_bot(settings.EMAIL_GATEWAY_BOT, stream.realm_id),
)
return encode_email_address_helper(stream.name, channel_email_address.email_token, show_sender)
return channel_email_address.email_token
def encode_email_address_helper(name: str, email_token: str, show_sender: bool = False) -> str:
def encode_email_address(name: str, email_token: str, show_sender: bool = False) -> str:
# Some deployments may not use the email gateway
if settings.EMAIL_GATEWAY_PATTERN == "":
return ""