We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
MAIL FROM: does-not-exist@[X.X.X.X] results in an admin exeption stacktrace
If a client (read: malicious attacker) connects to Postfix and uses an IP address within brackets instead of a domain name for the sender, e.g.:

```
$ telnet mail.example.com 25

Connected to example.com
Escape character is '^]'.
220 mail.example.com ESMTP ready
EHLO dummy.example.com
250-mail.example.com
250 STARTTLS
MAIL FROM: does-not-exist@[116.203.165.200]
250 2.0.0 OK
RCPT TO: some-user@example.com
451 4.3.0 <does-not-exist@[116.203.165.200]>: Temporary lookup failure
```

we see the following stracktrace in the admin container:

```
[2019-07-27 14:26:27,015] ERROR in app: Exception on /internal/postfix/domain/[116.203.165.200] [GET]
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 271, in alabel
    ulabel(label)
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 307, in ulabel
    check_label(label)
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 261, in check_label
    raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
idna.core.InvalidCodepoint: Codepoint U+005B at position 1 of '[116' not allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1127, in _execute_context
    context = constructor(dialect, self, conn, *args)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 669, in _init_compiled
    param.append(processors[key](compiled_params[key]))
  File "/usr/lib/python3.7/site-packages/sqlalchemy/sql/type_api.py", line 1182, in process
    return process_param(value, dialect)
  File "/app/mailu/models.py", line 30, in process_bind_param
    return idna.encode(value).decode("ascii").lower()
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 361, in encode
    s = alabel(label)
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 273, in alabel
    raise IDNAError('The label {0} is not a valid A-label'.format(label))
idna.core.IDNAError: The label b'[116' is not a valid A-label

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/mailu/internal/views/postfix.py", line 9, in postfix_mailbox_domain
    domain = models.Domain.query.get(domain_name) or \
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 924, in get
    ident, loading.load_on_pk_identity)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 1007, in _get_impl
    return db_load_fn(self, primary_key_identity)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/loading.py", line 250, in load_on_pk_identity
    return q.one()
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2954, in one
    ret = self.one_or_none()
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2924, in one_or_none
    ret = list(self)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 2995, in __iter__
    return self._execute_and_instances(context)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3018, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 948, in execute
    return meth(self, multiparams, params)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1132, in _execute_context
    None, None)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception
    exc_info
  File "/usr/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 248, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1127, in _execute_context
    context = constructor(dialect, self, conn, *args)
  File "/usr/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 669, in _init_compiled
    param.append(processors[key](compiled_params[key]))
  File "/usr/lib/python3.7/site-packages/sqlalchemy/sql/type_api.py", line 1182, in process
    return process_param(value, dialect)
  File "/app/mailu/models.py", line 30, in process_bind_param
    return idna.encode(value).decode("ascii").lower()
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 361, in encode
    s = alabel(label)
  File "/usr/lib/python3.7/site-packages/idna/core.py", line 273, in alabel
    raise IDNAError('The label {0} is not a valid A-label'.format(label))
sqlalchemy.exc.StatementError: (idna.core.IDNAError) The label b'[116' is not a valid A-label [SQL: 'SELECT domain.created_at AS domain_created_at, domain.updated_at AS domain_updated_at, domain.comment AS domain_comment, domain.name AS domain_name, domain.max_users AS domain_max_users, domain.max_aliases AS domain_max_aliases, domain.max_quota_bytes AS domain_max_quota_bytes, domain.signup_enabled AS domain_signup_enabled \nFROM domain \nWHERE domain.name = ?'] [parameters: [{'%(140312238936248 param)s': '[116.203.165.200]'}]]
10.36.0.0 - - [27/Jul/2019:14:26:27 +0000] "GET /internal/postfix/domain/%5B116.203.165.200%5D HTTP/1.1" 500 291 "-" "Python/3.7 aiohttp/3.5.4"
10.44.0.0 - - [27/Jul/2019:14:26:31 +0000] "GET /internal/auth/email HTTP/1.0" 200 0 "-" "-"
```

NOTE: the lookup is cached I think and you need to use another IP address to reproduce the error multiple times.

I think we're missing some validation rules, because trying a similar (invalid) MAIL FROM with an IP (but without brackets) is handled properly:

```
telnet mail.example.com 25
Trying ...
Connected to example.com.
Escape character is '^]'.
220 mail.example.com ESMTP ready
EHLO dummy.example.com
250-mail.example.com
250 STARTTLS
MAIL FROM: does-not-exist@192.168.1.1
250 2.0.0 OK
RCPT TO: some-user@example.com
501 5.1.7 Bad sender address syntax
Connection closed by foreign host.
```

--- 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/internal/views/postfix.py`
Content:
```
1 from mailu import models
2 from mailu.internal import internal
3 
4 import flask
5 
6 
7 @internal.route("/postfix/domain/<domain_name>")
8 def postfix_mailbox_domain(domain_name):
9     domain = models.Domain.query.get(domain_name) or \
10              models.Alternative.query.get(domain_name) or \
11              flask.abort(404)
12     return flask.jsonify(domain.name)
13 
14 
15 @internal.route("/postfix/mailbox/<path:email>")
16 def postfix_mailbox_map(email):
17     user = models.User.query.get(email) or flask.abort(404)
18     return flask.jsonify(user.email)
19 
20 
21 @internal.route("/postfix/alias/<path:alias>")
22 def postfix_alias_map(alias):
23     localpart, domain_name = models.Email.resolve_domain(alias)
24     if localpart is None:
25         return flask.jsonify(domain_name)
26     destination = models.Email.resolve_destination(localpart, domain_name)
27     return flask.jsonify(",".join(destination)) if destination else flask.abort(404)
28 
29 
30 @internal.route("/postfix/transport/<path:email>")
31 def postfix_transport(email):
32     if email == '*':
33         return flask.abort(404)
34     localpart, domain_name = models.Email.resolve_domain(email)
35     relay = models.Relay.query.get(domain_name) or flask.abort(404)
36     return flask.jsonify("smtp:[{}]".format(relay.smtp))
37 
38 
39 @internal.route("/postfix/sender/login/<path:sender>")
40 def postfix_sender_login(sender):
41     localpart, domain_name = models.Email.resolve_domain(sender)
42     if localpart is None:
43         return flask.abort(404)
44     destination = models.Email.resolve_destination(localpart, domain_name, True)
45     return flask.jsonify(",".join(destination)) if destination else flask.abort(404)
46 
47 
48 @internal.route("/postfix/sender/access/<path:sender>")
49 def postfix_sender_access(sender):
50     """ Simply reject any sender that pretends to be from a local domain
51     """
52     if not is_void_address(sender):
53         localpart, domain_name = models.Email.resolve_domain(sender)
54         return flask.jsonify("REJECT") if models.Domain.query.get(domain_name) else flask.abort(404)
55     else:
56         return flask.abort(404)
57 
58 
59 def is_void_address(email):
60     '''True if the email is void (null) email address.
61     '''
62     if email.startswith('<') and email.endswith('>'):
63         email = email[1:-1]
64     # Some MTAs use things like '<MAILER-DAEMON>' instead of '<>'; so let's
65     # consider void any such thing.
66     return '@' not in email
67
```
--- 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/internal/views/postfix.py b/core/admin/mailu/internal/views/postfix.py
--- a/core/admin/mailu/internal/views/postfix.py
+++ b/core/admin/mailu/internal/views/postfix.py
@@ -2,10 +2,13 @@
 from mailu.internal import internal
 
 import flask
+import re
 
 
 @internal.route("/postfix/domain/<domain_name>")
 def postfix_mailbox_domain(domain_name):
+    if re.match("^\[.*\]$", domain_name):
+        return flask.abort(404)
     domain = models.Domain.query.get(domain_name) or \
              models.Alternative.query.get(domain_name) or \
              flask.abort(404)
@@ -29,7 +32,7 @@
 
 @internal.route("/postfix/transport/<path:email>")
 def postfix_transport(email):
-    if email == '*':
+    if email == '*' or re.match("(^|.*@)\[.*\]$", email):
         return flask.abort(404)
     localpart, domain_name = models.Email.resolve_domain(email)
     relay = models.Relay.query.get(domain_name) or flask.abort(404)

{"golden_diff": "diff --git a/core/admin/mailu/internal/views/postfix.py b/core/admin/mailu/internal/views/postfix.py\n--- a/core/admin/mailu/internal/views/postfix.py\n+++ b/core/admin/mailu/internal/views/postfix.py\n@@ -2,10 +2,13 @@\n from mailu.internal import internal\n \n import flask\n+import re\n \n \n @internal.route(\"/postfix/domain/<domain_name>\")\n def postfix_mailbox_domain(domain_name):\n+    if re.match(\"^\\[.*\\]$\", domain_name):\n+        return flask.abort(404)\n     domain = models.Domain.query.get(domain_name) or \\\n              models.Alternative.query.get(domain_name) or \\\n              flask.abort(404)\n@@ -29,7 +32,7 @@\n \n @internal.route(\"/postfix/transport/<path:email>\")\n def postfix_transport(email):\n-    if email == '*':\n+    if email == '*' or re.match(\"(^|.*@)\\[.*\\]$\", email):\n         return flask.abort(404)\n     localpart, domain_name = models.Email.resolve_domain(email)\n     relay = models.Relay.query.get(domain_name) or flask.abort(404)\n", "issue": "MAIL FROM: does-not-exist@[X.X.X.X] results in an admin exeption stacktrace\nIf a client (read: malicious attacker) connects to Postfix and uses an IP address within brackets instead of a domain name for the sender, e.g.:\r\n\r\n```\r\n$ telnet mail.example.com 25\r\n\r\nConnected to example.com\r\nEscape character is '^]'.\r\n220 mail.example.com ESMTP ready\r\nEHLO dummy.example.com\r\n250-mail.example.com\r\n250 STARTTLS\r\nMAIL FROM: does-not-exist@[116.203.165.200]\r\n250 2.0.0 OK\r\nRCPT TO: some-user@example.com\r\n451 4.3.0 <does-not-exist@[116.203.165.200]>: Temporary lookup failure\r\n```\r\n\r\nwe see the following stracktrace in the admin container:\r\n\r\n```\r\n[2019-07-27 14:26:27,015] ERROR in app: Exception on /internal/postfix/domain/[116.203.165.200] [GET]\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 271, in alabel\r\n    ulabel(label)\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 307, in ulabel\r\n    check_label(label)\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 261, in check_label\r\n    raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))\r\nidna.core.InvalidCodepoint: Codepoint U+005B at position 1 of '[116' not allowed\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1127, in _execute_context\r\n    context = constructor(dialect, self, conn, *args)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/default.py\", line 669, in _init_compiled\r\n    param.append(processors[key](compiled_params[key]))\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/sql/type_api.py\", line 1182, in process\r\n    return process_param(value, dialect)\r\n  File \"/app/mailu/models.py\", line 30, in process_bind_param\r\n    return idna.encode(value).decode(\"ascii\").lower()\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 361, in encode\r\n    s = alabel(label)\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 273, in alabel\r\n    raise IDNAError('The label {0} is not a valid A-label'.format(label))\r\nidna.core.IDNAError: The label b'[116' is not a valid A-label\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.7/site-packages/flask/app.py\", line 2292, in wsgi_app\r\n    response = self.full_dispatch_request()\r\n  File \"/usr/lib/python3.7/site-packages/flask/app.py\", line 1815, in full_dispatch_request\r\n    rv = self.handle_user_exception(e)\r\n  File \"/usr/lib/python3.7/site-packages/flask/app.py\", line 1718, in handle_user_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/usr/lib/python3.7/site-packages/flask/_compat.py\", line 35, in reraise\r\n    raise value\r\n  File \"/usr/lib/python3.7/site-packages/flask/app.py\", line 1813, in full_dispatch_request\r\n    rv = self.dispatch_request()\r\n  File \"/usr/lib/python3.7/site-packages/flask/app.py\", line 1799, in dispatch_request\r\n    return self.view_functions[rule.endpoint](**req.view_args)\r\n  File \"/app/mailu/internal/views/postfix.py\", line 9, in postfix_mailbox_domain\r\n    domain = models.Domain.query.get(domain_name) or \\\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 924, in get\r\n    ident, loading.load_on_pk_identity)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 1007, in _get_impl\r\n    return db_load_fn(self, primary_key_identity)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/loading.py\", line 250, in load_on_pk_identity\r\n    return q.one()\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 2954, in one\r\n    ret = self.one_or_none()\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 2924, in one_or_none\r\n    ret = list(self)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 2995, in __iter__\r\n    return self._execute_and_instances(context)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/orm/query.py\", line 3018, in _execute_and_instances\r\n    result = conn.execute(querycontext.statement, self._params)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 948, in execute\r\n    return meth(self, multiparams, params)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/sql/elements.py\", line 269, in _execute_on_connection\r\n    return connection._execute_clauseelement(self, multiparams, params)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1060, in _execute_clauseelement\r\n    compiled_sql, distilled_params\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1132, in _execute_context\r\n    None, None)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1413, in _handle_dbapi_exception\r\n    exc_info\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/util/compat.py\", line 265, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/util/compat.py\", line 248, in reraise\r\n    raise value.with_traceback(tb)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1127, in _execute_context\r\n    context = constructor(dialect, self, conn, *args)\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/engine/default.py\", line 669, in _init_compiled\r\n    param.append(processors[key](compiled_params[key]))\r\n  File \"/usr/lib/python3.7/site-packages/sqlalchemy/sql/type_api.py\", line 1182, in process\r\n    return process_param(value, dialect)\r\n  File \"/app/mailu/models.py\", line 30, in process_bind_param\r\n    return idna.encode(value).decode(\"ascii\").lower()\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 361, in encode\r\n    s = alabel(label)\r\n  File \"/usr/lib/python3.7/site-packages/idna/core.py\", line 273, in alabel\r\n    raise IDNAError('The label {0} is not a valid A-label'.format(label))\r\nsqlalchemy.exc.StatementError: (idna.core.IDNAError) The label b'[116' is not a valid A-label [SQL: 'SELECT domain.created_at AS domain_created_at, domain.updated_at AS domain_updated_at, domain.comment AS domain_comment, domain.name AS domain_name, domain.max_users AS domain_max_users, domain.max_aliases AS domain_max_aliases, domain.max_quota_bytes AS domain_max_quota_bytes, domain.signup_enabled AS domain_signup_enabled \\nFROM domain \\nWHERE domain.name = ?'] [parameters: [{'%(140312238936248 param)s': '[116.203.165.200]'}]]\r\n10.36.0.0 - - [27/Jul/2019:14:26:27 +0000] \"GET /internal/postfix/domain/%5B116.203.165.200%5D HTTP/1.1\" 500 291 \"-\" \"Python/3.7 aiohttp/3.5.4\"\r\n10.44.0.0 - - [27/Jul/2019:14:26:31 +0000] \"GET /internal/auth/email HTTP/1.0\" 200 0 \"-\" \"-\"\r\n```\r\n\r\nNOTE: the lookup is cached I think and you need to use another IP address to reproduce the error multiple times.\r\n\r\nI think we're missing some validation rules, because trying a similar (invalid) MAIL FROM with an IP (but without brackets) is handled properly:\r\n\r\n```\r\ntelnet mail.example.com 25\r\nTrying ...\r\nConnected to example.com.\r\nEscape character is '^]'.\r\n220 mail.example.com ESMTP ready\r\nEHLO dummy.example.com\r\n250-mail.example.com\r\n250 STARTTLS\r\nMAIL FROM: does-not-exist@192.168.1.1\r\n250 2.0.0 OK\r\nRCPT TO: some-user@example.com\r\n501 5.1.7 Bad sender address syntax\r\nConnection closed by foreign host.\r\n```\n", "before_files": [{"content": "from mailu import models\nfrom mailu.internal import internal\n\nimport flask\n\n\n@internal.route(\"/postfix/domain/<domain_name>\")\ndef postfix_mailbox_domain(domain_name):\n    domain = models.Domain.query.get(domain_name) or \\\n             models.Alternative.query.get(domain_name) or \\\n             flask.abort(404)\n    return flask.jsonify(domain.name)\n\n\n@internal.route(\"/postfix/mailbox/<path:email>\")\ndef postfix_mailbox_map(email):\n    user = models.User.query.get(email) or flask.abort(404)\n    return flask.jsonify(user.email)\n\n\n@internal.route(\"/postfix/alias/<path:alias>\")\ndef postfix_alias_map(alias):\n    localpart, domain_name = models.Email.resolve_domain(alias)\n    if localpart is None:\n        return flask.jsonify(domain_name)\n    destination = models.Email.resolve_destination(localpart, domain_name)\n    return flask.jsonify(\",\".join(destination)) if destination else flask.abort(404)\n\n\n@internal.route(\"/postfix/transport/<path:email>\")\ndef postfix_transport(email):\n    if email == '*':\n        return flask.abort(404)\n    localpart, domain_name = models.Email.resolve_domain(email)\n    relay = models.Relay.query.get(domain_name) or flask.abort(404)\n    return flask.jsonify(\"smtp:[{}]\".format(relay.smtp))\n\n\n@internal.route(\"/postfix/sender/login/<path:sender>\")\ndef postfix_sender_login(sender):\n    localpart, domain_name = models.Email.resolve_domain(sender)\n    if localpart is None:\n        return flask.abort(404)\n    destination = models.Email.resolve_destination(localpart, domain_name, True)\n    return flask.jsonify(\",\".join(destination)) if destination else flask.abort(404)\n\n\n@internal.route(\"/postfix/sender/access/<path:sender>\")\ndef postfix_sender_access(sender):\n    \"\"\" Simply reject any sender that pretends to be from a local domain\n    \"\"\"\n    if not is_void_address(sender):\n        localpart, domain_name = models.Email.resolve_domain(sender)\n        return flask.jsonify(\"REJECT\") if models.Domain.query.get(domain_name) else flask.abort(404)\n    else:\n        return flask.abort(404)\n\n\ndef is_void_address(email):\n    '''True if the email is void (null) email address.\n    '''\n    if email.startswith('<') and email.endswith('>'):\n        email = email[1:-1]\n    # Some MTAs use things like '<MAILER-DAEMON>' instead of '<>'; so let's\n    # consider void any such thing.\n    return '@' not in email\n", "path": "core/admin/mailu/internal/views/postfix.py"}], "after_files": [{"content": "from mailu import models\nfrom mailu.internal import internal\n\nimport flask\nimport re\n\n\n@internal.route(\"/postfix/domain/<domain_name>\")\ndef postfix_mailbox_domain(domain_name):\n    if re.match(\"^\\[.*\\]$\", domain_name):\n        return flask.abort(404)\n    domain = models.Domain.query.get(domain_name) or \\\n             models.Alternative.query.get(domain_name) or \\\n             flask.abort(404)\n    return flask.jsonify(domain.name)\n\n\n@internal.route(\"/postfix/mailbox/<path:email>\")\ndef postfix_mailbox_map(email):\n    user = models.User.query.get(email) or flask.abort(404)\n    return flask.jsonify(user.email)\n\n\n@internal.route(\"/postfix/alias/<path:alias>\")\ndef postfix_alias_map(alias):\n    localpart, domain_name = models.Email.resolve_domain(alias)\n    if localpart is None:\n        return flask.jsonify(domain_name)\n    destination = models.Email.resolve_destination(localpart, domain_name)\n    return flask.jsonify(\",\".join(destination)) if destination else flask.abort(404)\n\n\n@internal.route(\"/postfix/transport/<path:email>\")\ndef postfix_transport(email):\n    if email == '*' or re.match(\"(^|.*@)\\[.*\\]$\", email):\n        return flask.abort(404)\n    localpart, domain_name = models.Email.resolve_domain(email)\n    relay = models.Relay.query.get(domain_name) or flask.abort(404)\n    return flask.jsonify(\"smtp:[{}]\".format(relay.smtp))\n\n\n@internal.route(\"/postfix/sender/login/<path:sender>\")\ndef postfix_sender_login(sender):\n    localpart, domain_name = models.Email.resolve_domain(sender)\n    if localpart is None:\n        return flask.abort(404)\n    destination = models.Email.resolve_destination(localpart, domain_name, True)\n    return flask.jsonify(\",\".join(destination)) if destination else flask.abort(404)\n\n\n@internal.route(\"/postfix/sender/access/<path:sender>\")\ndef postfix_sender_access(sender):\n    \"\"\" Simply reject any sender that pretends to be from a local domain\n    \"\"\"\n    if not is_void_address(sender):\n        localpart, domain_name = models.Email.resolve_domain(sender)\n        return flask.jsonify(\"REJECT\") if models.Domain.query.get(domain_name) else flask.abort(404)\n    else:\n        return flask.abort(404)\n\n\ndef is_void_address(email):\n    '''True if the email is void (null) email address.\n    '''\n    if email.startswith('<') and email.endswith('>'):\n        email = email[1:-1]\n    # Some MTAs use things like '<MAILER-DAEMON>' instead of '<>'; so let's\n    # consider void any such thing.\n    return '@' not in email\n", "path": "core/admin/mailu/internal/views/postfix.py"}]}