We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Refactorings for welcome HTML email 
Based on https://github.com/mdn/kuma/pull/7866 
we'll drop the `utm` query string things and we'll get rid of the plain text email template. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kuma/users/tasks.py`
Content:
```
1 import logging
2 
3 from celery import task
4 from django.conf import settings
5 from django.contrib.auth import get_user_model
6 from django.utils import translation
7 from django.utils.translation import gettext_lazy as _
8 
9 from kuma.core.decorators import skip_in_maintenance_mode
10 from kuma.core.email_utils import render_email
11 from kuma.core.utils import (
12     EmailMultiAlternativesRetrying,
13     send_mail_retrying,
14     strings_are_translated,
15 )
16 
17 log = logging.getLogger("kuma.users.tasks")
18 
19 
20 WELCOME_EMAIL_STRINGS = [
21     "Like words?",
22     "Don't be shy, if you have any doubt, problems, questions: contact us! We are here to help.",
23 ]
24 
25 
26 @task
27 @skip_in_maintenance_mode
28 def send_recovery_email(user_pk, email, locale=None):
29     user = get_user_model().objects.get(pk=user_pk)
30     locale = locale or settings.WIKI_DEFAULT_LANGUAGE
31     url = settings.SITE_URL + user.get_recovery_url()
32     context = {"recovery_url": url, "username": user.username}
33     with translation.override(locale):
34         subject = render_email("users/email/recovery/subject.ltxt", context)
35         # Email subject *must not* contain newlines
36         subject = "".join(subject.splitlines())
37         plain = render_email("users/email/recovery/plain.ltxt", context)
38         send_mail_retrying(subject, plain, settings.DEFAULT_FROM_EMAIL, [email])
39 
40 
41 @task
42 @skip_in_maintenance_mode
43 def send_welcome_email(user_pk, locale):
44     user = get_user_model().objects.get(pk=user_pk)
45     if locale == settings.WIKI_DEFAULT_LANGUAGE or strings_are_translated(
46         WELCOME_EMAIL_STRINGS, locale
47     ):
48         context = {"username": user.username}
49         log.debug("Using the locale %s to send the welcome email", locale)
50         with translation.override(locale):
51             content_plain = render_email("users/email/welcome/plain.ltxt", context)
52             content_html = render_email("users/email/welcome/html.ltxt", context)
53 
54             email = EmailMultiAlternativesRetrying(
55                 _("Getting started with your new MDN account"),
56                 content_plain,
57                 settings.WELCOME_EMAIL_FROM,
58                 [user.email],
59             )
60             email.attach_alternative(content_html, "text/html")
61             email.send()
62
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kuma/users/tasks.py b/kuma/users/tasks.py
--- a/kuma/users/tasks.py
+++ b/kuma/users/tasks.py
@@ -5,6 +5,7 @@
 from django.contrib.auth import get_user_model
 from django.utils import translation
 from django.utils.translation import gettext_lazy as _
+from pyquery import PyQuery as pq
 
 from kuma.core.decorators import skip_in_maintenance_mode
 from kuma.core.email_utils import render_email
@@ -48,8 +49,18 @@
         context = {"username": user.username}
         log.debug("Using the locale %s to send the welcome email", locale)
         with translation.override(locale):
-            content_plain = render_email("users/email/welcome/plain.ltxt", context)
             content_html = render_email("users/email/welcome/html.ltxt", context)
+            doc = pq(content_html)
+            urls = []
+            for i, link in enumerate(doc("body a[href]").items()):
+                link.text(f"{link.text()}[{i + 1}]")
+                urls.append((i + 1, link.attr("href")))
+
+            content_plain = doc("body").text().replace("\n", "\n\n")
+            if urls:
+                content_plain += "\n\n"
+                for i, url in urls:
+                    content_plain += f"[{i}] {url}\n"
 
             email = EmailMultiAlternativesRetrying(
                 _("Getting started with your new MDN account"),

{"golden_diff": "diff --git a/kuma/users/tasks.py b/kuma/users/tasks.py\n--- a/kuma/users/tasks.py\n+++ b/kuma/users/tasks.py\n@@ -5,6 +5,7 @@\n from django.contrib.auth import get_user_model\n from django.utils import translation\n from django.utils.translation import gettext_lazy as _\n+from pyquery import PyQuery as pq\n \n from kuma.core.decorators import skip_in_maintenance_mode\n from kuma.core.email_utils import render_email\n@@ -48,8 +49,18 @@\n         context = {\"username\": user.username}\n         log.debug(\"Using the locale %s to send the welcome email\", locale)\n         with translation.override(locale):\n-            content_plain = render_email(\"users/email/welcome/plain.ltxt\", context)\n             content_html = render_email(\"users/email/welcome/html.ltxt\", context)\n+            doc = pq(content_html)\n+            urls = []\n+            for i, link in enumerate(doc(\"body a[href]\").items()):\n+                link.text(f\"{link.text()}[{i + 1}]\")\n+                urls.append((i + 1, link.attr(\"href\")))\n+\n+            content_plain = doc(\"body\").text().replace(\"\\n\", \"\\n\\n\")\n+            if urls:\n+                content_plain += \"\\n\\n\"\n+                for i, url in urls:\n+                    content_plain += f\"[{i}] {url}\\n\"\n \n             email = EmailMultiAlternativesRetrying(\n                 _(\"Getting started with your new MDN account\"),\n", "issue": "Refactorings for welcome HTML email \nBased on https://github.com/mdn/kuma/pull/7866 \r\nwe'll drop the `utm` query string things and we'll get rid of the plain text email template. \n", "before_files": [{"content": "import logging\n\nfrom celery import task\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.utils import translation\nfrom django.utils.translation import gettext_lazy as _\n\nfrom kuma.core.decorators import skip_in_maintenance_mode\nfrom kuma.core.email_utils import render_email\nfrom kuma.core.utils import (\n    EmailMultiAlternativesRetrying,\n    send_mail_retrying,\n    strings_are_translated,\n)\n\nlog = logging.getLogger(\"kuma.users.tasks\")\n\n\nWELCOME_EMAIL_STRINGS = [\n    \"Like words?\",\n    \"Don't be shy, if you have any doubt, problems, questions: contact us! We are here to help.\",\n]\n\n\n@task\n@skip_in_maintenance_mode\ndef send_recovery_email(user_pk, email, locale=None):\n    user = get_user_model().objects.get(pk=user_pk)\n    locale = locale or settings.WIKI_DEFAULT_LANGUAGE\n    url = settings.SITE_URL + user.get_recovery_url()\n    context = {\"recovery_url\": url, \"username\": user.username}\n    with translation.override(locale):\n        subject = render_email(\"users/email/recovery/subject.ltxt\", context)\n        # Email subject *must not* contain newlines\n        subject = \"\".join(subject.splitlines())\n        plain = render_email(\"users/email/recovery/plain.ltxt\", context)\n        send_mail_retrying(subject, plain, settings.DEFAULT_FROM_EMAIL, [email])\n\n\n@task\n@skip_in_maintenance_mode\ndef send_welcome_email(user_pk, locale):\n    user = get_user_model().objects.get(pk=user_pk)\n    if locale == settings.WIKI_DEFAULT_LANGUAGE or strings_are_translated(\n        WELCOME_EMAIL_STRINGS, locale\n    ):\n        context = {\"username\": user.username}\n        log.debug(\"Using the locale %s to send the welcome email\", locale)\n        with translation.override(locale):\n            content_plain = render_email(\"users/email/welcome/plain.ltxt\", context)\n            content_html = render_email(\"users/email/welcome/html.ltxt\", context)\n\n            email = EmailMultiAlternativesRetrying(\n                _(\"Getting started with your new MDN account\"),\n                content_plain,\n                settings.WELCOME_EMAIL_FROM,\n                [user.email],\n            )\n            email.attach_alternative(content_html, \"text/html\")\n            email.send()\n", "path": "kuma/users/tasks.py"}], "after_files": [{"content": "import logging\n\nfrom celery import task\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.utils import translation\nfrom django.utils.translation import gettext_lazy as _\nfrom pyquery import PyQuery as pq\n\nfrom kuma.core.decorators import skip_in_maintenance_mode\nfrom kuma.core.email_utils import render_email\nfrom kuma.core.utils import (\n    EmailMultiAlternativesRetrying,\n    send_mail_retrying,\n    strings_are_translated,\n)\n\nlog = logging.getLogger(\"kuma.users.tasks\")\n\n\nWELCOME_EMAIL_STRINGS = [\n    \"Like words?\",\n    \"Don't be shy, if you have any doubt, problems, questions: contact us! We are here to help.\",\n]\n\n\n@task\n@skip_in_maintenance_mode\ndef send_recovery_email(user_pk, email, locale=None):\n    user = get_user_model().objects.get(pk=user_pk)\n    locale = locale or settings.WIKI_DEFAULT_LANGUAGE\n    url = settings.SITE_URL + user.get_recovery_url()\n    context = {\"recovery_url\": url, \"username\": user.username}\n    with translation.override(locale):\n        subject = render_email(\"users/email/recovery/subject.ltxt\", context)\n        # Email subject *must not* contain newlines\n        subject = \"\".join(subject.splitlines())\n        plain = render_email(\"users/email/recovery/plain.ltxt\", context)\n        send_mail_retrying(subject, plain, settings.DEFAULT_FROM_EMAIL, [email])\n\n\n@task\n@skip_in_maintenance_mode\ndef send_welcome_email(user_pk, locale):\n    user = get_user_model().objects.get(pk=user_pk)\n    if locale == settings.WIKI_DEFAULT_LANGUAGE or strings_are_translated(\n        WELCOME_EMAIL_STRINGS, locale\n    ):\n        context = {\"username\": user.username}\n        log.debug(\"Using the locale %s to send the welcome email\", locale)\n        with translation.override(locale):\n            content_html = render_email(\"users/email/welcome/html.ltxt\", context)\n            doc = pq(content_html)\n            urls = []\n            for i, link in enumerate(doc(\"body a[href]\").items()):\n                link.text(f\"{link.text()}[{i + 1}]\")\n                urls.append((i + 1, link.attr(\"href\")))\n\n            content_plain = doc(\"body\").text().replace(\"\\n\", \"\\n\\n\")\n            if urls:\n                content_plain += \"\\n\\n\"\n                for i, url in urls:\n                    content_plain += f\"[{i}] {url}\\n\"\n\n            email = EmailMultiAlternativesRetrying(\n                _(\"Getting started with your new MDN account\"),\n                content_plain,\n                settings.WELCOME_EMAIL_FROM,\n                [user.email],\n            )\n            email.attach_alternative(content_html, \"text/html\")\n            email.send()\n", "path": "kuma/users/tasks.py"}]}