We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
master can't receive mail – "AUTH not supported"
## Before you open your issue
- [X] Check if no issue or pull-request for this already exists.
- [X] Check [documentation](https://mailu.io/master/) and [FAQ](https://mailu.io/master/faq.html). (Tip, use the search function on the documentation page)
- [X] You understand `Mailu` is made by volunteers in their **free time** — be conscise, civil and accept that delays can occur.
- [X] The title of the issue should be short and simple. It should contain specific terms related to the actual issue. Be specific while writing the title.

## Environment & Versions
### Environment
 - [X] docker-compose
 - [ ] kubernetes
 - [ ] docker swarm

### Versions
`master`

## Description

Not able to receive email.
Error `502 5.5.1 AUTH not supported (in reply to RCPT TO command)`

## Replication Steps

1) Spin up a `master` instance, using setup.mailu.io
2) Send an E-Mail to the newly created admin on the instance
3) (Make sure it's nothing on your end, set up a `1.9` instance the same way. Works without a problem.)

## Logs

On the receiving side (mailu:master).

```
front_1     | 2022/03/09 16:27:12 [info] 19#19: *107 client [removed-ipv4]:38640 connected to 0.0.0.0:25
front_1     | 2022/03/09 16:27:13 [info] 19#19: *107 client login failed: "AUTH not supported" while in http auth state, client: [removed-ipv4] using starttls, server: 0.0.0.0:25
```

And on the sending side (mailu:1.9 - my production instance) I get this email:

```
This is the mail system at host [my-domain].

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system

<admin@[destination.mail]>: host [destination.mail][removed-ipv4] said:
    502 5.5.1 AUTH not supported (in reply to RCPT TO command)

Reporting-MTA: dns; [my-domain]
X-Postfix-Queue-ID: 027AA1198C9
X-Postfix-Sender: rfc822; [my-mail]
Arrival-Date: Wed,  9 Mar 2022 17:27:11 +0100 (CET)

Final-Recipient: rfc822; admin@[destination.mail]
Original-Recipient: rfc822;admin@[destination.mail]</a>
Action: failed
Status: 5.5.1
Remote-MTA: dns; [destination.mail]
Diagnostic-Code: smtp; 502 5.5.1 AUTH not supported
```

Same thing (but differently formatted) with gmail, too.

Probably related to #2265 and #2261
*Edit:* Maybe this commit, too: https://github.com/Mailu/Mailu/pull/2265/commits/7ce7f2096b530376af4944a98bd6edc276cd648e

--- 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/auth.py`
Content:
```
1 from mailu import models, utils
2 from mailu.internal import internal, nginx
3 from flask import current_app as app
4 
5 import flask
6 import flask_login
7 import base64
8 
9 @internal.route("/auth/email")
10 def nginx_authentication():
11     """ Main authentication endpoint for Nginx email server
12     """
13     client_ip = flask.request.headers["Client-Ip"]
14     headers = flask.request.headers
15     if headers["Auth-Port"] == '25':
16         response = flask.Response()
17         response.headers['Auth-Status'] = 'AUTH not supported'
18         response.headers['Auth-Error-Code'] = '502 5.5.1'
19         utils.limiter.rate_limit_ip(client_ip)
20         return response
21     is_from_webmail = headers['Auth-Port'] in ['10143', '10025']
22     if not is_from_webmail and utils.limiter.should_rate_limit_ip(client_ip):
23         status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')
24         response = flask.Response()
25         response.headers['Auth-Status'] = status
26         response.headers['Auth-Error-Code'] = code
27         if int(flask.request.headers['Auth-Login-Attempt']) < 10:
28             response.headers['Auth-Wait'] = '3'
29         return response
30     headers = nginx.handle_authentication(flask.request.headers)
31     response = flask.Response()
32     for key, value in headers.items():
33         response.headers[key] = str(value)
34     is_valid_user = False
35     if response.headers.get("Auth-User-Exists"):
36         username = response.headers["Auth-User"]
37         if utils.limiter.should_rate_limit_user(username, client_ip):
38             # FIXME could be done before handle_authentication()
39             status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')
40             response = flask.Response()
41             response.headers['Auth-Status'] = status
42             response.headers['Auth-Error-Code'] = code
43             if int(flask.request.headers['Auth-Login-Attempt']) < 10:
44                 response.headers['Auth-Wait'] = '3'
45             return response
46         is_valid_user = True
47     if headers.get("Auth-Status") == "OK":
48         utils.limiter.exempt_ip_from_ratelimits(client_ip)
49     elif is_valid_user:
50         utils.limiter.rate_limit_user(username, client_ip)
51     elif not is_from_webmail:
52         utils.limiter.rate_limit_ip(client_ip)
53     return response
54 
55 @internal.route("/auth/admin")
56 def admin_authentication():
57     """ Fails if the user is not an authenticated admin.
58     """
59     if (not flask_login.current_user.is_anonymous
60         and flask_login.current_user.global_admin
61         and flask_login.current_user.enabled):
62         return ""
63     return flask.abort(403)
64 
65 @internal.route("/auth/user")
66 def user_authentication():
67     """ Fails if the user is not authenticated.
68     """
69     if (not flask_login.current_user.is_anonymous
70         and flask_login.current_user.enabled):
71         response = flask.Response()
72         email = flask_login.current_user.get_id()
73         response.headers["X-User"] = models.IdnaEmail.process_bind_param(flask_login, email, "")
74         response.headers["X-User-Token"] = utils.gen_temp_token(email, flask.session)
75         return response
76     return flask.abort(403)
77 
78 
79 @internal.route("/auth/basic")
80 def basic_authentication():
81     """ Tries to authenticate using the Authorization header.
82     """
83     client_ip = flask.request.headers.get('X-Real-IP', flask.request.remote_addr)
84     if utils.limiter.should_rate_limit_ip(client_ip):
85         response = flask.Response(status=401)
86         response.headers["WWW-Authenticate"] = 'Basic realm="Authentication rate limit from one source exceeded"'
87         response.headers['Retry-After'] = '60'
88         return response
89     authorization = flask.request.headers.get("Authorization")
90     if authorization and authorization.startswith("Basic "):
91         encoded = authorization.replace("Basic ", "")
92         user_email, password = base64.b64decode(encoded).split(b":", 1)
93         user_email = user_email.decode("utf8")
94         if utils.limiter.should_rate_limit_user(user_email, client_ip):
95             response = flask.Response(status=401)
96             response.headers["WWW-Authenticate"] = 'Basic realm="Authentication rate limit for this username exceeded"'
97             response.headers['Retry-After'] = '60'
98             return response
99         user = models.User.query.get(user_email)
100         if user and nginx.check_credentials(user, password.decode('utf-8'), client_ip, "web"):
101             response = flask.Response()
102             response.headers["X-User"] = models.IdnaEmail.process_bind_param(flask_login, user.email, "")
103             utils.limiter.exempt_ip_from_ratelimits(client_ip)
104             return response
105         utils.limiter.rate_limit_user(user_email, client_ip) if user else utils.limiter.rate_limit_ip(client_ip)
106     response = flask.Response(status=401)
107     response.headers["WWW-Authenticate"] = 'Basic realm="Login Required"'
108     return response
109
```
--- 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/auth.py b/core/admin/mailu/internal/views/auth.py
--- a/core/admin/mailu/internal/views/auth.py
+++ b/core/admin/mailu/internal/views/auth.py
@@ -12,7 +12,7 @@
     """
     client_ip = flask.request.headers["Client-Ip"]
     headers = flask.request.headers
-    if headers["Auth-Port"] == '25':
+    if headers["Auth-Port"] == '25' and headers['Auth-Method'] != 'none':
         response = flask.Response()
         response.headers['Auth-Status'] = 'AUTH not supported'
         response.headers['Auth-Error-Code'] = '502 5.5.1'

{"golden_diff": "diff --git a/core/admin/mailu/internal/views/auth.py b/core/admin/mailu/internal/views/auth.py\n--- a/core/admin/mailu/internal/views/auth.py\n+++ b/core/admin/mailu/internal/views/auth.py\n@@ -12,7 +12,7 @@\n     \"\"\"\n     client_ip = flask.request.headers[\"Client-Ip\"]\n     headers = flask.request.headers\n-    if headers[\"Auth-Port\"] == '25':\n+    if headers[\"Auth-Port\"] == '25' and headers['Auth-Method'] != 'none':\n         response = flask.Response()\n         response.headers['Auth-Status'] = 'AUTH not supported'\n         response.headers['Auth-Error-Code'] = '502 5.5.1'\n", "issue": "master can't receive mail \u2013 \"AUTH not supported\"\n## Before you open your issue\r\n- [X] Check if no issue or pull-request for this already exists.\r\n- [X] Check [documentation](https://mailu.io/master/) and [FAQ](https://mailu.io/master/faq.html). (Tip, use the search function on the documentation page)\r\n- [X] You understand `Mailu` is made by volunteers in their **free time** \u2014 be conscise, civil and accept that delays can occur.\r\n- [X] The title of the issue should be short and simple. It should contain specific terms related to the actual issue. Be specific while writing the title.\r\n\r\n## Environment & Versions\r\n### Environment\r\n - [X] docker-compose\r\n - [ ] kubernetes\r\n - [ ] docker swarm\r\n\r\n### Versions\r\n`master`\r\n\r\n## Description\r\n\r\nNot able to receive email.\r\nError `502 5.5.1 AUTH not supported (in reply to RCPT TO command)`\r\n\r\n## Replication Steps\r\n\r\n1) Spin up a `master` instance, using setup.mailu.io\r\n2) Send an E-Mail to the newly created admin on the instance\r\n3) (Make sure it's nothing on your end, set up a `1.9` instance the same way. Works without a problem.)\r\n\r\n## Logs\r\n\r\nOn the receiving side (mailu:master).\r\n\r\n```\r\nfront_1     | 2022/03/09 16:27:12 [info] 19#19: *107 client [removed-ipv4]:38640 connected to 0.0.0.0:25\r\nfront_1     | 2022/03/09 16:27:13 [info] 19#19: *107 client login failed: \"AUTH not supported\" while in http auth state, client: [removed-ipv4] using starttls, server: 0.0.0.0:25\r\n```\r\n\r\nAnd on the sending side (mailu:1.9 - my production instance) I get this email:\r\n\r\n```\r\nThis is the mail system at host [my-domain].\r\n\r\nI'm sorry to have to inform you that your message could not\r\nbe delivered to one or more recipients. It's attached below.\r\n\r\nFor further assistance, please send mail to postmaster.\r\n\r\nIf you do so, please include this problem report. You can\r\ndelete your own text from the attached returned message.\r\n\r\n                   The mail system\r\n\r\n<admin@[destination.mail]>: host [destination.mail][removed-ipv4] said:\r\n    502 5.5.1 AUTH not supported (in reply to RCPT TO command)\r\n\r\nReporting-MTA: dns; [my-domain]\r\nX-Postfix-Queue-ID: 027AA1198C9\r\nX-Postfix-Sender: rfc822; [my-mail]\r\nArrival-Date: Wed,  9 Mar 2022 17:27:11 +0100 (CET)\r\n\r\nFinal-Recipient: rfc822; admin@[destination.mail]\r\nOriginal-Recipient: rfc822;admin@[destination.mail]</a>\r\nAction: failed\r\nStatus: 5.5.1\r\nRemote-MTA: dns; [destination.mail]\r\nDiagnostic-Code: smtp; 502 5.5.1 AUTH not supported\r\n```\r\n\r\nSame thing (but differently formatted) with gmail, too.\r\n\r\nProbably related to #2265 and #2261\r\n*Edit:* Maybe this commit, too: https://github.com/Mailu/Mailu/pull/2265/commits/7ce7f2096b530376af4944a98bd6edc276cd648e\n", "before_files": [{"content": "from mailu import models, utils\nfrom mailu.internal import internal, nginx\nfrom flask import current_app as app\n\nimport flask\nimport flask_login\nimport base64\n\n@internal.route(\"/auth/email\")\ndef nginx_authentication():\n    \"\"\" Main authentication endpoint for Nginx email server\n    \"\"\"\n    client_ip = flask.request.headers[\"Client-Ip\"]\n    headers = flask.request.headers\n    if headers[\"Auth-Port\"] == '25':\n        response = flask.Response()\n        response.headers['Auth-Status'] = 'AUTH not supported'\n        response.headers['Auth-Error-Code'] = '502 5.5.1'\n        utils.limiter.rate_limit_ip(client_ip)\n        return response\n    is_from_webmail = headers['Auth-Port'] in ['10143', '10025']\n    if not is_from_webmail and utils.limiter.should_rate_limit_ip(client_ip):\n        status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')\n        response = flask.Response()\n        response.headers['Auth-Status'] = status\n        response.headers['Auth-Error-Code'] = code\n        if int(flask.request.headers['Auth-Login-Attempt']) < 10:\n            response.headers['Auth-Wait'] = '3'\n        return response\n    headers = nginx.handle_authentication(flask.request.headers)\n    response = flask.Response()\n    for key, value in headers.items():\n        response.headers[key] = str(value)\n    is_valid_user = False\n    if response.headers.get(\"Auth-User-Exists\"):\n        username = response.headers[\"Auth-User\"]\n        if utils.limiter.should_rate_limit_user(username, client_ip):\n            # FIXME could be done before handle_authentication()\n            status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')\n            response = flask.Response()\n            response.headers['Auth-Status'] = status\n            response.headers['Auth-Error-Code'] = code\n            if int(flask.request.headers['Auth-Login-Attempt']) < 10:\n                response.headers['Auth-Wait'] = '3'\n            return response\n        is_valid_user = True\n    if headers.get(\"Auth-Status\") == \"OK\":\n        utils.limiter.exempt_ip_from_ratelimits(client_ip)\n    elif is_valid_user:\n        utils.limiter.rate_limit_user(username, client_ip)\n    elif not is_from_webmail:\n        utils.limiter.rate_limit_ip(client_ip)\n    return response\n\n@internal.route(\"/auth/admin\")\ndef admin_authentication():\n    \"\"\" Fails if the user is not an authenticated admin.\n    \"\"\"\n    if (not flask_login.current_user.is_anonymous\n        and flask_login.current_user.global_admin\n        and flask_login.current_user.enabled):\n        return \"\"\n    return flask.abort(403)\n\n@internal.route(\"/auth/user\")\ndef user_authentication():\n    \"\"\" Fails if the user is not authenticated.\n    \"\"\"\n    if (not flask_login.current_user.is_anonymous\n        and flask_login.current_user.enabled):\n        response = flask.Response()\n        email = flask_login.current_user.get_id()\n        response.headers[\"X-User\"] = models.IdnaEmail.process_bind_param(flask_login, email, \"\")\n        response.headers[\"X-User-Token\"] = utils.gen_temp_token(email, flask.session)\n        return response\n    return flask.abort(403)\n\n\n@internal.route(\"/auth/basic\")\ndef basic_authentication():\n    \"\"\" Tries to authenticate using the Authorization header.\n    \"\"\"\n    client_ip = flask.request.headers.get('X-Real-IP', flask.request.remote_addr)\n    if utils.limiter.should_rate_limit_ip(client_ip):\n        response = flask.Response(status=401)\n        response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Authentication rate limit from one source exceeded\"'\n        response.headers['Retry-After'] = '60'\n        return response\n    authorization = flask.request.headers.get(\"Authorization\")\n    if authorization and authorization.startswith(\"Basic \"):\n        encoded = authorization.replace(\"Basic \", \"\")\n        user_email, password = base64.b64decode(encoded).split(b\":\", 1)\n        user_email = user_email.decode(\"utf8\")\n        if utils.limiter.should_rate_limit_user(user_email, client_ip):\n            response = flask.Response(status=401)\n            response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Authentication rate limit for this username exceeded\"'\n            response.headers['Retry-After'] = '60'\n            return response\n        user = models.User.query.get(user_email)\n        if user and nginx.check_credentials(user, password.decode('utf-8'), client_ip, \"web\"):\n            response = flask.Response()\n            response.headers[\"X-User\"] = models.IdnaEmail.process_bind_param(flask_login, user.email, \"\")\n            utils.limiter.exempt_ip_from_ratelimits(client_ip)\n            return response\n        utils.limiter.rate_limit_user(user_email, client_ip) if user else utils.limiter.rate_limit_ip(client_ip)\n    response = flask.Response(status=401)\n    response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Login Required\"'\n    return response\n", "path": "core/admin/mailu/internal/views/auth.py"}], "after_files": [{"content": "from mailu import models, utils\nfrom mailu.internal import internal, nginx\nfrom flask import current_app as app\n\nimport flask\nimport flask_login\nimport base64\n\n@internal.route(\"/auth/email\")\ndef nginx_authentication():\n    \"\"\" Main authentication endpoint for Nginx email server\n    \"\"\"\n    client_ip = flask.request.headers[\"Client-Ip\"]\n    headers = flask.request.headers\n    if headers[\"Auth-Port\"] == '25' and headers['Auth-Method'] != 'none':\n        response = flask.Response()\n        response.headers['Auth-Status'] = 'AUTH not supported'\n        response.headers['Auth-Error-Code'] = '502 5.5.1'\n        utils.limiter.rate_limit_ip(client_ip)\n        return response\n    is_from_webmail = headers['Auth-Port'] in ['10143', '10025']\n    if not is_from_webmail and utils.limiter.should_rate_limit_ip(client_ip):\n        status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')\n        response = flask.Response()\n        response.headers['Auth-Status'] = status\n        response.headers['Auth-Error-Code'] = code\n        if int(flask.request.headers['Auth-Login-Attempt']) < 10:\n            response.headers['Auth-Wait'] = '3'\n        return response\n    headers = nginx.handle_authentication(flask.request.headers)\n    response = flask.Response()\n    for key, value in headers.items():\n        response.headers[key] = str(value)\n    is_valid_user = False\n    if response.headers.get(\"Auth-User-Exists\"):\n        username = response.headers[\"Auth-User\"]\n        if utils.limiter.should_rate_limit_user(username, client_ip):\n            # FIXME could be done before handle_authentication()\n            status, code = nginx.get_status(flask.request.headers['Auth-Protocol'], 'ratelimit')\n            response = flask.Response()\n            response.headers['Auth-Status'] = status\n            response.headers['Auth-Error-Code'] = code\n            if int(flask.request.headers['Auth-Login-Attempt']) < 10:\n                response.headers['Auth-Wait'] = '3'\n            return response\n        is_valid_user = True\n    if headers.get(\"Auth-Status\") == \"OK\":\n        utils.limiter.exempt_ip_from_ratelimits(client_ip)\n    elif is_valid_user:\n        utils.limiter.rate_limit_user(username, client_ip)\n    elif not is_from_webmail:\n        utils.limiter.rate_limit_ip(client_ip)\n    return response\n\n@internal.route(\"/auth/admin\")\ndef admin_authentication():\n    \"\"\" Fails if the user is not an authenticated admin.\n    \"\"\"\n    if (not flask_login.current_user.is_anonymous\n        and flask_login.current_user.global_admin\n        and flask_login.current_user.enabled):\n        return \"\"\n    return flask.abort(403)\n\n@internal.route(\"/auth/user\")\ndef user_authentication():\n    \"\"\" Fails if the user is not authenticated.\n    \"\"\"\n    if (not flask_login.current_user.is_anonymous\n        and flask_login.current_user.enabled):\n        response = flask.Response()\n        email = flask_login.current_user.get_id()\n        response.headers[\"X-User\"] = models.IdnaEmail.process_bind_param(flask_login, email, \"\")\n        response.headers[\"X-User-Token\"] = utils.gen_temp_token(email, flask.session)\n        return response\n    return flask.abort(403)\n\n\n@internal.route(\"/auth/basic\")\ndef basic_authentication():\n    \"\"\" Tries to authenticate using the Authorization header.\n    \"\"\"\n    client_ip = flask.request.headers.get('X-Real-IP', flask.request.remote_addr)\n    if utils.limiter.should_rate_limit_ip(client_ip):\n        response = flask.Response(status=401)\n        response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Authentication rate limit from one source exceeded\"'\n        response.headers['Retry-After'] = '60'\n        return response\n    authorization = flask.request.headers.get(\"Authorization\")\n    if authorization and authorization.startswith(\"Basic \"):\n        encoded = authorization.replace(\"Basic \", \"\")\n        user_email, password = base64.b64decode(encoded).split(b\":\", 1)\n        user_email = user_email.decode(\"utf8\")\n        if utils.limiter.should_rate_limit_user(user_email, client_ip):\n            response = flask.Response(status=401)\n            response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Authentication rate limit for this username exceeded\"'\n            response.headers['Retry-After'] = '60'\n            return response\n        user = models.User.query.get(user_email)\n        if user and nginx.check_credentials(user, password.decode('utf-8'), client_ip, \"web\"):\n            response = flask.Response()\n            response.headers[\"X-User\"] = models.IdnaEmail.process_bind_param(flask_login, user.email, \"\")\n            utils.limiter.exempt_ip_from_ratelimits(client_ip)\n            return response\n        utils.limiter.rate_limit_user(user_email, client_ip) if user else utils.limiter.rate_limit_ip(client_ip)\n    response = flask.Response(status=401)\n    response.headers[\"WWW-Authenticate\"] = 'Basic realm=\"Login Required\"'\n    return response\n", "path": "core/admin/mailu/internal/views/auth.py"}]}