Implement managesieve support

This commit is contained in:
Florent Daigniere
2023-04-20 15:36:17 +02:00
parent 152a2bf175
commit 107b0ab5ff
15 changed files with 134 additions and 38 deletions

View File

@@ -13,7 +13,8 @@ STATUSES = {
"authentication": ("Authentication credentials invalid", {
"imap": "AUTHENTICATIONFAILED",
"smtp": "535 5.7.8",
"pop3": "-ERR Authentication failed"
"pop3": "-ERR Authentication failed",
"sieve": "AuthFailed"
}),
"encryption": ("Must issue a STARTTLS command first", {
"smtp": "530 5.7.0"
@@ -32,7 +33,7 @@ def check_credentials(user, password, ip, protocol=None, auth_port=None):
return False
is_ok = False
# webmails
if auth_port in WEBMAIL_PORTS and password.startswith('token-'):
if auth_port in WEBMAIL_PORTS or auth_port == '4190' and password.startswith('token-'):
if utils.verify_temp_token(user.get_id(), password):
is_ok = True
# All tokens are 32 characters hex lowercase
@@ -50,8 +51,8 @@ def handle_authentication(headers):
""" Handle an HTTP nginx authentication request
See: http://nginx.org/en/docs/mail/ngx_mail_auth_http_module.html#protocol
"""
method = headers["Auth-Method"]
protocol = headers["Auth-Protocol"]
method = headers["Auth-Method"].lower()
protocol = headers["Auth-Protocol"].lower()
# Incoming mail, no authentication
if method == "none" and protocol == "smtp":
server, port = get_server(protocol, False)
@@ -121,7 +122,7 @@ def handle_authentication(headers):
"Auth-Wait": 0
}
# Unexpected
return {}
raise Exception("SHOULD NOT HAPPEN")
def get_status(protocol, status):
@@ -140,6 +141,8 @@ def get_server(protocol, authenticated=False):
hostname, port = app.config['SMTP_ADDRESS'], 10025
else:
hostname, port = app.config['SMTP_ADDRESS'], 25
elif protocol == "sieve":
hostname, port = app.config['IMAP_ADDRESS'], 4190
try:
# test if hostname is already resolved to an ip address
ipaddress.ip_address(hostname)