Parametrize hosts

Allows to use mailu without docker-compose when hostnames are not set up
by docker itself but provided via a separate resolver.

Use case: use mailu using nomad scheduler and consul resolver instead of
docker-compose. Other servers are provided by the DNS resolver that
resolves names like admin.service.consul or webmail.service.consul.
These names needs to be configurable.
This commit is contained in:
Mildred Ki'Lya
2018-01-24 00:55:43 +01:00
parent d8ebfbe020
commit f538e33dcf
5 changed files with 46 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
from mailu import db, models
from mailu import db, models, app
import re
import socket
import urllib
@@ -73,14 +74,19 @@ 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 = "imap", 143
hostname, port = extract_host_port(app.config['HOST_IMAP'], 143)
elif protocol == "pop3":
hostname, port = "imap", 110
hostname, port = extract_host_port(app.config['HOST_POP3'], 110)
elif protocol == "smtp":
hostname = "smtp"
port = 10025 if authenticated else 25
if authenticated:
hostname, port = extract_host_port(app.config['HOST_AUTHSMTP'], 10025)
else:
hostname, port = extract_host_port(app.config['HOST_SMTP'], 25)
address = socket.gethostbyname(hostname)
return address, port