mirror of
https://github.com/optim-enterprises-bv/Mailu.git
synced 2025-11-01 18:47:52 +00:00
Resolve HOST_* to *_ADDRESS only if *_ADDRESS is not already set
This commit is contained in:
@@ -3,6 +3,9 @@ from flask import current_app as app
|
||||
|
||||
import re
|
||||
import urllib
|
||||
import ipaddress
|
||||
import socket
|
||||
import tenacity
|
||||
|
||||
|
||||
SUPPORTED_AUTH_METHODS = ["none", "plain"]
|
||||
@@ -88,4 +91,18 @@ def get_server(protocol, authenticated=False):
|
||||
hostname, port = extract_host_port(app.config['AUTHSMTP_ADDRESS'], 10025)
|
||||
else:
|
||||
hostname, port = extract_host_port(app.config['SMTP_ADDRESS'], 25)
|
||||
try:
|
||||
# test if hostname is already resolved to an ip adddress
|
||||
ipaddress.ip_address(hostname)
|
||||
except:
|
||||
# hostname is not an ip address - so we need to resolve it
|
||||
hostname = resolve_hostname(hostname)
|
||||
return hostname, port
|
||||
|
||||
@tenacity.retry(stop=tenacity.stop_after_attempt(100),
|
||||
wait=tenacity.wait_random(min=2, max=5))
|
||||
def resolve_hostname(hostname):
|
||||
""" This function uses system DNS to resolve a hostname.
|
||||
It is capable of retrying in case the host is not immediately available
|
||||
"""
|
||||
return socket.gethostbyname(hostname)
|
||||
|
||||
Reference in New Issue
Block a user