Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
send_email: Distinct emails means distinct, case-insensitively.
Alex Vandiverbd38e6cb696d
diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.pyindex 9cfca2df27c..1fbbda4b8be 100644--- a/zerver/lib/send_email.py+++ b/zerver/lib/send_email.py@@ -21,6 +21,7 @@ from django.core.mail.message import sanitize_addressfrom django.core.management import CommandErrorfrom django.db import transactionfrom django.db.models import QuerySet+from django.db.models.functions import Lowerfrom django.http import HttpRequestfrom django.template import loaderfrom django.utils.timezone import now as timezone_now@@ -583,7 +584,7 @@ def send_custom_email(options: Dict[str, str],add_context: Optional[Callable[[Dict[str, object], UserProfile], None]] = None,distinct_email: bool = False,-) -> None:+) -> QuerySet[UserProfile]:"""Helper for `manage.py send_custom_email`.@@ -598,7 +599,11 @@ def send_custom_email(users = users.select_related("realm")if distinct_email:- users = users.distinct("delivery_email").order_by("delivery_email", "id")+ users = (+ users.annotate(lower_email=Lower("delivery_email"))+ .distinct("lower_email")+ .order_by("lower_email", "id")+ )else:users = users.order_by("id")for user_profile in users:@@ -617,6 +622,7 @@ def send_custom_email(if dry_run:break+ return usersdef send_custom_server_email(diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.pyindex 2e99d994b7c..ce27835a032 100644--- a/zerver/management/commands/send_custom_email.py+++ b/zerver/management/commands/send_custom_email.py@@ -197,7 +197,7 @@ class Command(ZulipBaseCommand):users = users.exclude(Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN))- send_custom_email(+ users = send_custom_email(users,dry_run=dry_run,options=options,