email: Implement auto-discovery

This commit is contained in:
fliu 2021-07-29 21:05:17 +00:00 committed by Sunil Mohan Adapa
parent 355cc84a1b
commit cdfef82bf6
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
4 changed files with 55 additions and 0 deletions

View File

@ -24,3 +24,18 @@
TKTAuthToken "admin"
</IfModule>
</Location>
<Location "/plinth/apps/email_server/*.xml">
# Require SSO
Include includes/freedombox-single-sign-on.conf
<IfModule mod_auth_pubtkt.c>
TKTAuthToken "admin"
</IfModule>
</Location>
<Location "/.well-known/autoconfig/mail/config-v1.1.xml">
ProxyPass http://127.0.0.1:8000/plinth/apps/email_server/config.xml
RequestHeader unset Cookie
Header unset Set-Cookie
Include includes/freedombox-robots.conf
</Location>

View File

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<clientConfig version="1.1">
<emailProvider id="{{ host }}">
<domain>{{ host }}</domain>
<displayName>FreedomBox Mail</displayName>
<displayShortName>FBXMail</displayShortName>
<incomingServer type="imap">
<hostname>{{ host }}</hostname>
<port>993</port>
<socketType>SSL</socketType>
<username>%EMAILLOCALPART%</username>
<authentication>password-cleartext</authentication>
</incomingServer>
<outgoingServer type="smtp">
<hostname>{{ host }}</hostname>
<port>465</port>
<socketType>SSL</socketType>
<username>%EMAILLOCALPART%</username>
<authentication>password-cleartext</authentication>
</outgoingServer>
</emailProvider>
</clientConfig>

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
from django.urls import path
from plinth.utils import non_admin_view
from stronghold.decorators import public
from . import views
@ -13,4 +14,6 @@ urlpatterns = [
non_admin_view(views.MyMailView.as_view()), name='my_mail'),
path('apps/email_server/my_aliases',
non_admin_view(views.AliasView.as_view())),
path('apps/email_server/config.xml', public(views.XmlView.as_view())),
]

View File

@ -273,3 +273,18 @@ class DomainView(TabMixin, TemplateView):
changed[key] = value
audit.domain.set_keys(changed)
return self.render_to_response(self.get_context_data())
class XmlView(TemplateView):
template_name = 'config.xml'
def render_to_response(self, *args, **kwargs):
if 200 <= kwargs.get('status', 200) < 300:
kwargs['content_type'] = 'text/xml; charset=utf-8'
response = super().render_to_response(*args, **kwargs)
return response
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['host'] = self.request.get_host()
return context