mirror of
https://github.com/optim-enterprises-bv/Mailu-OIDC.git
synced 2025-11-02 02:57:49 +00:00
Enable dynamic resolution of hostnames
This commit is contained in:
@@ -2,7 +2,6 @@ from mailu import models, utils
|
||||
from flask import current_app as app
|
||||
from socrate import system
|
||||
|
||||
import re
|
||||
import urllib
|
||||
import ipaddress
|
||||
import sqlalchemy.exc
|
||||
@@ -128,20 +127,16 @@ def get_status(protocol, status):
|
||||
status, codes = STATUSES[status]
|
||||
return status, codes[protocol]
|
||||
|
||||
def extract_host_port(host_and_port, default_port):
|
||||
host, _, port = re.match('^(.*?)(:([0-9]*))?$', host_and_port).groups()
|
||||
return host, int(port) if port else default_port
|
||||
|
||||
def get_server(protocol, authenticated=False):
|
||||
if protocol == "imap":
|
||||
hostname, port = extract_host_port(app.config['IMAP_ADDRESS'], 143)
|
||||
hostname, port = app.config['IMAP_ADDRESS'], 143
|
||||
elif protocol == "pop3":
|
||||
hostname, port = extract_host_port(app.config['POP3_ADDRESS'], 110)
|
||||
hostname, port = app.config['IMAP_ADDRESS'], 110
|
||||
elif protocol == "smtp":
|
||||
if authenticated:
|
||||
hostname, port = extract_host_port(app.config['AUTHSMTP_ADDRESS'], 10025)
|
||||
hostname, port = app.config['SMTP_ADDRESS'], 10025
|
||||
else:
|
||||
hostname, port = extract_host_port(app.config['SMTP_ADDRESS'], 25)
|
||||
hostname, port = app.config['SMTP_ADDRESS'], 25
|
||||
try:
|
||||
# test if hostname is already resolved to an ip address
|
||||
ipaddress.ip_address(hostname)
|
||||
|
||||
Reference in New Issue
Block a user