prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Make smtp_tls_policy_maps easily configurable
  Hi Team,
  
  It will be great to have following options configurable from mailu.env as they are required in many cases
  when SMTP RELAY from an ISP is in use:
  smtp_tls_security_level
  smtp_tls_wrappermode
  (PR is following)
  
  </issue>
  <code>
  [start of core/postfix/start.py]
  1 #!/usr/bin/python3
  2 
  3 import os
  4 import glob
  5 import shutil
  6 import multiprocessing
  7 import logging as log
  8 import sys
  9 
  10 from podop   import run_server
  11 from pwd import getpwnam
  12 from socrate import system, conf
  13 
  14 log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING"))
  15 
  16 def start_podop():
  17     os.setuid(getpwnam('postfix').pw_uid)
  18     os.mkdir('/dev/shm/postfix',mode=0o700)
  19     url = "http://" + os.environ["ADMIN_ADDRESS"] + "/internal/postfix/"
  20     # TODO: Remove verbosity setting from Podop?
  21     run_server(0, "postfix", "/tmp/podop.socket", [
  22 		("transport", "url", url + "transport/§"),
  23 		("alias", "url", url + "alias/§"),
  24 		("domain", "url", url + "domain/§"),
  25         ("mailbox", "url", url + "mailbox/§"),
  26         ("recipientmap", "url", url + "recipient/map/§"),
  27         ("sendermap", "url", url + "sender/map/§"),
  28         ("senderaccess", "url", url + "sender/access/§"),
  29         ("senderlogin", "url", url + "sender/login/§"),
  30         ("senderrate", "url", url + "sender/rate/§")
  31     ])
  32 
  33 def is_valid_postconf_line(line):
  34     return not line.startswith("#") \
  35             and not line == ''
  36 
  37 # Actual startup script
  38 os.environ["FRONT_ADDRESS"] = system.get_host_address_from_environment("FRONT", "front")
  39 os.environ["ADMIN_ADDRESS"] = system.get_host_address_from_environment("ADMIN", "admin")
  40 os.environ["ANTISPAM_MILTER_ADDRESS"] = system.get_host_address_from_environment("ANTISPAM_MILTER", "antispam:11332")
  41 os.environ["LMTP_ADDRESS"] = system.get_host_address_from_environment("LMTP", "imap:2525")
  42 os.environ["OUTCLEAN"] = os.environ["HOSTNAMES"].split(",")[0]
  43 try:
  44     _to_lookup = os.environ["OUTCLEAN"]
  45     # Ensure we lookup a FQDN: @see #1884
  46     if not _to_lookup.endswith('.'):
  47         _to_lookup += '.'
  48     os.environ["OUTCLEAN_ADDRESS"] = system.resolve_hostname(_to_lookup)
  49 except:
  50     os.environ["OUTCLEAN_ADDRESS"] = "10.10.10.10"
  51 
  52 for postfix_file in glob.glob("/conf/*.cf"):
  53     conf.jinja(postfix_file, os.environ, os.path.join("/etc/postfix", os.path.basename(postfix_file)))
  54 
  55 if os.path.exists("/overrides/postfix.cf"):
  56     for line in open("/overrides/postfix.cf").read().strip().split("\n"):
  57         if is_valid_postconf_line(line):
  58             os.system('postconf -e "{}"'.format(line))
  59 
  60 if os.path.exists("/overrides/postfix.master"):
  61     for line in open("/overrides/postfix.master").read().strip().split("\n"):
  62         if is_valid_postconf_line(line):
  63             os.system('postconf -Me "{}"'.format(line))
  64 
  65 for map_file in glob.glob("/overrides/*.map"):
  66     destination = os.path.join("/etc/postfix", os.path.basename(map_file))
  67     shutil.copyfile(map_file, destination)
  68     os.system("postmap {}".format(destination))
  69     os.remove(destination)
  70 
  71 if "RELAYUSER" in os.environ:
  72     path = "/etc/postfix/sasl_passwd"
  73     conf.jinja("/conf/sasl_passwd", os.environ, path)
  74     os.system("postmap {}".format(path))
  75 
  76 # Run Podop and Postfix
  77 multiprocessing.Process(target=start_podop).start()
  78 os.system("/usr/libexec/postfix/post-install meta_directory=/etc/postfix create-missing")
  79 # Before starting postfix, we need to check permissions on /queue
  80 # in the event that postfix,postdrop id have changed
  81 os.system("postfix set-permissions")
  82 os.system("postfix start-fg")
  83
  [end of core/postfix/start.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/core/postfix/start.py b/core/postfix/start.py
  --- a/core/postfix/start.py
  +++ b/core/postfix/start.py
  @@ -68,6 +68,12 @@
       os.system("postmap {}".format(destination))
       os.remove(destination)
   
  +if not os.path.exists("/etc/postfix/tls_policy.map.db"):
  +    with open("/etc/postfix/tls_policy.map", "w") as f:
  +        for domain in ['gmail.com', 'yahoo.com', 'hotmail.com', 'aol.com', 'outlook.com', 'comcast.net', 'icloud.com', 'msn.com', 'hotmail.co.uk', 'live.com', 'yahoo.co.in', 'me.com', 'mail.ru', 'cox.net', 'yahoo.co.uk', 'verizon.net', 'ymail.com', 'hotmail.it', 'kw.com', 'yahoo.com.tw', 'mac.com', 'live.se', 'live.nl', 'yahoo.com.br', 'googlemail.com', 'libero.it', 'web.de', 'allstate.com', 'btinternet.com', 'online.no', 'yahoo.com.au', 'live.dk', 'earthlink.net', 'yahoo.fr', 'yahoo.it', 'gmx.de', 'hotmail.fr', 'shawinc.com', 'yahoo.de', 'moe.edu.sg', 'naver.com', 'bigpond.com', 'statefarm.com', 'remax.net', 'rocketmail.com', 'live.no', 'yahoo.ca', 'bigpond.net.au', 'hotmail.se', 'gmx.at', 'live.co.uk', 'mail.com', 'yahoo.in', 'yandex.ru', 'qq.com', 'charter.net', 'indeedemail.com', 'alice.it', 'hotmail.de', 'bluewin.ch', 'optonline.net', 'wp.pl', 'yahoo.es', 'hotmail.no', 'pindotmedia.com', 'orange.fr', 'live.it', 'yahoo.co.id', 'yahoo.no', 'hotmail.es', 'morganstanley.com', 'wellsfargo.com', 'wanadoo.fr', 'facebook.com', 'yahoo.se', 'fema.dhs.gov', 'rogers.com', 'yahoo.com.hk', 'live.com.au', 'nic.in', 'nab.com.au', 'ubs.com', 'shaw.ca', 'umich.edu', 'westpac.com.au', 'yahoo.com.mx', 'yahoo.com.sg', 'farmersagent.com', 'yahoo.dk', 'dhs.gov']:
  +            f.write(f'{domain}\tsecure\n')
  +    os.system("postmap /etc/postfix/tls_policy.map")
  +
   if "RELAYUSER" in os.environ:
       path = "/etc/postfix/sasl_passwd"
       conf.jinja("/conf/sasl_passwd", os.environ, path)
  
verification_info: {"golden_diff": "diff --git a/core/postfix/start.py b/core/postfix/start.py\n--- a/core/postfix/start.py\n+++ b/core/postfix/start.py\n@@ -68,6 +68,12 @@\n     os.system(\"postmap {}\".format(destination))\n     os.remove(destination)\n \n+if not os.path.exists(\"/etc/postfix/tls_policy.map.db\"):\n+    with open(\"/etc/postfix/tls_policy.map\", \"w\") as f:\n+        for domain in ['gmail.com', 'yahoo.com', 'hotmail.com', 'aol.com', 'outlook.com', 'comcast.net', 'icloud.com', 'msn.com', 'hotmail.co.uk', 'live.com', 'yahoo.co.in', 'me.com', 'mail.ru', 'cox.net', 'yahoo.co.uk', 'verizon.net', 'ymail.com', 'hotmail.it', 'kw.com', 'yahoo.com.tw', 'mac.com', 'live.se', 'live.nl', 'yahoo.com.br', 'googlemail.com', 'libero.it', 'web.de', 'allstate.com', 'btinternet.com', 'online.no', 'yahoo.com.au', 'live.dk', 'earthlink.net', 'yahoo.fr', 'yahoo.it', 'gmx.de', 'hotmail.fr', 'shawinc.com', 'yahoo.de', 'moe.edu.sg', 'naver.com', 'bigpond.com', 'statefarm.com', 'remax.net', 'rocketmail.com', 'live.no', 'yahoo.ca', 'bigpond.net.au', 'hotmail.se', 'gmx.at', 'live.co.uk', 'mail.com', 'yahoo.in', 'yandex.ru', 'qq.com', 'charter.net', 'indeedemail.com', 'alice.it', 'hotmail.de', 'bluewin.ch', 'optonline.net', 'wp.pl', 'yahoo.es', 'hotmail.no', 'pindotmedia.com', 'orange.fr', 'live.it', 'yahoo.co.id', 'yahoo.no', 'hotmail.es', 'morganstanley.com', 'wellsfargo.com', 'wanadoo.fr', 'facebook.com', 'yahoo.se', 'fema.dhs.gov', 'rogers.com', 'yahoo.com.hk', 'live.com.au', 'nic.in', 'nab.com.au', 'ubs.com', 'shaw.ca', 'umich.edu', 'westpac.com.au', 'yahoo.com.mx', 'yahoo.com.sg', 'farmersagent.com', 'yahoo.dk', 'dhs.gov']:\n+            f.write(f'{domain}\\tsecure\\n')\n+    os.system(\"postmap /etc/postfix/tls_policy.map\")\n+\n if \"RELAYUSER\" in os.environ:\n     path = \"/etc/postfix/sasl_passwd\"\n     conf.jinja(\"/conf/sasl_passwd\", os.environ, path)\n", "issue": "Make smtp_tls_policy_maps easily configurable\nHi Team,\r\n\r\nIt will be great to have following options configurable from mailu.env as they are required in many cases\r\nwhen SMTP RELAY from an ISP is in use:\r\nsmtp_tls_security_level\r\nsmtp_tls_wrappermode\r\n(PR is following)\n", "before_files": [{"content": "#!/usr/bin/python3\n\nimport os\nimport glob\nimport shutil\nimport multiprocessing\nimport logging as log\nimport sys\n\nfrom podop   import run_server\nfrom pwd import getpwnam\nfrom socrate import system, conf\n\nlog.basicConfig(stream=sys.stderr, level=os.environ.get(\"LOG_LEVEL\", \"WARNING\"))\n\ndef start_podop():\n    os.setuid(getpwnam('postfix').pw_uid)\n    os.mkdir('/dev/shm/postfix',mode=0o700)\n    url = \"http://\" + os.environ[\"ADMIN_ADDRESS\"] + \"/internal/postfix/\"\n    # TODO: Remove verbosity setting from Podop?\n    run_server(0, \"postfix\", \"/tmp/podop.socket\", [\n\t\t(\"transport\", \"url\", url + \"transport/\u00a7\"),\n\t\t(\"alias\", \"url\", url + \"alias/\u00a7\"),\n\t\t(\"domain\", \"url\", url + \"domain/\u00a7\"),\n        (\"mailbox\", \"url\", url + \"mailbox/\u00a7\"),\n        (\"recipientmap\", \"url\", url + \"recipient/map/\u00a7\"),\n        (\"sendermap\", \"url\", url + \"sender/map/\u00a7\"),\n        (\"senderaccess\", \"url\", url + \"sender/access/\u00a7\"),\n        (\"senderlogin\", \"url\", url + \"sender/login/\u00a7\"),\n        (\"senderrate\", \"url\", url + \"sender/rate/\u00a7\")\n    ])\n\ndef is_valid_postconf_line(line):\n    return not line.startswith(\"#\") \\\n            and not line == ''\n\n# Actual startup script\nos.environ[\"FRONT_ADDRESS\"] = system.get_host_address_from_environment(\"FRONT\", \"front\")\nos.environ[\"ADMIN_ADDRESS\"] = system.get_host_address_from_environment(\"ADMIN\", \"admin\")\nos.environ[\"ANTISPAM_MILTER_ADDRESS\"] = system.get_host_address_from_environment(\"ANTISPAM_MILTER\", \"antispam:11332\")\nos.environ[\"LMTP_ADDRESS\"] = system.get_host_address_from_environment(\"LMTP\", \"imap:2525\")\nos.environ[\"OUTCLEAN\"] = os.environ[\"HOSTNAMES\"].split(\",\")[0]\ntry:\n    _to_lookup = os.environ[\"OUTCLEAN\"]\n    # Ensure we lookup a FQDN: @see #1884\n    if not _to_lookup.endswith('.'):\n        _to_lookup += '.'\n    os.environ[\"OUTCLEAN_ADDRESS\"] = system.resolve_hostname(_to_lookup)\nexcept:\n    os.environ[\"OUTCLEAN_ADDRESS\"] = \"10.10.10.10\"\n\nfor postfix_file in glob.glob(\"/conf/*.cf\"):\n    conf.jinja(postfix_file, os.environ, os.path.join(\"/etc/postfix\", os.path.basename(postfix_file)))\n\nif os.path.exists(\"/overrides/postfix.cf\"):\n    for line in open(\"/overrides/postfix.cf\").read().strip().split(\"\\n\"):\n        if is_valid_postconf_line(line):\n            os.system('postconf -e \"{}\"'.format(line))\n\nif os.path.exists(\"/overrides/postfix.master\"):\n    for line in open(\"/overrides/postfix.master\").read().strip().split(\"\\n\"):\n        if is_valid_postconf_line(line):\n            os.system('postconf -Me \"{}\"'.format(line))\n\nfor map_file in glob.glob(\"/overrides/*.map\"):\n    destination = os.path.join(\"/etc/postfix\", os.path.basename(map_file))\n    shutil.copyfile(map_file, destination)\n    os.system(\"postmap {}\".format(destination))\n    os.remove(destination)\n\nif \"RELAYUSER\" in os.environ:\n    path = \"/etc/postfix/sasl_passwd\"\n    conf.jinja(\"/conf/sasl_passwd\", os.environ, path)\n    os.system(\"postmap {}\".format(path))\n\n# Run Podop and Postfix\nmultiprocessing.Process(target=start_podop).start()\nos.system(\"/usr/libexec/postfix/post-install meta_directory=/etc/postfix create-missing\")\n# Before starting postfix, we need to check permissions on /queue\n# in the event that postfix,postdrop id have changed\nos.system(\"postfix set-permissions\")\nos.system(\"postfix start-fg\")\n", "path": "core/postfix/start.py"}]}