prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Remove fixed subject line from contact form
  The contact form has a drop down for choosing a topic. When patrons submit this form, the submissions all go to the same inbox. The selected topics are usually incorrect, but also make it more difficult to manage the inbox due to most messages looking the same.
  
  ### Describe the problem that you'd like solved
  Let the patron populate the subject line OR auto-populate the subject line from the message.
  
  ### Proposal & Constraints
  <!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->
  
  <!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->
  
  ### Additional context
  <!-- Add any other context or screenshots about the feature request here. -->
  
  ### Stakeholders
  <!-- @ tag stakeholders of this bug -->
  
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `openlibrary/plugins/openlibrary/support.py`
  Content:
  ```
  1 import hashlib
  2 
  3 import web
  4 import logging
  5 
  6 from infogami import config
  7 from infogami.utils import delegate
  8 from infogami.utils.view import render_template
  9 
  10 from openlibrary import accounts
  11 from openlibrary.core import stats
  12 from openlibrary.core.cache import get_memcache
  13 from openlibrary.plugins.upstream.addbook import get_recaptcha
  14 from openlibrary.utils.dateutil import MINUTE_SECS
  15 
  16 logger = logging.getLogger("openlibrary")
  17 
  18 
  19 class contact(delegate.page):
  20     def GET(self):
  21         i = web.input(path=None)
  22         user = accounts.get_current_user()
  23         email = user and user.email
  24 
  25         hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()
  26         has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)
  27         recaptcha = has_emailed_recently and get_recaptcha()
  28         return render_template("support", email=email, url=i.path, recaptcha=recaptcha)
  29 
  30     def POST(self):
  31         form = web.input()
  32         patron_name = form.get("name", "")
  33         email = form.get("email", "")
  34         topic = form.get("topic", "")
  35         description = form.get("question", "")
  36         url = form.get("url", "")
  37         user = accounts.get_current_user()
  38         useragent = web.ctx.env.get("HTTP_USER_AGENT", "")
  39         if not all([email, topic, description]):
  40             return ""
  41 
  42         hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()
  43         has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)
  44         if has_emailed_recently:
  45             recap = get_recaptcha()
  46             if recap and not recap.validate():
  47                 return render_template(
  48                     "message.html",
  49                     'Recaptcha solution was incorrect',
  50                     (
  51                         'Please <a href="javascript:history.back()">go back</a> and try '
  52                         'again.'
  53                     ),
  54                 )
  55 
  56         default_assignees = config.get("support_default_assignees", {})
  57         if (topic_key := str(topic.replace(" ", "_").lower())) in default_assignees:
  58             assignee = default_assignees.get(topic_key)
  59         else:
  60             assignee = default_assignees.get("default", "openlibrary@archive.org")
  61         stats.increment("ol.support.all")
  62         subject = "Support case *%s*" % topic
  63 
  64         url = web.ctx.home + url
  65         displayname = user and user.get_name() or ""
  66         username = user and user.get_username() or ""
  67 
  68         message = SUPPORT_EMAIL_TEMPLATE % locals()
  69         sendmail(email, assignee, subject, message)
  70 
  71         get_memcache().set(
  72             'contact-POST-%s' % hashed_ip, "true", expires=15 * MINUTE_SECS
  73         )
  74         return render_template("email/case_created", assignee)
  75 
  76 
  77 def sendmail(from_address, to_address, subject, message):
  78     if config.get('dummy_sendmail'):
  79         msg = (
  80             f'To: {to_address}\n'
  81             f'From:{from_address}\n'
  82             f'Subject:{subject}\n'
  83             f'\n{web.safestr(message)}'
  84         )
  85 
  86         logger.info("sending email:\n%s", msg)
  87     else:
  88         web.sendmail(from_address, to_address, subject, message)
  89 
  90 
  91 SUPPORT_EMAIL_TEMPLATE = """
  92 
  93 Description:\n
  94 %(description)s
  95 
  96 A new support case has been filed by %(displayname)s <%(email)s>.
  97 
  98 Topic: %(topic)s
  99 URL: %(url)s
  100 User-Agent: %(useragent)s
  101 OL-username: %(username)s
  102 Patron-name: %(patron_name)s
  103 """
  104 
  105 
  106 def setup():
  107     pass
  108
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/openlibrary/plugins/openlibrary/support.py b/openlibrary/plugins/openlibrary/support.py
  --- a/openlibrary/plugins/openlibrary/support.py
  +++ b/openlibrary/plugins/openlibrary/support.py
  @@ -32,11 +32,12 @@
           patron_name = form.get("name", "")
           email = form.get("email", "")
           topic = form.get("topic", "")
  +        subject_line = form.get('subject', '')
           description = form.get("question", "")
           url = form.get("url", "")
           user = accounts.get_current_user()
           useragent = web.ctx.env.get("HTTP_USER_AGENT", "")
  -        if not all([email, topic, description]):
  +        if not all([email, description]):
               return ""
   
           hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()
  @@ -59,7 +60,7 @@
           else:
               assignee = default_assignees.get("default", "openlibrary@archive.org")
           stats.increment("ol.support.all")
  -        subject = "Support case *%s*" % topic
  +        subject = "Support case *%s*" % self.prepare_subject_line(subject_line)
   
           url = web.ctx.home + url
           displayname = user and user.get_name() or ""
  @@ -73,6 +74,14 @@
           )
           return render_template("email/case_created", assignee)
   
  +    def prepare_subject_line(self, subject, max_length=60):
  +        if not subject:
  +            return '[no subject]'
  +        if len(subject) <= max_length:
  +            return subject
  +
  +        return subject[:max_length]
  +
   
   def sendmail(from_address, to_address, subject, message):
       if config.get('dummy_sendmail'):
  @@ -95,7 +104,7 @@
   
   A new support case has been filed by %(displayname)s <%(email)s>.
   
  -Topic: %(topic)s
  +Subject: %(subject_line)s
   URL: %(url)s
   User-Agent: %(useragent)s
   OL-username: %(username)s
  
verification_info: {"golden_diff": "diff --git a/openlibrary/plugins/openlibrary/support.py b/openlibrary/plugins/openlibrary/support.py\n--- a/openlibrary/plugins/openlibrary/support.py\n+++ b/openlibrary/plugins/openlibrary/support.py\n@@ -32,11 +32,12 @@\n         patron_name = form.get(\"name\", \"\")\n         email = form.get(\"email\", \"\")\n         topic = form.get(\"topic\", \"\")\n+        subject_line = form.get('subject', '')\n         description = form.get(\"question\", \"\")\n         url = form.get(\"url\", \"\")\n         user = accounts.get_current_user()\n         useragent = web.ctx.env.get(\"HTTP_USER_AGENT\", \"\")\n-        if not all([email, topic, description]):\n+        if not all([email, description]):\n             return \"\"\n \n         hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()\n@@ -59,7 +60,7 @@\n         else:\n             assignee = default_assignees.get(\"default\", \"openlibrary@archive.org\")\n         stats.increment(\"ol.support.all\")\n-        subject = \"Support case *%s*\" % topic\n+        subject = \"Support case *%s*\" % self.prepare_subject_line(subject_line)\n \n         url = web.ctx.home + url\n         displayname = user and user.get_name() or \"\"\n@@ -73,6 +74,14 @@\n         )\n         return render_template(\"email/case_created\", assignee)\n \n+    def prepare_subject_line(self, subject, max_length=60):\n+        if not subject:\n+            return '[no subject]'\n+        if len(subject) <= max_length:\n+            return subject\n+\n+        return subject[:max_length]\n+\n \n def sendmail(from_address, to_address, subject, message):\n     if config.get('dummy_sendmail'):\n@@ -95,7 +104,7 @@\n \n A new support case has been filed by %(displayname)s <%(email)s>.\n \n-Topic: %(topic)s\n+Subject: %(subject_line)s\n URL: %(url)s\n User-Agent: %(useragent)s\n OL-username: %(username)s\n", "issue": "Remove fixed subject line from contact form\nThe contact form has a drop down for choosing a topic. When patrons submit this form, the submissions all go to the same inbox. The selected topics are usually incorrect, but also make it more difficult to manage the inbox due to most messages looking the same.\r\n\r\n### Describe the problem that you'd like solved\r\nLet the patron populate the subject line OR auto-populate the subject line from the message.\r\n\r\n### Proposal & Constraints\r\n<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->\r\n\r\n<!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->\r\n\r\n### Additional context\r\n<!-- Add any other context or screenshots about the feature request here. -->\r\n\r\n### Stakeholders\r\n<!-- @ tag stakeholders of this bug -->\r\n\r\n\r\n\n", "before_files": [{"content": "import hashlib\n\nimport web\nimport logging\n\nfrom infogami import config\nfrom infogami.utils import delegate\nfrom infogami.utils.view import render_template\n\nfrom openlibrary import accounts\nfrom openlibrary.core import stats\nfrom openlibrary.core.cache import get_memcache\nfrom openlibrary.plugins.upstream.addbook import get_recaptcha\nfrom openlibrary.utils.dateutil import MINUTE_SECS\n\nlogger = logging.getLogger(\"openlibrary\")\n\n\nclass contact(delegate.page):\n    def GET(self):\n        i = web.input(path=None)\n        user = accounts.get_current_user()\n        email = user and user.email\n\n        hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()\n        has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)\n        recaptcha = has_emailed_recently and get_recaptcha()\n        return render_template(\"support\", email=email, url=i.path, recaptcha=recaptcha)\n\n    def POST(self):\n        form = web.input()\n        patron_name = form.get(\"name\", \"\")\n        email = form.get(\"email\", \"\")\n        topic = form.get(\"topic\", \"\")\n        description = form.get(\"question\", \"\")\n        url = form.get(\"url\", \"\")\n        user = accounts.get_current_user()\n        useragent = web.ctx.env.get(\"HTTP_USER_AGENT\", \"\")\n        if not all([email, topic, description]):\n            return \"\"\n\n        hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()\n        has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)\n        if has_emailed_recently:\n            recap = get_recaptcha()\n            if recap and not recap.validate():\n                return render_template(\n                    \"message.html\",\n                    'Recaptcha solution was incorrect',\n                    (\n                        'Please <a href=\"javascript:history.back()\">go back</a> and try '\n                        'again.'\n                    ),\n                )\n\n        default_assignees = config.get(\"support_default_assignees\", {})\n        if (topic_key := str(topic.replace(\" \", \"_\").lower())) in default_assignees:\n            assignee = default_assignees.get(topic_key)\n        else:\n            assignee = default_assignees.get(\"default\", \"openlibrary@archive.org\")\n        stats.increment(\"ol.support.all\")\n        subject = \"Support case *%s*\" % topic\n\n        url = web.ctx.home + url\n        displayname = user and user.get_name() or \"\"\n        username = user and user.get_username() or \"\"\n\n        message = SUPPORT_EMAIL_TEMPLATE % locals()\n        sendmail(email, assignee, subject, message)\n\n        get_memcache().set(\n            'contact-POST-%s' % hashed_ip, \"true\", expires=15 * MINUTE_SECS\n        )\n        return render_template(\"email/case_created\", assignee)\n\n\ndef sendmail(from_address, to_address, subject, message):\n    if config.get('dummy_sendmail'):\n        msg = (\n            f'To: {to_address}\\n'\n            f'From:{from_address}\\n'\n            f'Subject:{subject}\\n'\n            f'\\n{web.safestr(message)}'\n        )\n\n        logger.info(\"sending email:\\n%s\", msg)\n    else:\n        web.sendmail(from_address, to_address, subject, message)\n\n\nSUPPORT_EMAIL_TEMPLATE = \"\"\"\n\nDescription:\\n\n%(description)s\n\nA new support case has been filed by %(displayname)s <%(email)s>.\n\nTopic: %(topic)s\nURL: %(url)s\nUser-Agent: %(useragent)s\nOL-username: %(username)s\nPatron-name: %(patron_name)s\n\"\"\"\n\n\ndef setup():\n    pass\n", "path": "openlibrary/plugins/openlibrary/support.py"}], "after_files": [{"content": "import hashlib\n\nimport web\nimport logging\n\nfrom infogami import config\nfrom infogami.utils import delegate\nfrom infogami.utils.view import render_template\n\nfrom openlibrary import accounts\nfrom openlibrary.core import stats\nfrom openlibrary.core.cache import get_memcache\nfrom openlibrary.plugins.upstream.addbook import get_recaptcha\nfrom openlibrary.utils.dateutil import MINUTE_SECS\n\nlogger = logging.getLogger(\"openlibrary\")\n\n\nclass contact(delegate.page):\n    def GET(self):\n        i = web.input(path=None)\n        user = accounts.get_current_user()\n        email = user and user.email\n\n        hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()\n        has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)\n        recaptcha = has_emailed_recently and get_recaptcha()\n        return render_template(\"support\", email=email, url=i.path, recaptcha=recaptcha)\n\n    def POST(self):\n        form = web.input()\n        patron_name = form.get(\"name\", \"\")\n        email = form.get(\"email\", \"\")\n        topic = form.get(\"topic\", \"\")\n        subject_line = form.get('subject', '')\n        description = form.get(\"question\", \"\")\n        url = form.get(\"url\", \"\")\n        user = accounts.get_current_user()\n        useragent = web.ctx.env.get(\"HTTP_USER_AGENT\", \"\")\n        if not all([email, description]):\n            return \"\"\n\n        hashed_ip = hashlib.md5(web.ctx.ip.encode('utf-8')).hexdigest()\n        has_emailed_recently = get_memcache().get('contact-POST-%s' % hashed_ip)\n        if has_emailed_recently:\n            recap = get_recaptcha()\n            if recap and not recap.validate():\n                return render_template(\n                    \"message.html\",\n                    'Recaptcha solution was incorrect',\n                    (\n                        'Please <a href=\"javascript:history.back()\">go back</a> and try '\n                        'again.'\n                    ),\n                )\n\n        default_assignees = config.get(\"support_default_assignees\", {})\n        if (topic_key := str(topic.replace(\" \", \"_\").lower())) in default_assignees:\n            assignee = default_assignees.get(topic_key)\n        else:\n            assignee = default_assignees.get(\"default\", \"openlibrary@archive.org\")\n        stats.increment(\"ol.support.all\")\n        subject = \"Support case *%s*\" % self.prepare_subject_line(subject_line)\n\n        url = web.ctx.home + url\n        displayname = user and user.get_name() or \"\"\n        username = user and user.get_username() or \"\"\n\n        message = SUPPORT_EMAIL_TEMPLATE % locals()\n        sendmail(email, assignee, subject, message)\n\n        get_memcache().set(\n            'contact-POST-%s' % hashed_ip, \"true\", expires=15 * MINUTE_SECS\n        )\n        return render_template(\"email/case_created\", assignee)\n\n    def prepare_subject_line(self, subject, max_length=60):\n        if not subject:\n            return '[no subject]'\n        if len(subject) <= max_length:\n            return subject\n\n        return subject[:max_length]\n\n\ndef sendmail(from_address, to_address, subject, message):\n    if config.get('dummy_sendmail'):\n        msg = (\n            f'To: {to_address}\\n'\n            f'From:{from_address}\\n'\n            f'Subject:{subject}\\n'\n            f'\\n{web.safestr(message)}'\n        )\n\n        logger.info(\"sending email:\\n%s\", msg)\n    else:\n        web.sendmail(from_address, to_address, subject, message)\n\n\nSUPPORT_EMAIL_TEMPLATE = \"\"\"\n\nDescription:\\n\n%(description)s\n\nA new support case has been filed by %(displayname)s <%(email)s>.\n\nSubject: %(subject_line)s\nURL: %(url)s\nUser-Agent: %(useragent)s\nOL-username: %(username)s\nPatron-name: %(patron_name)s\n\"\"\"\n\n\ndef setup():\n    pass\n", "path": "openlibrary/plugins/openlibrary/support.py"}]}