from mailu.internal import internal from flask import current_app as app import flask import xmltodict @internal.route("/autoconfig/mozilla") def autoconfig_mozilla(): # https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat hostname = app.config['HOSTNAME'] xml = f''' %EMAILDOMAIN% Email Email {hostname} 993 SSL %EMAILADDRESS% password-cleartext {hostname} 465 SSL %EMAILADDRESS% password-cleartext true true Configure your email client \r\n''' return flask.Response(xml, mimetype='text/xml', status=200) @internal.route("/autoconfig/microsoft.json") def autoconfig_microsoft_json(): proto = flask.request.args.get('Protocol', 'Autodiscoverv1') if proto == 'Autodiscoverv1': hostname = app.config['HOSTNAME'] json = f'"Protocol":"Autodiscoverv1","Url":"https://{hostname}/autodiscover/autodiscover.xml"' return flask.Response('{'+json+'}', mimetype='application/json', status=200) else: return flask.abort(404) @internal.route("/autoconfig/microsoft", methods=['POST']) def autoconfig_microsoft(): # https://docs.microsoft.com/en-us/previous-versions/office/office-2010/cc511507(v=office.14)?redirectedfrom=MSDN#Anchor_3 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''' email settings IMAP {hostname} 993 {email} on off on SMTP {hostname} 465 {email} on off on ''' return flask.Response(xml, mimetype='text/xml', status=200) except: return flask.abort(400) @internal.route("/autoconfig/apple") def autoconfig_apple(): # https://developer.apple.com/business/documentation/Configuration-Profile-Reference.pdf hostname = app.config['HOSTNAME'] sitename = app.config['SITENAME'] xml = f''' PayloadContent EmailAccountDescription {sitename} EmailAccountName {hostname} EmailAccountType EmailTypeIMAP EmailAddress IncomingMailServerAuthentication EmailAuthPassword IncomingMailServerHostName {hostname} IncomingMailServerPortNumber 993 IncomingMailServerUseSSL IncomingMailServerUsername IncomingPassword OutgoingMailServerAuthentication EmailAuthPassword OutgoingMailServerHostName {hostname} OutgoingMailServerPortNumber 465 OutgoingMailServerUseSSL OutgoingMailServerUsername OutgoingPasswordSameAsIncomingPassword PayloadDescription {sitename} PayloadDisplayName {hostname} PayloadIdentifier {hostname}.email PayloadOrganization PayloadType com.apple.mail.managed PayloadUUID 72e152e2-d285-4588-9741-25bdd50c4d11 PayloadVersion 1 PreventAppSheet PreventMove SMIMEEnabled disableMailRecentsSyncing PayloadDescription {hostname} - E-Mail Account Configuration PayloadDisplayName E-Mail Account {hostname} PayloadIdentifier E-Mail Account {hostname} PayloadOrganization {hostname} PayloadRemovalDisallowed PayloadType Configuration PayloadUUID 56db43a5-d29e-4609-a908-dce94d0be48e PayloadVersion 1 \r\n''' return flask.Response(xml, mimetype='text/xml', status=200)