From 523cee1680ab5ef8f2a02e239a5e4f47a2c5b719 Mon Sep 17 00:00:00 2001 From: Florent Daigniere Date: Thu, 10 Mar 2022 09:28:10 +0100 Subject: [PATCH] Autoconfig mozilla-style --- core/admin/mailu/internal/views/__init__.py | 2 +- core/admin/mailu/internal/views/autoconfig.py | 42 +++++++++++++++ core/nginx/conf/nginx.conf | 7 +++ docs/faq.rst | 52 ------------------- 4 files changed, 50 insertions(+), 53 deletions(-) create mode 100644 core/admin/mailu/internal/views/autoconfig.py diff --git a/core/admin/mailu/internal/views/__init__.py b/core/admin/mailu/internal/views/__init__.py index 762b2a38..5ebd6ff8 100644 --- a/core/admin/mailu/internal/views/__init__.py +++ b/core/admin/mailu/internal/views/__init__.py @@ -1,3 +1,3 @@ __all__ = [ - 'auth', 'postfix', 'dovecot', 'fetch', 'rspamd' + 'auth', 'autoconfig', 'postfix', 'dovecot', 'fetch', 'rspamd' ] diff --git a/core/admin/mailu/internal/views/autoconfig.py b/core/admin/mailu/internal/views/autoconfig.py new file mode 100644 index 00000000..3538e756 --- /dev/null +++ b/core/admin/mailu/internal/views/autoconfig.py @@ -0,0 +1,42 @@ +from mailu.internal import internal + +from flask import current_app as app +import flask + +@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) diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index b9bb20b7..6d416c16 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -120,6 +120,13 @@ http { add_header X-XSS-Protection '1; mode=block'; add_header Referrer-Policy 'same-origin'; + # mozilla autoconfiguration + location ^~ /.well-known/autoconfig/mail/config-v1.1.xml { + rewrite /.well-known/autoconfig/mail/config-v1.1.xml /internal/autoconfig/mozilla break; + include /etc/nginx/proxy.conf; + proxy_pass http://$admin; + } + {% if TLS_FLAVOR == 'mail-letsencrypt' %} location ^~ /.well-known/acme-challenge/ { proxy_pass http://127.0.0.1:8008; diff --git a/docs/faq.rst b/docs/faq.rst index fe105403..4221de88 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -396,58 +396,6 @@ Mailu can serve an `MTA-STS policy`_; To configure it you will need to: .. _`1798`: https://github.com/Mailu/Mailu/issues/1798 .. _`MTA-STS policy`: https://datatracker.ietf.org/doc/html/rfc8461 -How do I setup client autoconfiguration? -```````````````````````````````````````` - -Mailu can serve an `XML file for autoconfiguration`_; To configure it you will need to: - -1. add ``autoconfig.example.com`` to the ``HOSTNAMES`` configuration variable (and ensure that a valid SSL certificate is available for it; this may mean restarting your smtp container) - -2. configure an override with the policy itself; for example, your ``overrides/nginx/autoconfiguration.conf`` could read: - -.. code-block:: bash - - location ^~ /mail/config-v1.1.xml { - return 200 " - - - %EMAILDOMAIN% - - Email - Email - - - mailu.example.com - 993 - SSL - %EMAILADDRESS% - password-cleartext - - - - mailu.example.com - 465 - SSL - %EMAILADDRESS% - password-cleartext - true - true - - - - Configure your email client - - - \r\n"; - } - -3. setup the appropriate DNS/CNAME record (``autoconfig.example.com`` -> ``mailu.example.com``). - -*issue reference:* `224`_. - -.. _`224`: https://github.com/Mailu/Mailu/issues/224 -.. _`XML file for autoconfiguration`: https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat - Technical issues ----------------