Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
slack: Fix formation of bot email addresses with non-ascii chars.
Mateusz Manderaa473d05840aa
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.pyindex 6088767bcdd..852028fea26 100644--- a/zerver/data_import/slack.py+++ b/zerver/data_import/slack.py@@ -11,6 +11,7 @@ import zipfilefrom collections import defaultdictfrom collections.abc import Iteratorfrom datetime import datetime, timezone+from email.errors import HeaderDefectfrom email.headerregistry import Addressfrom typing import Any, TypeAliasfrom urllib.parse import SplitResult, urlsplit@@ -124,6 +125,18 @@ class SlackBotEmail:username=slack_bot_name.replace("Bot", "").replace(" ", "").lower() + "-bot",domain=domain_name,).addr_spec+ # The address formed above may not be a valid email format - e.g. containing+ # non-ASCII characters in the local part, if the slack_bot_name contains them.+ # Only Address(addr_spec=...) triggers the necessary validation.+ # Thus we call it here, and if issues are detected, we fall back to forming the+ # email address in a safer way - using the bot id string.+ try:+ Address(addr_spec=email)+ except HeaderDefect:+ email = Address(+ username=slack_bot_id + "-bot",+ domain=domain_name,+ ).addr_specif email in cls.duplicate_email_count:cls.duplicate_email_count[email] += 1