diff --git a/src/autoconfig.xml.ejs b/src/autoconfig.xml.ejs index 15a34acbc..ce228d217 100644 --- a/src/autoconfig.xml.ejs +++ b/src/autoconfig.xml.ejs @@ -5,14 +5,14 @@ Cloudron Mail Cloudron - <%= mailFqdn %> + <%= fqdn %> 993 SSL password-cleartext %EMAILADDRESS% - <%= mailFqdn %> + <%= fqdn %> 587 STARTTLS password-cleartext @@ -20,7 +20,7 @@ true - <%= mailFqdn %> + <%= fqdn %> 995 SSL %EMAILADDRESS% diff --git a/src/cloudron.js b/src/cloudron.js index 0e47651a8..9f0ec4e18 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -32,6 +32,7 @@ const apps = require('./apps.js'), dns = require('./dns.js'), dockerProxy = require('./dockerproxy.js'), eventlog = require('./eventlog.js'), + mailServer = require('./mailserver.js'), moment = require('moment-timezone'), network = require('./network.js'), oidc = require('./oidc.js'), @@ -141,7 +142,7 @@ async function getConfig() { consoleServerOrigin: await appstore.getConsoleServerOrigin(), adminDomain: settings.dashboardDomain(), adminFqdn: settings.dashboardFqdn(), - mailFqdn: settings.mailFqdn(), + mailFqdn: await mailServer.getLocation().fqdn, version: constants.VERSION, ubuntuVersion, isDemo: constants.DEMO, diff --git a/src/dns.js b/src/dns.js index 5456cda4c..c9d3423f0 100644 --- a/src/dns.js +++ b/src/dns.js @@ -30,6 +30,7 @@ const apps = require('./apps.js'), domains = require('./domains.js'), ipaddr = require('ipaddr.js'), mail = require('./mail.js'), + mailServer = require('./mailserver.js'), network = require('./network.js'), promiseRetry = require('./promise-retry.js'), safe = require('safetydance'), @@ -279,7 +280,7 @@ async function syncDnsRecords(options, progressCallback) { if (options.domain) allDomains = allDomains.filter(d => d.domain === options.domain); - const mailSubdomain = settings.mailFqdn().substr(0, settings.mailFqdn().length - settings.mailDomain().length - 1); + const { domain:mailDomain, fqdn:mailFqdn, subdomain:mailSubdomain } = await mailServer.getLocation(); const allApps = await apps.list(); @@ -292,7 +293,7 @@ async function syncDnsRecords(options, progressCallback) { let locations = []; if (domain.domain === settings.dashboardDomain()) locations.push({ subdomain: constants.DASHBOARD_SUBDOMAIN, domain: settings.dashboardDomain() }); - if (domain.domain === settings.mailDomain() && settings.mailFqdn() !== settings.dashboardFqdn()) locations.push({ subdomain: mailSubdomain, domain: settings.mailDomain() }); + if (domain.domain === mailDomain && mailFqdn !== settings.dashboardFqdn()) locations.push({ subdomain: mailSubdomain, domain: mailDomain }); for (const app of allApps) { const appLocations = [{ subdomain: app.subdomain, domain: app.domain }] diff --git a/src/domains.js b/src/domains.js index 1b5e8031f..9ba42551b 100644 --- a/src/domains.js +++ b/src/domains.js @@ -271,7 +271,9 @@ async function del(domain, auditSource) { assert.strictEqual(typeof auditSource, 'object'); if (domain === settings.dashboardDomain()) throw new BoxError(BoxError.CONFLICT, 'Cannot remove admin domain'); - if (domain === settings.mailDomain()) throw new BoxError(BoxError.CONFLICT, 'Cannot remove mail domain. Change the mail server location first'); + + const { domain:mailDomain } = await mailServer.getLocation(); + if (domain === mailDomain) throw new BoxError(BoxError.CONFLICT, 'Cannot remove mail domain. Change the mail server location first'); let queries = [ { query: 'DELETE FROM mail WHERE domain = ?', args: [ domain ] }, diff --git a/src/mail.js b/src/mail.js index ae16f49d0..35b92b4f7 100644 --- a/src/mail.js +++ b/src/mail.js @@ -77,7 +77,6 @@ const assert = require('assert'), path = require('path'), safe = require('safetydance'), services = require('./services.js'), - settings = require('./settings.js'), shell = require('./shell.js'), superagent = require('superagent'), validator = require('validator'), @@ -294,7 +293,7 @@ async function checkSpf(domain, mailFqdn) { name: '@', type: 'TXT', value: null, - expected: 'v=spf1 a:' + mailFqdn + ' ~all', + expected: `v=spf1 a:${mailFqdn} ~all`, status: false, errorMessage: '' }; @@ -310,14 +309,14 @@ async function checkSpf(domain, mailFqdn) { let txtRecord = txtRecords[i].join(''); // https://agari.zendesk.com/hc/en-us/articles/202952749-How-long-can-my-SPF-record-be- if (txtRecord.indexOf('v=spf1 ') !== 0) continue; // not SPF spf.value = txtRecord; - spf.status = spf.value.indexOf(' a:' + settings.mailFqdn()) !== -1; + spf.status = spf.value.indexOf(` a:${mailFqdn}`) !== -1; break; } if (spf.status) { spf.expected = spf.value; } else if (i !== txtRecords.length) { - spf.expected = 'v=spf1 a:' + settings.mailFqdn() + ' ' + spf.value.slice('v=spf1 '.length); + spf.expected = `v=spf1 a:${mailFqdn} ` + spf.value.slice('v=spf1 '.length); } return spf; @@ -332,7 +331,7 @@ async function checkMx(domain, mailFqdn) { name: '@', type: 'MX', value: null, - expected: '10 ' + mailFqdn + '.', + expected: `10 ${mailFqdn}.`, status: false, errorMessage: '' }; @@ -532,7 +531,7 @@ async function getStatus(domain) { relay: {} // { status, value } always checked }; - const mailFqdn = settings.mailFqdn(); + const { fqdn } = await mailServer.getLocation(); const mailDomain = await getDomain(domain); if (!mailDomain) throw new BoxError(BoxError.NOT_FOUND, 'mail domain not found'); @@ -540,7 +539,7 @@ async function getStatus(domain) { const checks = []; if (mailDomain.enabled) { checks.push( - { what: 'dns.mx', promise: checkMx(domain, mailFqdn) }, + { what: 'dns.mx', promise: checkMx(domain, fqdn) }, { what: 'dns.dmarc', promise: checkDmarc(domain) } ); } @@ -548,9 +547,9 @@ async function getStatus(domain) { if (mailDomain.relay.provider === 'cloudron-smtp') { // these tests currently only make sense when using Cloudron's SMTP server at this point checks.push( - { what: 'dns.spf', promise: checkSpf(domain, mailFqdn) }, + { what: 'dns.spf', promise: checkSpf(domain, fqdn) }, { what: 'dns.dkim', promise: checkDkim(mailDomain) }, - { what: 'dns.ptr', promise: checkPtr(mailFqdn) }, + { what: 'dns.ptr', promise: checkPtr(fqdn) }, { what: 'relay', promise: checkOutboundPort25() }, { what: 'rbl', promise: checkRblStatus(domain) }, ); @@ -719,7 +718,8 @@ async function upsertDnsRecords(domain, mailFqdn) { async function setDnsRecords(domain) { assert.strictEqual(typeof domain, 'string'); - await upsertDnsRecords(domain, settings.mailFqdn()); + const { fqdn } = await mailServer.getLocation(); + await upsertDnsRecords(domain, fqdn); } async function clearDomains() { diff --git a/src/mailserver.js b/src/mailserver.js index 60eefd118..93d6ae21a 100644 --- a/src/mailserver.js +++ b/src/mailserver.js @@ -14,8 +14,10 @@ exports = module.exports = { getMailAuth, getLocation, - setLocation, // triggers the change task - changeLocation, // does the actual changing + startChangeLocation, + changeLocation, + + initLocation, DEFAULT_MEMORY_LIMIT: 512 * 1024 * 1024, }; @@ -194,8 +196,9 @@ async function restart() { if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return; const mailConfig = await services.getServiceConfig('mail'); - debug(`restart: restarting mail container with mailFqdn:${settings.mailFqdn()} mailDomain:${settings.mailDomain()}`); - await configureMail(settings.mailFqdn(), settings.mailDomain(), mailConfig); + const { domain, fqdn } = await getLocation(); + debug(`restart: restarting mail container with mailFqdn:${fqdn} mailDomain:${domain}`); + await configureMail(fqdn, domain, mailConfig); } async function start(existingInfra) { @@ -220,10 +223,11 @@ async function restartIfActivated() { async function onDomainAdded(domain) { assert.strictEqual(typeof domain, 'string'); - if (!settings.mailFqdn()) return; // mail domain is not set yet (when provisioning) + const { fqdn } = await getLocation(); + if (!fqdn) return; // mail domain is not set yet (when provisioning) debug(`onDomainAdded: configuring mail for added domain ${domain}`); - await mail.upsertDnsRecords(domain, settings.mailFqdn()); + await mail.upsertDnsRecords(domain, fqdn); await restartIfActivated(); } @@ -247,18 +251,21 @@ async function checkCertificate() { } async function getLocation() { - const domain = settings.mailDomain(), fqdn = settings.mailFqdn(); + const domain = await settings.get(settings.MAIL_DOMAIN_KEY); + const fqdn = await settings.get(settings.MAIL_FQDN_KEY); + + if (!domain || !fqdn) return {}; + const subdomain = fqdn.substr(0, fqdn.length - domain.length - 1); - return { domain, subdomain }; + return { domain, fqdn, subdomain }; } async function changeLocation(auditSource, progressCallback) { assert.strictEqual(typeof auditSource, 'object'); assert.strictEqual(typeof progressCallback, 'function'); - const fqdn = settings.mailFqdn(), domain = settings.mailDomain(); - const subdomain = fqdn.substr(0, fqdn.length - domain.length - 1); + const { fqdn, domain, subdomain } = await getLocation(); let progress = 20; progressCallback({ percent: progress, message: `Setting up DNS of certs of mail server ${fqdn}` }); @@ -280,7 +287,15 @@ async function changeLocation(auditSource, progressCallback) { await restartIfActivated(); } -async function setLocation(subdomain, domain, auditSource) { +async function initLocation(mailDomain, mailFqdn) { + assert.strictEqual(typeof mailDomain, 'string'); + assert.strictEqual(typeof mailFqdn, 'string'); + + await settings.set(settings.MAIL_DOMAIN_KEY, mailDomain); + await settings.set(settings.MAIL_FQDN_KEY, mailFqdn); +} + +async function startChangeLocation(subdomain, domain, auditSource) { assert.strictEqual(typeof subdomain, 'string'); assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof auditSource, 'object'); @@ -292,7 +307,7 @@ async function setLocation(subdomain, domain, auditSource) { const fqdn = dns.fqdn(subdomain, domain); - await settings.setMailLocation(domain, fqdn); + await initLocation(domain, fqdn); const taskId = await tasks.add(tasks.TASK_CHANGE_MAIL_LOCATION, [ auditSource ]); tasks.startTask(taskId, {}); diff --git a/src/provision.js b/src/provision.js index 7e8a009d2..70c36be78 100644 --- a/src/provision.js +++ b/src/provision.js @@ -22,6 +22,7 @@ const appstore = require('./appstore.js'), eventlog = require('./eventlog.js'), fs = require('fs'), mail = require('./mail.js'), + mailServer = require('./mailserver.js'), mounts = require('./mounts.js'), network = require('./network.js'), reverseProxy = require('./reverseproxy.js'), @@ -113,7 +114,7 @@ async function setup(domainConfig, ipv4Config, auditSource) { dkimSelector: 'cloudron' }; - await settings.setMailLocation(domain, `${constants.DASHBOARD_SUBDOMAIN}.${domain}`); // default mail location. do this before we add the domain for upserting mail DNS + await mailServer.initLocation(domain, `${constants.DASHBOARD_SUBDOMAIN}.${domain}`); // default mail location. do this before we add the domain for upserting mail DNS await domains.add(domain, data, auditSource); await network.setIPv4Config(ipv4Config); diff --git a/src/reverseproxy.js b/src/reverseproxy.js index b989ed27a..b80ee9ef5 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -301,7 +301,8 @@ async function getCertificate(location) { } async function getMailCertificate() { - return await getCertificate({ domain: settings.mailDomain(), fqdn: settings.mailFqdn(), certificate: null, type: apps.LOCATION_TYPE_MAIL }); + const { domain, fqdn } = await mailServer.getLocation(); + return await getCertificate({ domain, fqdn, certificate: null, type: apps.LOCATION_TYPE_MAIL }); } async function getDirectoryServerCertificate() { @@ -642,7 +643,8 @@ async function checkCerts(options, auditSource, progressCallback) { assert.strictEqual(typeof progressCallback, 'function'); let locations = []; - if (settings.dashboardFqdn() !== settings.mailFqdn()) locations.push({ domain: settings.mailDomain(), fqdn: settings.mailFqdn(), certificate: null, type: apps.LOCATION_TYPE_MAIL }); + const { domain:mailDomain, fqdn:mailFqdn } = await mailServer.getLocation(); + if (settings.dashboardFqdn() !== mailFqdn) locations.push({ domain: mailDomain, fqdn: mailFqdn, certificate: null, type: apps.LOCATION_TYPE_MAIL }); locations.push({ domain: settings.dashboardDomain(), fqdn: settings.dashboardFqdn(), certificate: null, type: apps.LOCATION_TYPE_DASHBOARD }); const allApps = (await apps.list()).filter(app => app.runState !== apps.RSTATE_STOPPED); diff --git a/src/routes/mailserver.js b/src/routes/mailserver.js index 59de37421..764dd9b24 100644 --- a/src/routes/mailserver.js +++ b/src/routes/mailserver.js @@ -78,7 +78,7 @@ async function setLocation(req, res, next) { if (typeof req.body.domain !== 'string') return next(new HttpError(400, 'domain must be a string')); if (typeof req.body.subdomain !== 'string') return next(new HttpError(400, 'subdomain must be a string')); - const [error, taskId] = await safe(mailServer.setLocation(req.body.subdomain, req.body.domain, AuditSource.fromRequest(req))); + const [error, taskId] = await safe(mailServer.startChangeLocation(req.body.subdomain, req.body.domain, AuditSource.fromRequest(req))); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(202, { taskId })); diff --git a/src/routes/test/common.js b/src/routes/test/common.js index 22f3f9b32..23bd30542 100644 --- a/src/routes/test/common.js +++ b/src/routes/test/common.js @@ -53,6 +53,7 @@ exports = module.exports = { dashboardDomain: 'test.example.com', dashboardFqdn: 'my.test.example.com', appstoreToken: 'toktok', + mailFqdn: 'my.test.example.com', serverUrl: `http://localhost:${constants.PORT}`, }; diff --git a/src/routes/test/mail-test.js b/src/routes/test/mail-test.js index a5e34a754..774c7f344 100644 --- a/src/routes/test/mail-test.js +++ b/src/routes/test/mail-test.js @@ -13,7 +13,7 @@ const common = require('./common.js'), _ = require('underscore'); describe('Mail API', function () { - const { setup, cleanup, serverUrl, owner, dashboardDomain } = common; + const { setup, cleanup, serverUrl, owner, dashboardDomain, mailFqdn } = common; let publicKey; before(async () => { @@ -136,13 +136,13 @@ describe('Mail API', function () { expect(response.body.dns.mx).to.be.an('object'); expect(response.body.dns.mx.type).to.eql('MX'); expect(response.body.dns.mx.value).to.eql(null); - expect(response.body.dns.mx.expected).to.eql('10 ' + settings.mailFqdn() + '.'); + expect(response.body.dns.mx.expected).to.eql('10 ' + mailFqdn + '.'); expect(response.body.dns.mx.status).to.eql(false); expect(response.body.dns.ptr).to.be.an('object'); expect(response.body.dns.ptr.type).to.eql('PTR'); // expect(response.body.ptr.value).to.eql(null); this will be anything random - expect(response.body.dns.ptr.expected).to.eql(settings.mailFqdn()); + expect(response.body.dns.ptr.expected).to.eql(mailFqdn); expect(response.body.dns.ptr.status).to.eql(false); }); @@ -176,11 +176,11 @@ describe('Mail API', function () { expect(response.body.dns.mx).to.be.an('object'); expect(response.body.dns.mx.status).to.eql(false); - expect(response.body.dns.mx.expected).to.eql('10 ' + settings.mailFqdn() + '.'); + expect(response.body.dns.mx.expected).to.eql('10 ' + mailFqdn + '.'); expect(response.body.dns.mx.value).to.eql(null); expect(response.body.dns.ptr).to.be.an('object'); - expect(response.body.dns.ptr.expected).to.eql(settings.mailFqdn()); + expect(response.body.dns.ptr.expected).to.eql(mailFqdn); expect(response.body.dns.ptr.status).to.eql(false); // expect(response.body.ptr.value).to.eql(null); this will be anything random }); @@ -188,7 +188,7 @@ describe('Mail API', function () { it('succeeds with all different spf, dkim, dmarc, mx, ptr records', async function () { clearDnsAnswerQueue(); - dnsAnswerQueue[mxDomain].MX = [ { priority: '20', exchange: settings.mailFqdn() }, { priority: '10', exchange: 'some.other.server' } ]; + dnsAnswerQueue[mxDomain].MX = [ { priority: '20', exchange: mailFqdn }, { priority: '10', exchange: 'some.other.server' } ]; dnsAnswerQueue[dmarcDomain].TXT = [['v=DMARC2; p=reject; pct=100']]; dnsAnswerQueue[dkimDomain].TXT = [['v=DKIM2; t=s; p=' + publicKey]]; dnsAnswerQueue[spfDomain].TXT = [['v=spf1 a:random.com ~all']]; @@ -215,11 +215,11 @@ describe('Mail API', function () { expect(response.body.dns.mx).to.be.an('object'); expect(response.body.dns.mx.status).to.eql(true); - expect(response.body.dns.mx.expected).to.eql('10 ' + settings.mailFqdn() + '.'); - expect(response.body.dns.mx.value).to.eql('20 ' + settings.mailFqdn() + '. 10 some.other.server.'); + expect(response.body.dns.mx.expected).to.eql('10 ' + mailFqdn + '.'); + expect(response.body.dns.mx.value).to.eql('20 ' + mailFqdn + '. 10 some.other.server.'); expect(response.body.dns.ptr).to.be.an('object'); - expect(response.body.dns.ptr.expected).to.eql(settings.mailFqdn()); + expect(response.body.dns.ptr.expected).to.eql(mailFqdn); expect(response.body.dns.ptr.status).to.eql(false); // expect(response.body.ptr.value).to.eql(null); this will be anything random @@ -229,7 +229,7 @@ describe('Mail API', function () { it('succeeds with existing embedded spf', async function () { clearDnsAnswerQueue(); - dnsAnswerQueue[spfDomain].TXT = [['v=spf1 a:example.com a:' + settings.mailFqdn() + ' ~all']]; + dnsAnswerQueue[spfDomain].TXT = [['v=spf1 a:example.com a:' + mailFqdn + ' ~all']]; const response = await superagent.get(`${serverUrl}/api/v1/mail/${dashboardDomain}/status`) .query({ access_token: owner.token }); @@ -239,8 +239,8 @@ describe('Mail API', function () { expect(response.body.dns.spf).to.be.an('object'); expect(response.body.dns.spf.domain).to.eql(spfDomain); expect(response.body.dns.spf.type).to.eql('TXT'); - expect(response.body.dns.spf.value).to.eql('v=spf1 a:example.com a:' + settings.mailFqdn() + ' ~all'); - expect(response.body.dns.spf.expected).to.eql('v=spf1 a:example.com a:' + settings.mailFqdn() + ' ~all'); + expect(response.body.dns.spf.value).to.eql('v=spf1 a:example.com a:' + mailFqdn + ' ~all'); + expect(response.body.dns.spf.expected).to.eql('v=spf1 a:example.com a:' + mailFqdn + ' ~all'); expect(response.body.dns.spf.status).to.eql(true); }); @@ -263,7 +263,7 @@ describe('Mail API', function () { it('succeeds with all correct records', async function () { clearDnsAnswerQueue(); - dnsAnswerQueue[mxDomain].MX = [ { priority: '10', exchange: settings.mailFqdn() } ]; + dnsAnswerQueue[mxDomain].MX = [ { priority: '10', exchange: mailFqdn } ]; dnsAnswerQueue[dmarcDomain].TXT = [['v=DMARC1; p=reject; pct=100']]; dnsAnswerQueue[dkimDomain].TXT = [['v=DKIM1; t=s; p=', publicKey ]]; dnsAnswerQueue[spfDomain].TXT = [['v=spf1 a:' + settings.dashboardFqdn() + ' ~all']]; @@ -294,8 +294,8 @@ describe('Mail API', function () { expect(response.body.dns.mx).to.be.an('object'); expect(response.body.dns.mx.status).to.eql(true); - expect(response.body.dns.mx.expected).to.eql('10 ' + settings.mailFqdn() + '.'); - expect(response.body.dns.mx.value).to.eql('10 ' + settings.mailFqdn() + '.'); + expect(response.body.dns.mx.expected).to.eql('10 ' + mailFqdn + '.'); + expect(response.body.dns.mx.value).to.eql('10 ' + mailFqdn + '.'); }); }); diff --git a/src/services.js b/src/services.js index 84fb7835e..31ea7e778 100644 --- a/src/services.js +++ b/src/services.js @@ -973,6 +973,7 @@ async function setupEmail(app, options) { const mailDomains = await mail.listDomains(); const mailInDomains = mailDomains.filter(function (d) { return d.enabled; }).map(function (d) { return d.domain; }).join(','); + const { fqdn } = await mailServer.getLocation(); // note that "external" access info can be derived from MAIL_DOMAIN (since it's part of user documentation) const env = [ @@ -987,7 +988,7 @@ async function setupEmail(app, options) { { name: 'CLOUDRON_EMAIL_SIEVE_PORT', value: '4190' }, // starttls { name: 'CLOUDRON_EMAIL_DOMAIN', value: app.domain }, { name: 'CLOUDRON_EMAIL_DOMAINS', value: mailInDomains }, - { name: 'CLOUDRON_EMAIL_SERVER_HOST', value: settings.mailFqdn() }, // this is also a hint to reconfigure on mail server name change + { name: 'CLOUDRON_EMAIL_SERVER_HOST', value: fqdn }, // this is also a hint to reconfigure on mail server name change { name: 'CLOUDRON_EMAIL_LDAP_MAILBOXES_BASE_DN', value: 'ou=mailboxes,dc=cloudron' } ]; diff --git a/src/settings.js b/src/settings.js index c48b38774..6286c1fbf 100644 --- a/src/settings.js +++ b/src/settings.js @@ -6,10 +6,6 @@ exports = module.exports = { // these values come from the cache dashboardDomain, setDashboardLocation, - setMailLocation, - - mailFqdn, - mailDomain, dashboardOrigin, dashboardFqdn, @@ -73,8 +69,6 @@ const gDefaults = (function () { const result = { }; result[exports.DASHBOARD_DOMAIN_KEY] = ''; result[exports.DASHBOARD_FQDN_KEY] = ''; - result[exports.MAIL_DOMAIN_KEY] = ''; - result[exports.MAIL_FQDN_KEY] = ''; return result; })(); @@ -150,8 +144,6 @@ async function initCache() { gCache = { dashboardDomain: allSettings[exports.DASHBOARD_DOMAIN_KEY], dashboardFqdn: allSettings[exports.DASHBOARD_FQDN_KEY], - mailDomain: allSettings[exports.MAIL_DOMAIN_KEY], - mailFqdn: allSettings[exports.MAIL_FQDN_KEY], }; } @@ -167,19 +159,6 @@ async function setDashboardLocation(dashboardDomain, dashboardFqdn) { gCache.dashboardFqdn = dashboardFqdn; } -async function setMailLocation(mailDomain, mailFqdn) { - assert.strictEqual(typeof mailDomain, 'string'); - assert.strictEqual(typeof mailFqdn, 'string'); - - await set(exports.MAIL_DOMAIN_KEY, mailDomain); - await set(exports.MAIL_FQDN_KEY, mailFqdn); - - gCache.mailDomain = mailDomain; - gCache.mailFqdn = mailFqdn; -} - function dashboardDomain() { return gCache.dashboardDomain; } function dashboardFqdn() { return gCache.dashboardFqdn; } -function mailDomain() { return gCache.mailDomain; } -function mailFqdn() { return gCache.mailFqdn; } function dashboardOrigin() { return 'https://' + dashboardFqdn(); } diff --git a/src/test/common.js b/src/test/common.js index 4df29fe89..d3ffe4e09 100644 --- a/src/test/common.js +++ b/src/test/common.js @@ -8,6 +8,7 @@ const apps = require('../apps.js'), expect = require('expect.js'), fs = require('fs'), mailer = require('../mailer.js'), + mailServer = require('../mailserver.js'), nock = require('nock'), path = require('path'), paths = require('../paths.js'), @@ -221,7 +222,7 @@ async function domainSetup() { nock.cleanAll(); await databaseSetup(); - await settings.setMailLocation(domain.domain, `${constants.DASHBOARD_SUBDOMAIN}.${domain.domain}`); // default mail location. do this before we add the domain for upserting mail DNS + await mailServer.initLocation(domain.domain, `${constants.DASHBOARD_SUBDOMAIN}.${domain.domain}`); // default mail location. do this before we add the domain for upserting mail DNS await domains.add(domain.domain, domain, auditSource); } diff --git a/src/wellknown.js b/src/wellknown.js index be2b1790d..a865bb8f1 100644 --- a/src/wellknown.js +++ b/src/wellknown.js @@ -10,6 +10,7 @@ const assert = require('assert'), ejs = require('ejs'), fs = require('fs'), mail = require('./mail.js'), + mailServer = require('./mailserver.js'), safe = require('safetydance'), settings = require('./settings.js'), superagent = require('superagent'); @@ -21,12 +22,12 @@ async function get(domain, location) { assert.strictEqual(typeof location, 'string'); if (location === 'autoconfig/mail/config-v1.1.xml') { // this also gets a ?emailaddress - const mailDomain = await mail.getDomain(domain); if (!mailDomain) throw new BoxError(BoxError.NOT_FOUND, 'Domain not found'); if (!mailDomain.enabled) throw new BoxError(BoxError.NOT_FOUND, 'Email not enabled'); + const { fqdn } = await mailServer.getLocation(); - const autoconfig = ejs.render(MAIL_AUTOCONFIG_EJS, { domain, mailFqdn: settings.mailFqdn() }); + const autoconfig = ejs.render(MAIL_AUTOCONFIG_EJS, { domain, fqdn }); return { type: 'text/xml', body: autoconfig }; } else if (location === 'host-meta' || location === 'matrix/server' || location === 'matrix/client') {