Reflect the data from the POST

master
Florent Daigniere 3 years ago
parent 14931c4acd
commit 3e6f3a95a4

@ -2,6 +2,7 @@ from mailu.internal import internal
from flask import current_app as app from flask import current_app as app
import flask import flask
import xmltodict
@internal.route("/autoconfig/mozilla") @internal.route("/autoconfig/mozilla")
def autoconfig_mozilla(): def autoconfig_mozilla():
@ -50,13 +51,20 @@ def autoconfig_microsoft_json():
else: else:
return flask.abort(404) return flask.abort(404)
@internal.route("/autoconfig/microsoft", methods=['GET', 'POST']) @internal.route("/autoconfig/microsoft", methods=['POST'])
def autoconfig_microsoft(): def autoconfig_microsoft():
# https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14)?redirectedfrom=MSDN#Anchor_3 # https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14)?redirectedfrom=MSDN#Anchor_3
hostname = app.config['HOSTNAME'] hostname = app.config['HOSTNAME']
try:
xmlRequest = (flask.request.data).decode("utf-8")
xml = xmltodict.parse(xmlRequest[xmlRequest.find('<'):xmlRequest.rfind('>')+1])
schema = xml['Autodiscover']['Request']['AcceptableResponseSchema']
if schema != 'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a':
return flask.abort(404)
email = xml['Autodiscover']['Request']['EMailAddress']
xml = f'''<?xml version=\"1.0\" encoding=\"utf-8\" ?> xml = f'''<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006\"> <Autodiscover xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006\">
<Response xmlns=\"http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a\"> <Response xmlns="{schema}">
<Account> <Account>
<AccountType>email</AccountType> <AccountType>email</AccountType>
<Action>settings</Action> <Action>settings</Action>
@ -64,22 +72,27 @@ def autoconfig_microsoft():
<Type>IMAP</Type> <Type>IMAP</Type>
<Server>{hostname}</Server> <Server>{hostname}</Server>
<Port>993</Port> <Port>993</Port>
<LoginName>{email}</LoginName>
<DomainRequired>on</DomainRequired> <DomainRequired>on</DomainRequired>
<SPA>off</SPA> <SPA>off</SPA>
<Encryption>TLS</Encryption> <SSL>on</SSL>
</Protocol> </Protocol>
<Protocol> <Protocol>
<Type>SMTP</Type> <Type>SMTP</Type>
<Server>{hostname}</Server> <Server>{hostname}</Server>
<Port>465</Port> <Port>465</Port>
<LoginName>{email}</LoginName>
<DomainRequired>on</DomainRequired> <DomainRequired>on</DomainRequired>
<SPA>off</SPA> <SPA>off</SPA>
<Encryption>TLS</Encryption> <SSL>on</SSL>
</Protocol> </Protocol>
</Account> </Account>
</Response> </Response>
</Autodiscover>''' </Autodiscover>'''
return flask.Response(xml, mimetype='text/xml', status=200) return flask.Response(xml, mimetype='text/xml', status=200)
except:
pass
return flask.abort(400)
@internal.route("/autoconfig/apple") @internal.route("/autoconfig/apple")
def autoconfig_apple(): def autoconfig_apple():

@ -73,3 +73,4 @@ webencodings==0.5.1
Werkzeug==2.0.2 Werkzeug==2.0.2
WTForms==2.3.3 WTForms==2.3.3
WTForms-Components==0.10.5 WTForms-Components==0.10.5
xmltodict==0.12.0

@ -25,3 +25,4 @@ srslib
marshmallow marshmallow
flask-marshmallow flask-marshmallow
marshmallow-sqlalchemy marshmallow-sqlalchemy
xmltodict

Loading…
Cancel
Save