diff --git a/src/apps.js b/src/apps.js index 57822a075..207a56000 100644 --- a/src/apps.js +++ b/src/apps.js @@ -66,6 +66,7 @@ var addons = require('./addons.js'), eventlog = require('./eventlog.js'), fs = require('fs'), groups = require('./groups.js'), + mail = require('./mail.js'), mailboxdb = require('./mailboxdb.js'), manifestFormat = require('cloudron-manifestformat'), os = require('os'), @@ -670,6 +671,11 @@ function configure(appId, data, auditSource, callback) { if (error) return callback(error); } + if ('mailboxName' in data) { + error = mail.validateName(data.mailboxName); + if (error) return callback(error); + } + domains.get(domain, function (error, domainObject) { if (error && error.reason === DomainsError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such domain')); if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, 'Could not get domain info:' + error.message)); @@ -699,8 +705,8 @@ function configure(appId, data, auditSource, callback) { debug('Will configure app with id:%s values:%j', appId, values); - var oldName = (app.location ? app.location : app.manifest.title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '')) + '.app'; - var newName = (location ? location : app.manifest.title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '')) + '.app'; + var oldName = app.mailboxName; + var newName = data.mailboxName || app.mailboxName; mailboxdb.updateName(oldName, values.oldConfig.domain, newName, domain, function (error) { if (error && error.reason === DatabaseError.ALREADY_EXISTS) return callback(new AppsError(AppsError.ALREADY_EXISTS, 'This mailbox is already taken')); if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.BAD_STATE)); diff --git a/src/mail.js b/src/mail.js index 676213bc7..6ab281847 100644 --- a/src/mail.js +++ b/src/mail.js @@ -12,6 +12,8 @@ exports = module.exports = { addDnsRecords: addDnsRecords, + validateName: validateName, + setMailFromValidation: setMailFromValidation, setCatchAllAddress: setCatchAllAddress, setMailRelay: setMailRelay, @@ -46,7 +48,6 @@ exports = module.exports = { var assert = require('assert'), async = require('async'), config = require('./config.js'), - constants = require('./constants.js'), DatabaseError = require('./databaseerror.js'), debug = require('debug')('box:mail'), dns = require('./native-dns.js'), diff --git a/src/routes/apps.js b/src/routes/apps.js index a1f7b8c57..1f3fe47e7 100644 --- a/src/routes/apps.js +++ b/src/routes/apps.js @@ -170,6 +170,8 @@ function configureApp(req, res, next) { if (data.robotsTxt && typeof data.robotsTxt !== 'string') return next(new HttpError(400, 'robotsTxt must be a string')); + if ('mailboxName' in data && typeof data.mailboxName !== 'string') return next(new HttpError(400, 'mailboxName must be a string')); + debug('Configuring app id:%s data:%j', req.params.id, data); apps.configure(req.params.id, data, auditSource(req), function (error) {