From c545b8d110d769f3bb33fce6c976c26a3a13e3be Mon Sep 17 00:00:00 2001 From: kaiyou Date: Tue, 21 Nov 2017 20:46:18 +0100 Subject: [PATCH] Honor feature limitations for imap and pop3 --- core/admin/mailu/internal/nginx.py | 37 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/core/admin/mailu/internal/nginx.py b/core/admin/mailu/internal/nginx.py index cdd6a214..3ad51de6 100644 --- a/core/admin/mailu/internal/nginx.py +++ b/core/admin/mailu/internal/nginx.py @@ -37,27 +37,32 @@ def handle_authentication(headers): password = urllib.parse.unquote(headers["Auth-Pass"]) ip = urllib.parse.unquote(headers["Client-Ip"]) user = models.User.query.get(user_email) + status = False if user: for token in user.tokens: if (token.check_password(password) and (not token.ip or token.ip == ip)): - return { - "Auth-Status": "OK", - "Auth-Server": server, - "Auth-Port": port - } + status = True if user.check_password(password): - return { - "Auth-Status": "OK", - "Auth-Server": server, - "Auth-Port": port - } - status, code = get_status(protocol, "authentication") - return { - "Auth-Status": status, - "Auth-Error-Code": code, - "Auth-Wait": 0 - } + status = True + if status: + if protocol == "imap" and not user.enable_imap: + status = False + elif protocol == "pop3" and not user.enable_pop: + status = False + if status: + return { + "Auth-Status": "OK", + "Auth-Server": server, + "Auth-Port": port + } + else: + status, code = get_status(protocol, "authentication") + return { + "Auth-Status": status, + "Auth-Error-Code": code, + "Auth-Wait": 0 + } # Unexpected return {}