Repository: Mailu/Mailu

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


Discussion:
`git revert 7ce7f2096b530376af4944a98bd6edc276cd648e` (https://github.com/Mailu/Mailu/commit/7ce7f2096b530376af4944a98bd6edc276cd648e)

Fixes this issue. Make of that what you want.

(*Edit:* I have a docker image called `niduroki/mailu-admin:revert` implementing this little change, the configuration from above thus changes the admin-image from `mailu/admin:master` to `niduroki/mailu-admin:revert`)
Can you make a packet capture and paste here the request made by nginx to admin please? (to /internal/auth/email)
Not too certain if this is right - I'm not too versed with tcpdump.
(Output of `tcpdump -vvv -s0` in mailu_admin_1 –  this is the only entry related to `/auth/email` – using the official `mailu/admin:master`)

```
18:08:34.214362 IP (tos 0x0, ttl 64, id 24944, offset 0, flags [DF], proto TCP (6), length 502)
    mailu_front_1.mailu_default.36244 > 3c7905b538eb.80: Flags [P.], cksum 0x1941 (incorrect -> 0xac8b), seq 1:451, ack 1, win 502, options [nop,nop,TS val 2773252836 ecr 321669164], length 450: HTTP, length: 450
        GET /internal/auth/email HTTP/1.0
        Host: 192.168.203.4
        Connection: close
        Auth-Method: none
        Auth-User: 
        Auth-Pass: 
        Auth-Protocol: smtp
        Auth-Login-Attempt: 1
        Client-IP: [production-server-ip4]
        Client-Host: [production-server-hostname]
        Auth-SMTP-Helo: [production-server-hostname]
        Auth-SMTP-From: MAIL FROM:<chris@[production-server-hostname]> SIZE=403 BODY=8BITMIME
        Auth-SMTP-To: RCPT TO:<admin@[testserver-hostname]> ORCPT=rfc822;admin@[testserver-hostname]
        Auth-SSL: on
        Auth-Port: 25

```

Resolving patch:
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 @@ def nginx_authentication():
     """
     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'


Test patch: