Commit e2f06170 authored by kaiyou's avatar kaiyou

Support calling an external API for resolving aliases

parent 3db448c9
Pipeline #380 passed with stage
in 10 minutes and 41 seconds
......@@ -13,6 +13,7 @@ import time
import os
import glob
import smtplib
import requests
import idna
import dns
......@@ -133,6 +134,7 @@ class Domain(Base):
max_aliases = db.Column(db.Integer, nullable=False, default=-1)
max_quota_bytes = db.Column(db.BigInteger(), nullable=False, default=0)
signup_enabled = db.Column(db.Boolean(), nullable=False, default=False)
alias_delegation_api = db.Column(db.String(255))
@property
def dkim_key(self):
......@@ -165,6 +167,11 @@ class Domain(Base):
else:
return False
def delegate_alias(self, localpart):
return requests.get(
self.alias_delegation_api.format(localpart)
).json() or None
def check_mx(self):
try:
hostnames = app.config['HOSTNAMES'].split(',')
......@@ -269,9 +276,14 @@ class Email(object):
def resolve_destination(cls, localpart, domain_name, ignore_forward_keep=False):
localpart_stripped = None
stripped_alias = None
delimiter = os.environ.get('RECIPIENT_DELIMITER')
if delimiter in localpart:
localpart_stripped = localpart.rsplit(delimiter, 1)[0]
if os.environ.get('RECIPIENT_DELIMITER') in localpart:
localpart_stripped = localpart.rsplit(os.environ.get('RECIPIENT_DELIMITER'), 1)[0]
domain = Domain.query.get(domain_name)
if domain and domain.alias_delegation_api:
return domain.delegate_alias(localpart)
user = User.query.get('{}@{}'.format(localpart, domain_name))
if not user and localpart_stripped:
......
alembic==1.0.10
asn1crypto==0.24.0
Babel==2.6.0
bcrypt==3.1.6
alembic==1.3.2
Babel==2.7.0
bcrypt==3.1.7
blinker==1.4
cffi==1.12.3
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
Click==7.0
cryptography==2.6.1
decorator==4.4.0
cryptography==2.8
decorator==4.4.1
dnspython==1.16.0
dominate==2.3.5
Flask==1.0.2
dominate==2.4.0
Flask==1.1.1
Flask-Babel==0.12.2
Flask-Bootstrap==3.3.7.1
Flask-DebugToolbar==0.10.1
Flask-Limiter==1.0.1
Flask-Limiter==1.1.0
Flask-Login==0.4.1
Flask-Migrate==2.4.0
Flask-Migrate==2.5.2
Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.0
Flask-SQLAlchemy==2.4.1
Flask-WTF==0.14.2
gunicorn==19.9.0
idna==2.8
infinity==1.4
intervals==0.8.1
itsdangerous==1.1.0
Jinja2==2.10.1
limits==1.3
Mako==1.0.9
Jinja2==2.10.3
limits==1.4.1
Mako==1.1.0
MarkupSafe==1.1.1
mysqlclient==1.4.2.post1
passlib==1.7.1
psycopg2==2.8.2
mysqlclient==1.4.6
passlib==1.7.2
psycopg2==2.8.4
pycparser==2.19
pyOpenSSL==19.0.0
python-dateutil==2.8.0
pyOpenSSL==19.1.0
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2019.1
PyYAML==5.1
redis==3.2.1
six==1.12.0
socrate==0.1.1
SQLAlchemy==1.3.3
tabulate==0.8.3
tenacity==5.0.4
validators==0.12.5
pytz==2019.3
PyYAML==5.2
redis==3.3.11
requests==2.22.0
six==1.13.0
socrate==0.2.0
SQLAlchemy==1.3.12
tabulate==0.8.6
tenacity==6.0.0
urllib3==1.25.7
validators==0.14.1
visitor==0.1.3
Werkzeug==0.15.3
Werkzeug==0.16.0
WTForms==2.2.1
WTForms-Components==0.10.4
......@@ -8,6 +8,7 @@ Flask-script
Flask-wtf
Flask-debugtoolbar
Flask-limiter
requests
redis
WTForms-Components
socrate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment