We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Colon in CTF name breaks emails
This is because of:

https://tools.ietf.org/html/rfc5322#section-2.2

This can probably be fixed with `"HE:tech" <tech@example.com>`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `CTFd/utils/email/smtp.py`
Content:
```
1 import smtplib
2 from email.message import EmailMessage
3 from socket import timeout
4 
5 from CTFd.utils import get_app_config, get_config
6 
7 
8 def get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=None):
9     if SSL is None:
10         smtp = smtplib.SMTP(host, port, timeout=3)
11     else:
12         smtp = smtplib.SMTP_SSL(host, port, timeout=3)
13 
14     if TLS:
15         smtp.starttls()
16 
17     if auth:
18         smtp.login(username, password)
19     return smtp
20 
21 
22 def sendmail(addr, text, subject):
23     ctf_name = get_config("ctf_name")
24     mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
25     mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
26 
27     data = {
28         "host": get_config("mail_server") or get_app_config("MAIL_SERVER"),
29         "port": int(get_config("mail_port") or get_app_config("MAIL_PORT")),
30     }
31     username = get_config("mail_username") or get_app_config("MAIL_USERNAME")
32     password = get_config("mail_password") or get_app_config("MAIL_PASSWORD")
33     TLS = get_config("mail_tls") or get_app_config("MAIL_TLS")
34     SSL = get_config("mail_ssl") or get_app_config("MAIL_SSL")
35     auth = get_config("mail_useauth") or get_app_config("MAIL_USEAUTH")
36 
37     if username:
38         data["username"] = username
39     if password:
40         data["password"] = password
41     if TLS:
42         data["TLS"] = TLS
43     if SSL:
44         data["SSL"] = SSL
45     if auth:
46         data["auth"] = auth
47 
48     try:
49         smtp = get_smtp(**data)
50 
51         msg = EmailMessage()
52         msg.set_content(text)
53 
54         msg["Subject"] = subject
55         msg["From"] = mailfrom_addr
56         msg["To"] = addr
57 
58         smtp.send_message(msg)
59 
60         smtp.quit()
61         return True, "Email sent"
62     except smtplib.SMTPException as e:
63         return False, str(e)
64     except timeout:
65         return False, "SMTP server connection timed out"
66     except Exception as e:
67         return False, str(e)
68
```

Path: `CTFd/utils/email/mailgun.py`
Content:
```
1 import requests
2 
3 from CTFd.utils import get_app_config, get_config
4 
5 
6 def sendmail(addr, text, subject):
7     ctf_name = get_config("ctf_name")
8     mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
9     mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
10 
11     mailgun_base_url = get_config("mailgun_base_url") or get_app_config(
12         "MAILGUN_BASE_URL"
13     )
14     mailgun_api_key = get_config("mailgun_api_key") or get_app_config("MAILGUN_API_KEY")
15     try:
16         r = requests.post(
17             mailgun_base_url + "/messages",
18             auth=("api", mailgun_api_key),
19             data={
20                 "from": mailfrom_addr,
21                 "to": [addr],
22                 "subject": subject,
23                 "text": text,
24             },
25             timeout=1.0,
26         )
27     except requests.RequestException as e:
28         return (
29             False,
30             "{error} exception occured while handling your request".format(
31                 error=type(e).__name__
32             ),
33         )
34 
35     if r.status_code == 200:
36         return True, "Email sent"
37     else:
38         return False, "Mailgun settings are incorrect"
39
```
--- 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/CTFd/utils/email/mailgun.py b/CTFd/utils/email/mailgun.py
--- a/CTFd/utils/email/mailgun.py
+++ b/CTFd/utils/email/mailgun.py
@@ -1,3 +1,5 @@
+from email.utils import formataddr
+
 import requests
 
 from CTFd.utils import get_app_config, get_config
@@ -6,7 +8,7 @@
 def sendmail(addr, text, subject):
     ctf_name = get_config("ctf_name")
     mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
-    mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
+    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))
 
     mailgun_base_url = get_config("mailgun_base_url") or get_app_config(
         "MAILGUN_BASE_URL"
diff --git a/CTFd/utils/email/smtp.py b/CTFd/utils/email/smtp.py
--- a/CTFd/utils/email/smtp.py
+++ b/CTFd/utils/email/smtp.py
@@ -1,5 +1,6 @@
 import smtplib
 from email.message import EmailMessage
+from email.utils import formataddr
 from socket import timeout
 
 from CTFd.utils import get_app_config, get_config
@@ -22,7 +23,7 @@
 def sendmail(addr, text, subject):
     ctf_name = get_config("ctf_name")
     mailfrom_addr = get_config("mailfrom_addr") or get_app_config("MAILFROM_ADDR")
-    mailfrom_addr = "{} <{}>".format(ctf_name, mailfrom_addr)
+    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))
 
     data = {
         "host": get_config("mail_server") or get_app_config("MAIL_SERVER"),

{"golden_diff": "diff --git a/CTFd/utils/email/mailgun.py b/CTFd/utils/email/mailgun.py\n--- a/CTFd/utils/email/mailgun.py\n+++ b/CTFd/utils/email/mailgun.py\n@@ -1,3 +1,5 @@\n+from email.utils import formataddr\n+\n import requests\n \n from CTFd.utils import get_app_config, get_config\n@@ -6,7 +8,7 @@\n def sendmail(addr, text, subject):\n     ctf_name = get_config(\"ctf_name\")\n     mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n-    mailfrom_addr = \"{} <{}>\".format(ctf_name, mailfrom_addr)\n+    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))\n \n     mailgun_base_url = get_config(\"mailgun_base_url\") or get_app_config(\n         \"MAILGUN_BASE_URL\"\ndiff --git a/CTFd/utils/email/smtp.py b/CTFd/utils/email/smtp.py\n--- a/CTFd/utils/email/smtp.py\n+++ b/CTFd/utils/email/smtp.py\n@@ -1,5 +1,6 @@\n import smtplib\n from email.message import EmailMessage\n+from email.utils import formataddr\n from socket import timeout\n \n from CTFd.utils import get_app_config, get_config\n@@ -22,7 +23,7 @@\n def sendmail(addr, text, subject):\n     ctf_name = get_config(\"ctf_name\")\n     mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n-    mailfrom_addr = \"{} <{}>\".format(ctf_name, mailfrom_addr)\n+    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))\n \n     data = {\n         \"host\": get_config(\"mail_server\") or get_app_config(\"MAIL_SERVER\"),\n", "issue": "Colon in CTF name breaks emails\nThis is because of:\r\n\r\nhttps://tools.ietf.org/html/rfc5322#section-2.2\r\n\r\nThis can probably be fixed with `\"HE:tech\" <tech@example.com>`.\n", "before_files": [{"content": "import smtplib\nfrom email.message import EmailMessage\nfrom socket import timeout\n\nfrom CTFd.utils import get_app_config, get_config\n\n\ndef get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=None):\n    if SSL is None:\n        smtp = smtplib.SMTP(host, port, timeout=3)\n    else:\n        smtp = smtplib.SMTP_SSL(host, port, timeout=3)\n\n    if TLS:\n        smtp.starttls()\n\n    if auth:\n        smtp.login(username, password)\n    return smtp\n\n\ndef sendmail(addr, text, subject):\n    ctf_name = get_config(\"ctf_name\")\n    mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n    mailfrom_addr = \"{} <{}>\".format(ctf_name, mailfrom_addr)\n\n    data = {\n        \"host\": get_config(\"mail_server\") or get_app_config(\"MAIL_SERVER\"),\n        \"port\": int(get_config(\"mail_port\") or get_app_config(\"MAIL_PORT\")),\n    }\n    username = get_config(\"mail_username\") or get_app_config(\"MAIL_USERNAME\")\n    password = get_config(\"mail_password\") or get_app_config(\"MAIL_PASSWORD\")\n    TLS = get_config(\"mail_tls\") or get_app_config(\"MAIL_TLS\")\n    SSL = get_config(\"mail_ssl\") or get_app_config(\"MAIL_SSL\")\n    auth = get_config(\"mail_useauth\") or get_app_config(\"MAIL_USEAUTH\")\n\n    if username:\n        data[\"username\"] = username\n    if password:\n        data[\"password\"] = password\n    if TLS:\n        data[\"TLS\"] = TLS\n    if SSL:\n        data[\"SSL\"] = SSL\n    if auth:\n        data[\"auth\"] = auth\n\n    try:\n        smtp = get_smtp(**data)\n\n        msg = EmailMessage()\n        msg.set_content(text)\n\n        msg[\"Subject\"] = subject\n        msg[\"From\"] = mailfrom_addr\n        msg[\"To\"] = addr\n\n        smtp.send_message(msg)\n\n        smtp.quit()\n        return True, \"Email sent\"\n    except smtplib.SMTPException as e:\n        return False, str(e)\n    except timeout:\n        return False, \"SMTP server connection timed out\"\n    except Exception as e:\n        return False, str(e)\n", "path": "CTFd/utils/email/smtp.py"}, {"content": "import requests\n\nfrom CTFd.utils import get_app_config, get_config\n\n\ndef sendmail(addr, text, subject):\n    ctf_name = get_config(\"ctf_name\")\n    mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n    mailfrom_addr = \"{} <{}>\".format(ctf_name, mailfrom_addr)\n\n    mailgun_base_url = get_config(\"mailgun_base_url\") or get_app_config(\n        \"MAILGUN_BASE_URL\"\n    )\n    mailgun_api_key = get_config(\"mailgun_api_key\") or get_app_config(\"MAILGUN_API_KEY\")\n    try:\n        r = requests.post(\n            mailgun_base_url + \"/messages\",\n            auth=(\"api\", mailgun_api_key),\n            data={\n                \"from\": mailfrom_addr,\n                \"to\": [addr],\n                \"subject\": subject,\n                \"text\": text,\n            },\n            timeout=1.0,\n        )\n    except requests.RequestException as e:\n        return (\n            False,\n            \"{error} exception occured while handling your request\".format(\n                error=type(e).__name__\n            ),\n        )\n\n    if r.status_code == 200:\n        return True, \"Email sent\"\n    else:\n        return False, \"Mailgun settings are incorrect\"\n", "path": "CTFd/utils/email/mailgun.py"}], "after_files": [{"content": "import smtplib\nfrom email.message import EmailMessage\nfrom email.utils import formataddr\nfrom socket import timeout\n\nfrom CTFd.utils import get_app_config, get_config\n\n\ndef get_smtp(host, port, username=None, password=None, TLS=None, SSL=None, auth=None):\n    if SSL is None:\n        smtp = smtplib.SMTP(host, port, timeout=3)\n    else:\n        smtp = smtplib.SMTP_SSL(host, port, timeout=3)\n\n    if TLS:\n        smtp.starttls()\n\n    if auth:\n        smtp.login(username, password)\n    return smtp\n\n\ndef sendmail(addr, text, subject):\n    ctf_name = get_config(\"ctf_name\")\n    mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))\n\n    data = {\n        \"host\": get_config(\"mail_server\") or get_app_config(\"MAIL_SERVER\"),\n        \"port\": int(get_config(\"mail_port\") or get_app_config(\"MAIL_PORT\")),\n    }\n    username = get_config(\"mail_username\") or get_app_config(\"MAIL_USERNAME\")\n    password = get_config(\"mail_password\") or get_app_config(\"MAIL_PASSWORD\")\n    TLS = get_config(\"mail_tls\") or get_app_config(\"MAIL_TLS\")\n    SSL = get_config(\"mail_ssl\") or get_app_config(\"MAIL_SSL\")\n    auth = get_config(\"mail_useauth\") or get_app_config(\"MAIL_USEAUTH\")\n\n    if username:\n        data[\"username\"] = username\n    if password:\n        data[\"password\"] = password\n    if TLS:\n        data[\"TLS\"] = TLS\n    if SSL:\n        data[\"SSL\"] = SSL\n    if auth:\n        data[\"auth\"] = auth\n\n    try:\n        smtp = get_smtp(**data)\n\n        msg = EmailMessage()\n        msg.set_content(text)\n\n        msg[\"Subject\"] = subject\n        msg[\"From\"] = mailfrom_addr\n        msg[\"To\"] = addr\n\n        smtp.send_message(msg)\n\n        smtp.quit()\n        return True, \"Email sent\"\n    except smtplib.SMTPException as e:\n        return False, str(e)\n    except timeout:\n        return False, \"SMTP server connection timed out\"\n    except Exception as e:\n        return False, str(e)\n", "path": "CTFd/utils/email/smtp.py"}, {"content": "from email.utils import formataddr\n\nimport requests\n\nfrom CTFd.utils import get_app_config, get_config\n\n\ndef sendmail(addr, text, subject):\n    ctf_name = get_config(\"ctf_name\")\n    mailfrom_addr = get_config(\"mailfrom_addr\") or get_app_config(\"MAILFROM_ADDR\")\n    mailfrom_addr = formataddr((ctf_name, mailfrom_addr))\n\n    mailgun_base_url = get_config(\"mailgun_base_url\") or get_app_config(\n        \"MAILGUN_BASE_URL\"\n    )\n    mailgun_api_key = get_config(\"mailgun_api_key\") or get_app_config(\"MAILGUN_API_KEY\")\n    try:\n        r = requests.post(\n            mailgun_base_url + \"/messages\",\n            auth=(\"api\", mailgun_api_key),\n            data={\n                \"from\": mailfrom_addr,\n                \"to\": [addr],\n                \"subject\": subject,\n                \"text\": text,\n            },\n            timeout=1.0,\n        )\n    except requests.RequestException as e:\n        return (\n            False,\n            \"{error} exception occured while handling your request\".format(\n                error=type(e).__name__\n            ),\n        )\n\n    if r.status_code == 200:\n        return True, \"Email sent\"\n    else:\n        return False, \"Mailgun settings are incorrect\"\n", "path": "CTFd/utils/email/mailgun.py"}]}