2022-03-10 10:28:10 +02:00
|
|
|
from mailu.internal import internal
|
|
|
|
|
|
|
|
from flask import current_app as app
|
|
|
|
import flask
|
2022-03-16 15:43:14 +02:00
|
|
|
import xmltodict
|
2022-03-10 10:28:10 +02:00
|
|
|
|
|
|
|
@internal.route("/autoconfig/mozilla")
|
|
|
|
def autoconfig_mozilla():
|
|
|
|
# https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
|
|
|
|
hostname = app.config['HOSTNAME']
|
2022-03-17 12:39:57 +02:00
|
|
|
xml = f'''<?xml version="1.0"?>
|
|
|
|
<clientConfig version="1.1">
|
|
|
|
<emailProvider id="%EMAILDOMAIN%">
|
2022-03-10 10:28:10 +02:00
|
|
|
<domain>%EMAILDOMAIN%</domain>
|
|
|
|
|
|
|
|
<displayName>Email</displayName>
|
|
|
|
<displayShortName>Email</displayShortName>
|
|
|
|
|
2022-03-17 12:39:57 +02:00
|
|
|
<incomingServer type="imap">
|
2022-03-10 10:28:10 +02:00
|
|
|
<hostname>{hostname}</hostname>
|
|
|
|
<port>993</port>
|
|
|
|
<socketType>SSL</socketType>
|
|
|
|
<username>%EMAILADDRESS%</username>
|
|
|
|
<authentication>password-cleartext</authentication>
|
|
|
|
</incomingServer>
|
|
|
|
|
2022-03-17 12:39:57 +02:00
|
|
|
<outgoingServer type="smtp">
|
2022-03-10 10:28:10 +02:00
|
|
|
<hostname>{hostname}</hostname>
|
|
|
|
<port>465</port>
|
|
|
|
<socketType>SSL</socketType>
|
|
|
|
<username>%EMAILADDRESS%</username>
|
|
|
|
<authentication>password-cleartext</authentication>
|
|
|
|
<addThisServer>true</addThisServer>
|
|
|
|
<useGlobalPreferredServer>true</useGlobalPreferredServer>
|
|
|
|
</outgoingServer>
|
|
|
|
|
2022-03-17 12:39:57 +02:00
|
|
|
<documentation url="https://{hostname}/admin/client">
|
|
|
|
<descr lang="en">Configure your email client</descr>
|
2022-03-10 10:28:10 +02:00
|
|
|
</documentation>
|
|
|
|
</emailProvider>
|
2022-03-10 11:00:51 +02:00
|
|
|
</clientConfig>\r\n'''
|
|
|
|
return flask.Response(xml, mimetype='text/xml', status=200)
|
|
|
|
|
2022-03-15 11:26:29 +02:00
|
|
|
@internal.route("/autoconfig/microsoft.json")
|
|
|
|
def autoconfig_microsoft_json():
|
|
|
|
proto = flask.request.args.get('Protocol', 'Autodiscoverv1')
|
|
|
|
if proto == 'Autodiscoverv1':
|
|
|
|
hostname = app.config['HOSTNAME']
|
2022-03-16 15:14:03 +02:00
|
|
|
json = f'"Protocol":"Autodiscoverv1","Url":"https://{hostname}/autodiscover/autodiscover.xml"'
|
|
|
|
return flask.Response('{'+json+'}', mimetype='application/json', status=200)
|
2022-03-15 13:41:31 +02:00
|
|
|
else:
|
2022-03-15 11:26:29 +02:00
|
|
|
return flask.abort(404)
|
|
|
|
|
2022-03-16 15:43:14 +02:00
|
|
|
@internal.route("/autoconfig/microsoft", methods=['POST'])
|
2022-03-10 11:00:51 +02:00
|
|
|
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']
|
2022-03-16 15:43:14 +02:00
|
|
|
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']
|
2022-03-17 12:39:57 +02:00
|
|
|
xml = f'''<?xml version="1.0" encoding="utf-8" ?>
|
|
|
|
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
|
|
|
|
<Response xmlns="{schema}">
|
2022-03-16 15:43:14 +02:00
|
|
|
<Account>
|
|
|
|
<AccountType>email</AccountType>
|
|
|
|
<Action>settings</Action>
|
|
|
|
<Protocol>
|
|
|
|
<Type>IMAP</Type>
|
|
|
|
<Server>{hostname}</Server>
|
|
|
|
<Port>993</Port>
|
|
|
|
<LoginName>{email}</LoginName>
|
|
|
|
<DomainRequired>on</DomainRequired>
|
|
|
|
<SPA>off</SPA>
|
|
|
|
<SSL>on</SSL>
|
2022-03-16 12:02:39 +02:00
|
|
|
</Protocol>
|
2022-03-16 15:43:14 +02:00
|
|
|
<Protocol>
|
|
|
|
<Type>SMTP</Type>
|
|
|
|
<Server>{hostname}</Server>
|
|
|
|
<Port>465</Port>
|
|
|
|
<LoginName>{email}</LoginName>
|
|
|
|
<DomainRequired>on</DomainRequired>
|
|
|
|
<SPA>off</SPA>
|
|
|
|
<SSL>on</SSL>
|
|
|
|
</Protocol>
|
|
|
|
</Account>
|
|
|
|
</Response>
|
|
|
|
</Autodiscover>'''
|
|
|
|
return flask.Response(xml, mimetype='text/xml', status=200)
|
|
|
|
except:
|
2022-03-17 12:38:22 +02:00
|
|
|
return flask.abort(400)
|
2022-03-10 11:29:11 +02:00
|
|
|
|
|
|
|
@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']
|
2022-03-17 12:39:57 +02:00
|
|
|
xml = f'''<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
|
|
|
|
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
2022-03-10 11:29:11 +02:00
|
|
|
<dict>
|
|
|
|
<key>PayloadContent</key>
|
|
|
|
<array>
|
|
|
|
<dict>
|
|
|
|
<key>EmailAccountDescription</key>
|
|
|
|
<string>{sitename}</string>
|
|
|
|
<key>EmailAccountName</key>
|
|
|
|
<string>{hostname}</string>
|
|
|
|
<key>EmailAccountType</key>
|
|
|
|
<string>EmailTypeIMAP</string>
|
|
|
|
<key>EmailAddress</key>
|
|
|
|
<string></string>
|
|
|
|
<key>IncomingMailServerAuthentication</key>
|
|
|
|
<string>EmailAuthPassword</string>
|
|
|
|
<key>IncomingMailServerHostName</key>
|
|
|
|
<string>{hostname}</string>
|
|
|
|
<key>IncomingMailServerPortNumber</key>
|
|
|
|
<integer>993</integer>
|
|
|
|
<key>IncomingMailServerUseSSL</key>
|
|
|
|
<true/>
|
|
|
|
<key>IncomingMailServerUsername</key>
|
|
|
|
<string></string>
|
|
|
|
<key>IncomingPassword</key>
|
|
|
|
<string></string>
|
|
|
|
<key>OutgoingMailServerAuthentication</key>
|
|
|
|
<string>EmailAuthPassword</string>
|
|
|
|
<key>OutgoingMailServerHostName</key>
|
|
|
|
<string>{hostname}</string>
|
|
|
|
<key>OutgoingMailServerPortNumber</key>
|
|
|
|
<integer>465</integer>
|
|
|
|
<key>OutgoingMailServerUseSSL</key>
|
|
|
|
<true/>
|
|
|
|
<key>OutgoingMailServerUsername</key>
|
|
|
|
<string></string>
|
|
|
|
<key>OutgoingPasswordSameAsIncomingPassword</key>
|
|
|
|
<true/>
|
|
|
|
<key>PayloadDescription</key>
|
|
|
|
<string>{sitename}</string>
|
|
|
|
<key>PayloadDisplayName</key>
|
|
|
|
<string>{hostname}</string>
|
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>{hostname}.email</string>
|
|
|
|
<key>PayloadOrganization</key>
|
|
|
|
<string></string>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>com.apple.mail.managed</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>72e152e2-d285-4588-9741-25bdd50c4d11</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
<key>PreventAppSheet</key>
|
|
|
|
<true/>
|
|
|
|
<key>PreventMove</key>
|
|
|
|
<false/>
|
|
|
|
<key>SMIMEEnabled</key>
|
|
|
|
<false/>
|
|
|
|
<key>disableMailRecentsSyncing</key>
|
|
|
|
<false/>
|
|
|
|
</dict>
|
|
|
|
</array>
|
|
|
|
<key>PayloadDescription</key>
|
|
|
|
<string>{hostname} - E-Mail Account Configuration</string>
|
|
|
|
<key>PayloadDisplayName</key>
|
|
|
|
<string>E-Mail Account {hostname}</string>
|
|
|
|
<key>PayloadIdentifier</key>
|
|
|
|
<string>E-Mail Account {hostname}</string>
|
|
|
|
<key>PayloadOrganization</key>
|
|
|
|
<string>{hostname}</string>
|
|
|
|
<key>PayloadRemovalDisallowed</key>
|
|
|
|
<false/>
|
|
|
|
<key>PayloadType</key>
|
|
|
|
<string>Configuration</string>
|
|
|
|
<key>PayloadUUID</key>
|
|
|
|
<string>56db43a5-d29e-4609-a908-dce94d0be48e</string>
|
|
|
|
<key>PayloadVersion</key>
|
|
|
|
<integer>1</integer>
|
|
|
|
</dict>
|
|
|
|
</plist>\r\n'''
|
|
|
|
return flask.Response(xml, mimetype='text/xml', status=200)
|