prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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>`.
  
  </issue>
  <code>
  [start of CTFd/utils/email/smtp.py]
  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
  [end of CTFd/utils/email/smtp.py]
  [start of CTFd/utils/email/mailgun.py]
  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 of CTFd/utils/email/mailgun.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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"),
  
verification_info: {"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"}]}