We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Redis address parsing is done in init_app
This was added in #1107:

https://github.com/Mailu/Mailu/blob/f3f0c3190be9ab9b53a29c5b0326fc9a4602df46/core/admin/mailu/configuration.py#L11-L12

While, `REDIS_ADDRESS` is now only resolved in `init_app`. (#940). We took care of that in:

https://github.com/Mailu/Mailu/blob/f3f0c3190be9ab9b53a29c5b0326fc9a4602df46/core/admin/mailu/configuration.py#L116-L117

I believe DEFAULT_CONFIG should be like:

https://github.com/Mailu/Mailu/blob/4c25c83419be128fb12591721627a718ec23f69d/core/admin/mailu/configuration.py#L12-L13

We are now in the process of backporting #940 to 1.7. PR #1107 was not backported. Therefore 1.7 will look like the last snippet.

CC @mildred, @kaiyou 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/admin/mailu/configuration.py`
Content:
```
1 import os
2 
3 from socrate import system
4 
5 DEFAULT_CONFIG = {
6     # Specific to the admin UI
7     'DOCKER_SOCKET': 'unix:///var/run/docker.sock',
8     'BABEL_DEFAULT_LOCALE': 'en',
9     'BABEL_DEFAULT_TIMEZONE': 'UTC',
10     'BOOTSTRAP_SERVE_LOCAL': True,
11     'RATELIMIT_STORAGE_URL': 'redis://%s/2' % (os.getenv("REDIS_ADDRESS", "redis")),
12     'QUOTA_STORAGE_URL': 'redis://%s/1' % (os.getenv("REDIS_ADDRESS", "redis")),
13     'DEBUG': False,
14     'DOMAIN_REGISTRATION': False,
15     'TEMPLATES_AUTO_RELOAD': True,
16     # Database settings
17     'DB_FLAVOR': None,
18     'DB_USER': 'mailu',
19     'DB_PW': None,
20     'DB_HOST': 'database',
21     'DB_NAME': 'mailu',
22     'SQLITE_DATABASE_FILE':'data/main.db',
23     'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',
24     'SQLALCHEMY_TRACK_MODIFICATIONS': False,
25     # Statistics management
26     'INSTANCE_ID_PATH': '/data/instance',
27     'STATS_ENDPOINT': '0.{}.stats.mailu.io',
28     # Common configuration variables
29     'SECRET_KEY': 'changeMe',
30     'DOMAIN': 'mailu.io',
31     'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',
32     'POSTMASTER': 'postmaster',
33     'TLS_FLAVOR': 'cert',
34     'AUTH_RATELIMIT': '10/minute;1000/hour',
35     'DISABLE_STATISTICS': False,
36     # Mail settings
37     'DMARC_RUA': None,
38     'DMARC_RUF': None,
39     'WELCOME': False,
40     'WELCOME_SUBJECT': 'Dummy welcome topic',
41     'WELCOME_BODY': 'Dummy welcome body',
42     'DKIM_SELECTOR': 'dkim',
43     'DKIM_PATH': '/dkim/{domain}.{selector}.key',
44     'DEFAULT_QUOTA': 1000000000,
45     # Web settings
46     'SITENAME': 'Mailu',
47     'WEBSITE': 'https://mailu.io',
48     'WEB_ADMIN': '/admin',
49     'WEB_WEBMAIL': '/webmail',
50     'WEBMAIL': 'none',
51     'RECAPTCHA_PUBLIC_KEY': '',
52     'RECAPTCHA_PRIVATE_KEY': '',
53     # Advanced settings
54     'PASSWORD_SCHEME': 'BLF-CRYPT',
55     'LOG_LEVEL': 'WARNING',
56     # Host settings
57     'HOST_IMAP': 'imap',
58     'HOST_LMTP': 'imap:2525',
59     'HOST_POP3': 'imap',
60     'HOST_SMTP': 'smtp',
61     'HOST_AUTHSMTP': 'smtp',
62     'HOST_ADMIN': 'admin',
63     'HOST_ANTISPAM': 'antispam:11334',
64     'HOST_WEBMAIL': 'webmail',
65     'HOST_WEBDAV': 'webdav:5232',
66     'HOST_REDIS': 'redis',
67     'HOST_FRONT': 'front',
68     'SUBNET': '192.168.203.0/24',
69     'POD_ADDRESS_RANGE': None
70 }
71 
72 class ConfigManager(dict):
73     """ Naive configuration manager that uses environment only
74     """
75 
76     DB_TEMPLATES = {
77         'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',
78         'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',
79         'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'
80     }
81 
82     HOSTS = ('IMAP', 'POP3', 'AUTHSMTP', 'SMTP', 'REDIS')
83     OPTIONAL_HOSTS = ('WEBMAIL', 'ANTISPAM')
84 
85     def __init__(self):
86         self.config = dict()
87 
88     def resolve_host(self):
89         optional = [item for item in self.OPTIONAL_HOSTS if item in self.config and self.config[item] != "none"]
90         for item in list(self.HOSTS) + optional:
91             host = 'HOST_' + item
92             address = item + '_ADDRESS'
93             self.config[address] = system.resolve_address(self.config[host])
94 
95     def __coerce_value(self, value):
96         if isinstance(value, str) and value.lower() in ('true','yes'):
97             return True
98         elif isinstance(value, str) and value.lower() in ('false', 'no'):
99             return False
100         return value
101 
102     def init_app(self, app):
103         self.config.update(app.config)
104         # get environment variables
105         self.config.update({
106             key: self.__coerce_value(os.environ.get(key, value))
107             for key, value in DEFAULT_CONFIG.items()
108         })
109         self.resolve_host()
110 
111         # automatically set the sqlalchemy string
112         if self.config['DB_FLAVOR']:
113             template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]
114             self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)
115 
116         self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])
117         self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])
118         # update the app config itself
119         app.config = self
120 
121     def setdefault(self, key, value):
122         if key not in self.config:
123             self.config[key] = value
124         return self.config[key]
125 
126     def get(self, *args):
127         return self.config.get(*args)
128 
129     def keys(self):
130         return self.config.keys()
131 
132     def __getitem__(self, key):
133         return self.config.get(key)
134 
135     def __setitem__(self, key, value):
136         self.config[key] = value
137 
138     def __contains__(self, key):
139         return key in self.config
140
```
--- 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/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py
--- a/core/admin/mailu/configuration.py
+++ b/core/admin/mailu/configuration.py
@@ -8,8 +8,8 @@
     'BABEL_DEFAULT_LOCALE': 'en',
     'BABEL_DEFAULT_TIMEZONE': 'UTC',
     'BOOTSTRAP_SERVE_LOCAL': True,
-    'RATELIMIT_STORAGE_URL': 'redis://%s/2' % (os.getenv("REDIS_ADDRESS", "redis")),
-    'QUOTA_STORAGE_URL': 'redis://%s/1' % (os.getenv("REDIS_ADDRESS", "redis")),
+    'RATELIMIT_STORAGE_URL': '',
+    'QUOTA_STORAGE_URL': '',
     'DEBUG': False,
     'DOMAIN_REGISTRATION': False,
     'TEMPLATES_AUTO_RELOAD': True,

{"golden_diff": "diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py\n--- a/core/admin/mailu/configuration.py\n+++ b/core/admin/mailu/configuration.py\n@@ -8,8 +8,8 @@\n     'BABEL_DEFAULT_LOCALE': 'en',\n     'BABEL_DEFAULT_TIMEZONE': 'UTC',\n     'BOOTSTRAP_SERVE_LOCAL': True,\n-    'RATELIMIT_STORAGE_URL': 'redis://%s/2' % (os.getenv(\"REDIS_ADDRESS\", \"redis\")),\n-    'QUOTA_STORAGE_URL': 'redis://%s/1' % (os.getenv(\"REDIS_ADDRESS\", \"redis\")),\n+    'RATELIMIT_STORAGE_URL': '',\n+    'QUOTA_STORAGE_URL': '',\n     'DEBUG': False,\n     'DOMAIN_REGISTRATION': False,\n     'TEMPLATES_AUTO_RELOAD': True,\n", "issue": "Redis address parsing is done in init_app\nThis was added in #1107:\r\n\r\nhttps://github.com/Mailu/Mailu/blob/f3f0c3190be9ab9b53a29c5b0326fc9a4602df46/core/admin/mailu/configuration.py#L11-L12\r\n\r\nWhile, `REDIS_ADDRESS` is now only resolved in `init_app`. (#940). We took care of that in:\r\n\r\nhttps://github.com/Mailu/Mailu/blob/f3f0c3190be9ab9b53a29c5b0326fc9a4602df46/core/admin/mailu/configuration.py#L116-L117\r\n\r\nI believe DEFAULT_CONFIG should be like:\r\n\r\nhttps://github.com/Mailu/Mailu/blob/4c25c83419be128fb12591721627a718ec23f69d/core/admin/mailu/configuration.py#L12-L13\r\n\r\nWe are now in the process of backporting #940 to 1.7. PR #1107 was not backported. Therefore 1.7 will look like the last snippet.\r\n\r\nCC @mildred, @kaiyou \n", "before_files": [{"content": "import os\n\nfrom socrate import system\n\nDEFAULT_CONFIG = {\n    # Specific to the admin UI\n    'DOCKER_SOCKET': 'unix:///var/run/docker.sock',\n    'BABEL_DEFAULT_LOCALE': 'en',\n    'BABEL_DEFAULT_TIMEZONE': 'UTC',\n    'BOOTSTRAP_SERVE_LOCAL': True,\n    'RATELIMIT_STORAGE_URL': 'redis://%s/2' % (os.getenv(\"REDIS_ADDRESS\", \"redis\")),\n    'QUOTA_STORAGE_URL': 'redis://%s/1' % (os.getenv(\"REDIS_ADDRESS\", \"redis\")),\n    'DEBUG': False,\n    'DOMAIN_REGISTRATION': False,\n    'TEMPLATES_AUTO_RELOAD': True,\n    # Database settings\n    'DB_FLAVOR': None,\n    'DB_USER': 'mailu',\n    'DB_PW': None,\n    'DB_HOST': 'database',\n    'DB_NAME': 'mailu',\n    'SQLITE_DATABASE_FILE':'data/main.db',\n    'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',\n    'SQLALCHEMY_TRACK_MODIFICATIONS': False,\n    # Statistics management\n    'INSTANCE_ID_PATH': '/data/instance',\n    'STATS_ENDPOINT': '0.{}.stats.mailu.io',\n    # Common configuration variables\n    'SECRET_KEY': 'changeMe',\n    'DOMAIN': 'mailu.io',\n    'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',\n    'POSTMASTER': 'postmaster',\n    'TLS_FLAVOR': 'cert',\n    'AUTH_RATELIMIT': '10/minute;1000/hour',\n    'DISABLE_STATISTICS': False,\n    # Mail settings\n    'DMARC_RUA': None,\n    'DMARC_RUF': None,\n    'WELCOME': False,\n    'WELCOME_SUBJECT': 'Dummy welcome topic',\n    'WELCOME_BODY': 'Dummy welcome body',\n    'DKIM_SELECTOR': 'dkim',\n    'DKIM_PATH': '/dkim/{domain}.{selector}.key',\n    'DEFAULT_QUOTA': 1000000000,\n    # Web settings\n    'SITENAME': 'Mailu',\n    'WEBSITE': 'https://mailu.io',\n    'WEB_ADMIN': '/admin',\n    'WEB_WEBMAIL': '/webmail',\n    'WEBMAIL': 'none',\n    'RECAPTCHA_PUBLIC_KEY': '',\n    'RECAPTCHA_PRIVATE_KEY': '',\n    # Advanced settings\n    'PASSWORD_SCHEME': 'BLF-CRYPT',\n    'LOG_LEVEL': 'WARNING',\n    # Host settings\n    'HOST_IMAP': 'imap',\n    'HOST_LMTP': 'imap:2525',\n    'HOST_POP3': 'imap',\n    'HOST_SMTP': 'smtp',\n    'HOST_AUTHSMTP': 'smtp',\n    'HOST_ADMIN': 'admin',\n    'HOST_ANTISPAM': 'antispam:11334',\n    'HOST_WEBMAIL': 'webmail',\n    'HOST_WEBDAV': 'webdav:5232',\n    'HOST_REDIS': 'redis',\n    'HOST_FRONT': 'front',\n    'SUBNET': '192.168.203.0/24',\n    'POD_ADDRESS_RANGE': None\n}\n\nclass ConfigManager(dict):\n    \"\"\" Naive configuration manager that uses environment only\n    \"\"\"\n\n    DB_TEMPLATES = {\n        'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',\n        'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',\n        'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'\n    }\n\n    HOSTS = ('IMAP', 'POP3', 'AUTHSMTP', 'SMTP', 'REDIS')\n    OPTIONAL_HOSTS = ('WEBMAIL', 'ANTISPAM')\n\n    def __init__(self):\n        self.config = dict()\n\n    def resolve_host(self):\n        optional = [item for item in self.OPTIONAL_HOSTS if item in self.config and self.config[item] != \"none\"]\n        for item in list(self.HOSTS) + optional:\n            host = 'HOST_' + item\n            address = item + '_ADDRESS'\n            self.config[address] = system.resolve_address(self.config[host])\n\n    def __coerce_value(self, value):\n        if isinstance(value, str) and value.lower() in ('true','yes'):\n            return True\n        elif isinstance(value, str) and value.lower() in ('false', 'no'):\n            return False\n        return value\n\n    def init_app(self, app):\n        self.config.update(app.config)\n        # get environment variables\n        self.config.update({\n            key: self.__coerce_value(os.environ.get(key, value))\n            for key, value in DEFAULT_CONFIG.items()\n        })\n        self.resolve_host()\n\n        # automatically set the sqlalchemy string\n        if self.config['DB_FLAVOR']:\n            template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]\n            self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)\n\n        self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])\n        self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])\n        # update the app config itself\n        app.config = self\n\n    def setdefault(self, key, value):\n        if key not in self.config:\n            self.config[key] = value\n        return self.config[key]\n\n    def get(self, *args):\n        return self.config.get(*args)\n\n    def keys(self):\n        return self.config.keys()\n\n    def __getitem__(self, key):\n        return self.config.get(key)\n\n    def __setitem__(self, key, value):\n        self.config[key] = value\n\n    def __contains__(self, key):\n        return key in self.config\n", "path": "core/admin/mailu/configuration.py"}], "after_files": [{"content": "import os\n\nfrom socrate import system\n\nDEFAULT_CONFIG = {\n    # Specific to the admin UI\n    'DOCKER_SOCKET': 'unix:///var/run/docker.sock',\n    'BABEL_DEFAULT_LOCALE': 'en',\n    'BABEL_DEFAULT_TIMEZONE': 'UTC',\n    'BOOTSTRAP_SERVE_LOCAL': True,\n    'RATELIMIT_STORAGE_URL': '',\n    'QUOTA_STORAGE_URL': '',\n    'DEBUG': False,\n    'DOMAIN_REGISTRATION': False,\n    'TEMPLATES_AUTO_RELOAD': True,\n    # Database settings\n    'DB_FLAVOR': None,\n    'DB_USER': 'mailu',\n    'DB_PW': None,\n    'DB_HOST': 'database',\n    'DB_NAME': 'mailu',\n    'SQLITE_DATABASE_FILE':'data/main.db',\n    'SQLALCHEMY_DATABASE_URI': 'sqlite:////data/main.db',\n    'SQLALCHEMY_TRACK_MODIFICATIONS': False,\n    # Statistics management\n    'INSTANCE_ID_PATH': '/data/instance',\n    'STATS_ENDPOINT': '0.{}.stats.mailu.io',\n    # Common configuration variables\n    'SECRET_KEY': 'changeMe',\n    'DOMAIN': 'mailu.io',\n    'HOSTNAMES': 'mail.mailu.io,alternative.mailu.io,yetanother.mailu.io',\n    'POSTMASTER': 'postmaster',\n    'TLS_FLAVOR': 'cert',\n    'AUTH_RATELIMIT': '10/minute;1000/hour',\n    'DISABLE_STATISTICS': False,\n    # Mail settings\n    'DMARC_RUA': None,\n    'DMARC_RUF': None,\n    'WELCOME': False,\n    'WELCOME_SUBJECT': 'Dummy welcome topic',\n    'WELCOME_BODY': 'Dummy welcome body',\n    'DKIM_SELECTOR': 'dkim',\n    'DKIM_PATH': '/dkim/{domain}.{selector}.key',\n    'DEFAULT_QUOTA': 1000000000,\n    # Web settings\n    'SITENAME': 'Mailu',\n    'WEBSITE': 'https://mailu.io',\n    'WEB_ADMIN': '/admin',\n    'WEB_WEBMAIL': '/webmail',\n    'WEBMAIL': 'none',\n    'RECAPTCHA_PUBLIC_KEY': '',\n    'RECAPTCHA_PRIVATE_KEY': '',\n    # Advanced settings\n    'PASSWORD_SCHEME': 'BLF-CRYPT',\n    'LOG_LEVEL': 'WARNING',\n    # Host settings\n    'HOST_IMAP': 'imap',\n    'HOST_LMTP': 'imap:2525',\n    'HOST_POP3': 'imap',\n    'HOST_SMTP': 'smtp',\n    'HOST_AUTHSMTP': 'smtp',\n    'HOST_ADMIN': 'admin',\n    'HOST_ANTISPAM': 'antispam:11334',\n    'HOST_WEBMAIL': 'webmail',\n    'HOST_WEBDAV': 'webdav:5232',\n    'HOST_REDIS': 'redis',\n    'HOST_FRONT': 'front',\n    'SUBNET': '192.168.203.0/24',\n    'POD_ADDRESS_RANGE': None\n}\n\nclass ConfigManager(dict):\n    \"\"\" Naive configuration manager that uses environment only\n    \"\"\"\n\n    DB_TEMPLATES = {\n        'sqlite': 'sqlite:////{SQLITE_DATABASE_FILE}',\n        'postgresql': 'postgresql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}',\n        'mysql': 'mysql://{DB_USER}:{DB_PW}@{DB_HOST}/{DB_NAME}'\n    }\n\n    HOSTS = ('IMAP', 'POP3', 'AUTHSMTP', 'SMTP', 'REDIS')\n    OPTIONAL_HOSTS = ('WEBMAIL', 'ANTISPAM')\n\n    def __init__(self):\n        self.config = dict()\n\n    def resolve_host(self):\n        optional = [item for item in self.OPTIONAL_HOSTS if item in self.config and self.config[item] != \"none\"]\n        for item in list(self.HOSTS) + optional:\n            host = 'HOST_' + item\n            address = item + '_ADDRESS'\n            self.config[address] = system.resolve_address(self.config[host])\n\n    def __coerce_value(self, value):\n        if isinstance(value, str) and value.lower() in ('true','yes'):\n            return True\n        elif isinstance(value, str) and value.lower() in ('false', 'no'):\n            return False\n        return value\n\n    def init_app(self, app):\n        self.config.update(app.config)\n        # get environment variables\n        self.config.update({\n            key: self.__coerce_value(os.environ.get(key, value))\n            for key, value in DEFAULT_CONFIG.items()\n        })\n        self.resolve_host()\n\n        # automatically set the sqlalchemy string\n        if self.config['DB_FLAVOR']:\n            template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]\n            self.config['SQLALCHEMY_DATABASE_URI'] = template.format(**self.config)\n\n        self.config['RATELIMIT_STORAGE_URL'] = 'redis://{0}/2'.format(self.config['REDIS_ADDRESS'])\n        self.config['QUOTA_STORAGE_URL'] = 'redis://{0}/1'.format(self.config['REDIS_ADDRESS'])\n        # update the app config itself\n        app.config = self\n\n    def setdefault(self, key, value):\n        if key not in self.config:\n            self.config[key] = value\n        return self.config[key]\n\n    def get(self, *args):\n        return self.config.get(*args)\n\n    def keys(self):\n        return self.config.keys()\n\n    def __getitem__(self, key):\n        return self.config.get(key)\n\n    def __setitem__(self, key, value):\n        self.config[key] = value\n\n    def __contains__(self, key):\n        return key in self.config\n", "path": "core/admin/mailu/configuration.py"}]}