Skip to content

Commit

Permalink
Merge pull request #1 from Monogramm/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
madmath03 authored Mar 11, 2019
2 parents 87c6bd1 + 654daa5 commit 38a0026
Show file tree
Hide file tree
Showing 9 changed files with 612 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM node:8-alpine

LABEL maintainer="Mathieu BRUNOT <mathieu.brunot at monogramm dot io>"

EXPOSE 8000
WORKDIR /app
COPY package.json yarn.lock index.js settings.js /app/
Expand Down
62 changes: 44 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# autodiscover-email-settings

[![Docker Pulls](https://img.shields.io/docker/pulls/weboaks/autodiscover-email-settings.svg)](https://hub.docker.com/r/weboaks/autodiscover-email-settings/) [![Docker layers](https://images.microbadger.com/badges/image/weboaks/autodiscover-email-settings.svg)](https://microbadger.com/images/weboaks/autodiscover-email-settings)
[![Docker Pulls](https://img.shields.io/docker/pulls/monogramm/autodiscover-email-settings.svg)](https://hub.docker.com/r/monogramm/autodiscover-email-settings/)
[![](https://images.microbadger.com/badges/version/monogramm/autodiscover-email-settings.svg)](https://microbadger.com/images/monogramm/autodiscover-email-settings)
[![Docker layers](https://images.microbadger.com/badges/image/monogramm/autodiscover-email-settings.svg)](https://microbadger.com/images/monogramm/autodiscover-email-settings)

This service is created to autodiscover your provider email settings.

It provides IMAP/SMTP Autodiscover capabilities on Microsoft Outlook/Apple Mail, Autoconfig capabilities for Thunderbird, and Configuration Profiles for iOS/Apple Mail.
**A simple support page is also available at the root of the autodiscover domain.**

### DNS settings

Expand Down Expand Up @@ -32,7 +35,8 @@ Replace above variables with data according to this table

### Usage

[traefik](https://github.com/containous/traefik) can proxy your containers on docker, on docker swarm, and on a wide range of orchestrators
[traefik](https://github.com/containous/traefik) can proxy your containers on docker, on docker swarm, and on a wide range of orchestrators.
You can also achieve this with another proxy like [Nginx](https://www.nginx.com/) for instance.

#### docker

Expand All @@ -41,13 +45,20 @@ version: '2'

services:
autodiscover-domain-com:
image: weboaks/autodiscover-email-settings:latest
image: monogramm/autodiscover-email-settings:latest
environment:
- DOMAIN=domain.com
- IMAP_HOST=imap.domain.com
- IMAP_PORT=993
- SMTP_HOST=smtp.domain.com
- SMTP_PORT=465
- COMPANY_NAME=Company
- SUPPORT_URL=https://autodiscover.domain.com
- DOMAIN=domain.com
- IMAP_HOST=imap.domain.com
- IMAP_PORT=993
- IMAP_SOCKET=SSL
- SMTP_HOST=smtp.domain.com
- SMTP_PORT=587
- SMTP_SOCKET=STARTTLS
- PROFILE_IDENTIFIER=com.domain.autodiscover
- PROFILE_UUID=48C88203-4DB9-49E8-B593-4831903605A0
- MAIL_UUID=7A981A9E-D5D0-4EF8-87FE-39FD6A506FAC
labels:
- "traefik.port=8000"
- "traefik.frontend.rule=Host:autoconfig.domain.com,autodiscover.domain.com"
Expand All @@ -60,13 +71,20 @@ version: '3'

services:
autodiscover-domain-com:
image: weboaks/autodiscover-email-settings:latest
image: monogramm/autodiscover-email-settings:latest
environment:
- DOMAIN=domain.com
- IMAP_HOST=imap.domain.com
- IMAP_PORT=993
- SMTP_HOST=smtp.domain.com
- SMTP_PORT=465
- COMPANY_NAME=Company
- SUPPORT_URL=https://autodiscover.domain.com
- DOMAIN=domain.com
- IMAP_HOST=imap.domain.com
- IMAP_PORT=993
- IMAP_SOCKET=SSL
- SMTP_HOST=smtp.domain.com
- SMTP_PORT=587
- SMTP_SOCKET=STARTTLS
- PROFILE_IDENTIFIER=com.domain.autodiscover
- PROFILE_UUID=48C88203-4DB9-49E8-B593-4831903605A0
- MAIL_UUID=7A981A9E-D5D0-4EF8-87FE-39FD6A506FAC
deploy:
replicas: 1
labels:
Expand All @@ -76,15 +94,23 @@ services:
### Credits
Inspired from https://github.com/johansmitsnl/docker-email-autodiscover, but with https://github.com/Tiliq/autodiscover.xml instead of https://github.com/gronke/email-autodiscover to allow a much lighter ([![](https://images.microbadger.com/badges/image/weboaks/autodiscover-email-settings.svg)](https://microbadger.com/images/weboaks/autodiscover-email-settings)) image based of node on alpine instead of apache on debian ([![](https://images.microbadger.com/badges/image/jsmitsnl/docker-email-autodiscover.svg)](https://microbadger.com/images/jsmitsnl/docker-email-autodiscover))
Inspired from https://github.com/sylvaindumont/autodiscover.xml, but without the few restrictions mentioned in the original project notes and with a simple support page to allow manual setup and iOS profile download.
The original project was inspired from https://github.com/johansmitsnl/docker-email-autodiscover, but with https://github.com/Tiliq/autodiscover.xml instead of https://github.com/gronke/email-autodiscover to allow a much lighter ([![](https://images.microbadger.com/badges/image/weboaks/autodiscover-email-settings.svg)](https://microbadger.com/images/weboaks/autodiscover-email-settings)) image based of node on alpine instead of apache on debian ([![](https://images.microbadger.com/badges/image/jsmitsnl/docker-email-autodiscover.svg)](https://microbadger.com/images/jsmitsnl/docker-email-autodiscover))
### Notes
The above autoconfiguration methods assume the following:
* Username: `{{email}}` (Entire email address)
* Encryption: SSL/TLS
.
* If username does not contain `@`, full email address will be generated based on domain settings

### Links

* Mozilla [Autoconfig configuration](https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Autoconfiguration/FileFormat/HowTo)
* Microsoft [Exchange Command Reference](https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-ascmd/1a3490f1-afe1-418a-aa92-6f630036d65a)
* Apple [ConfigurationProfile reference](https://developer.apple.com/library/archive/featuredarticles/iPhoneConfigurationProfileRef/index.html)

* [Bootstrap](https://getbootstrap.com/), [jQuery](https://jquery.com/) and [Popper.js](https://popper.js.org/) used for default support page

### License

Expand Down
32 changes: 30 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"papertrail"
],
"env": {
"COMPANY_NAME": {
"description": "Your company name",
"value": "Autodiscover"
},
"SUPPORT_URL": {
"description": "Your company support URL",
"value": "autodiscover.example.com"
},
"DOMAIN": {
"description": "Your default domain",
"value": "example.com"
Expand All @@ -17,16 +25,36 @@
"value": "imap.example.com"
},
"IMAP_PORT": {
"description": "Your Secure IMAP Port",
"description": "Your IMAP Port",
"value": "993"
},
"IMAP_SOCKET": {
"description": "Your IMAP Socket",
"value": "SSL"
},
"SMTP_HOST": {
"description": "Your SMTP Host",
"value": "smtp.example.com"
},
"SMTP_PORT": {
"description": "Your Secure SMTP Port",
"description": "Your SMTP Port",
"value": "587"
},
"SMTP_SOCKET": {
"description": "Your SMTP Socket",
"value": "STARTTLS"
},
"PROFILE_IDENTIFIER": {
"description": "Your mobile profile identifier",
"value": "com.example.autodiscover"
},
"PROFILE_UUID": {
"description": "Your mobile profile globally unique ID",
"value": "48C88203-4DB9-49E8-B593-4831903605A0"
},
"MAIL_UUID": {
"description": "Your mail profile globally unique ID",
"value": "7A981A9E-D5D0-4EF8-87FE-39FD6A506FAC"
}
}
}
86 changes: 71 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,116 @@ const body = require('koa-buddy');
const router = require('koa-router')();
const settings = require('./settings.js');

function findChild(name, children) {
function findChild(name, children, def = null) {
for (let child of children) {
if (child.name === name) {
return child;
}
}
return def;
}

// Microsoft Outlook / Apple Mail
router.post('/Autodiscover/Autodiscover.xml', function *autodiscover() {
function *autodiscover() {
this.set('Content-Type', 'application/xml');

const request = findChild('Request', this.request.body.root.children);
const schema = findChild('AcceptableResponseSchema', request.children);
const email = findChild('EMailAddress', request.children).content;
const username = email.split('@')[0];
const domain = email.split('@')[1];
const request = this.request.body && this.request.body.root ?
findChild('Request', this.request.body.root.children) :
null;
const schema = request !== null ?
findChild('AcceptableResponseSchema', request.children) :
null;
const xmlns = schema !== null ?
schema.content :
'http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006';

let email = request !== null ?
findChild('EMailAddress', request.children) :
null;

let username;
let domain;
if ( email === null || email.content === null ) {
email = '';
username = '';
domain = settings.domain;
} else if ( ~email.indexOf('@') ) {
email = email.content;
username = email.split('@')[0];
domain = email.split('@')[1];
} else {
username = email.content;
domain = settings.domain;
email = username + '@' + domain;
}

const imapenc = settings.imap.socket == 'STARTTLS' ? 'TLS' : settings.imap.socket;
const smtpenc = settings.smtp.socket == 'STARTTLS' ? 'TLS' : settings.smtp.socket;

yield this.render('autodiscover', {
schema: schema.content,
schema: xmlns,
email,
username,
domain
domain,
imapenc,
smtpenc
});
});
}

router.get('/autodiscover/autodiscover.xml', autodiscover);
router.post('/autodiscover/autodiscover.xml', autodiscover);
router.get('/Autodiscover/Autodiscover.xml', autodiscover);
router.post('/Autodiscover/Autodiscover.xml', autodiscover);

// Thunderbird
router.get('/mail/config-v1.1.xml', function *autoconfig() {
this.set('Content-Type', 'application/xml');
yield this.render('autoconfig');
});

// iOS / Apple Mail (/[email protected])
// iOS / Apple Mail (/[email protected] or /email.mobileconfig?email=username)
router.get('/email.mobileconfig', function *autoconfig() {
const email = this.request.query.email;
let email = this.request.query.email;

if (!email || !~email.indexOf('@')) {
if (!email) {
this.status = 400;

return;
}

const domain = email.split('@').pop();
let username;
let domain;
if (~email.indexOf('@') ) {
username = email.split('@')[0];
domain = email.split('@')[1];
} else {
username = email;
domain = settings.domain;
email = username + '@' + domain;
}

const filename = `${domain}.mobileconfig`;

const inssl = settings.imap.socket == 'SSL' || settings.imap.socket == 'STARTTLS' ? 'true' : 'false';
const outssl = settings.smtp.socket == 'SSL' || settings.smtp.socket == 'STARTTLS' ? 'true' : 'false';

this.set('Content-Type', 'application/x-apple-aspen-config; chatset=utf-8');
this.set('Content-Disposition', `attachment; filename="${filename}"`);

yield this.render('mobileconfig', {
email,
domain
username,
domain,
inssl,
outssl
});
});

// Generic support page
router.get('/', function *index() {
yield this.render('index.html');
});

app.context.render = swig({
root: path.join(__dirname, 'views'),
autoescape: true,
Expand Down
17 changes: 15 additions & 2 deletions settings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
module.exports = {
info: {
name: process.env.COMPANY_NAME,
url: process.env.SUPPORT_URL
},
domain: process.env.DOMAIN,
imap: {
host: process.env.IMAP_HOST,
port: process.env.IMAP_PORT
port: process.env.IMAP_PORT,
socket: process.env.IMAP_SOCKET
},
smtp: {
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT
port: process.env.SMTP_PORT,
socket: process.env.SMTP_SOCKET
},
mobile: {
identifier: process.env.PROFILE_IDENTIFIER,
uuid: process.env.PROFILE_UUID,
mail: {
uuid: process.env.MAIL_UUID,
}
}
};
12 changes: 9 additions & 3 deletions views/autoconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
<emailProvider id="{{domain}}">
<domain>{{domain}}</domain>

<displayName>%EMAILADDRESS%</displayName>
<displayName>{{info.name}} Email</displayName>
<displayShortName>%EMAILLOCALPART%</displayShortName>

<incomingServer type="imap">
<hostname>{{imap.host}}</hostname>
<port>{{imap.port}}</port>
<socketType>SSL</socketType>
<socketType>{{imap.socket}}</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</incomingServer>

<outgoingServer type="smtp">
<hostname>{{smtp.host}}</hostname>
<port>{{smtp.port}}</port>
<socketType>SSL</socketType>
<socketType>{{smtp.socket}}</socketType>
<authentication>password-cleartext</authentication>
<username>%EMAILADDRESS%</username>
</outgoingServer>

<documentation url="{{info.url}}">
<descr lang="fr">Description des paramètres</descr>
<descr lang="de">Allgemeine Beschreibung der Einstellungen</descr>
<descr lang="en">Generic settings page</descr>
</documentation>
</emailProvider>
</clientConfig>
Loading

0 comments on commit 38a0026

Please sign in to comment.