diff --git a/migrations/20160528090040-mailboxes-import-existing-users.js b/migrations/20160528090040-mailboxes-import-existing-users.js new file mode 100644 index 000000000..ed7602412 --- /dev/null +++ b/migrations/20160528090040-mailboxes-import-existing-users.js @@ -0,0 +1,23 @@ +var dbm = global.dbm || require('db-migrate'); +var type = dbm.dataType; + +// imports mailbox entries for existing users +exports.up = function(db, callback) { + async.series([ + db.runSql.bind(db, 'START TRANSACTION;'), + function addUserMailboxes(done) { + db.all('SELECT username FROM users', function (error, results) { + if (error) return done(error); + + async.eachSeries(results, function (r, next) { + db.runSql('INSERT INTO mailboxes (name) VALUES (?)', [ r.username ], next); + }, done); + }); + }, + db.runSql.bind(db, 'COMMIT') + ], callback); +}; + +exports.down = function(db, callback) { + callback(); +}; diff --git a/migrations/20160528090040-mailboxes-import-existing.js b/migrations/20160528090040-mailboxes-import-existing.js deleted file mode 100644 index ab64173bd..000000000 --- a/migrations/20160528090040-mailboxes-import-existing.js +++ /dev/null @@ -1,38 +0,0 @@ -var dbm = global.dbm || require('db-migrate'); -var type = dbm.dataType; - -// imports mailbox entries for existing users and apps -exports.up = function(db, callback) { - async.series([ - db.runSql.bind(db, 'START TRANSACTION;'), - function addUserMailboxes(done) { - db.all('SELECT username FROM users', function (error, results) { - if (error) return done(error); - - console.dir(results); - - async.eachSeries(results, function (r, next) { - db.runSql('INSERT INTO mailboxes (name) VALUES (?)', [ r.username ], next); - }, done); - }); - }, - function addAppMailboxes(done) { - db.all('SELECT location, manifestJson FROM apps', function (error, results) { - if (error) return done(error); - - console.dir(results); - - async.eachSeries(results, function (r, next) { - var app = { location: r.location, manifest: JSON.parse(r.manifestJson) }; - var from = (app.location ? app.location : app.manifest.title.replace(/[^a-zA-Z0-9]/, '')) + '.app'; - db.runSql('INSERT INTO mailboxes (name) VALUES (?)', [ from ], next); - }, done); - }); - }, - db.runSql.bind(db, 'COMMIT') - ], callback); -}; - -exports.down = function(db, callback) { - callback(); -}; diff --git a/src/mailboxes.js b/src/mailboxes.js index 1c404956c..d3c19becd 100644 --- a/src/mailboxes.js +++ b/src/mailboxes.js @@ -55,6 +55,8 @@ function validateName(name) { if (/[^a-zA-Z0-9.]/.test(name)) return new MailboxError(MailboxError.BAD_NAME, 'Name can only contain alphanumerals and dot'); + if (name.indexOf('.app') !== -1) return new UserError(UserError.BAD_USERNAME, 'Alias pattern is reserved for apps'); + return null; } diff --git a/src/user.js b/src/user.js index 22133294e..59076d8fa 100644 --- a/src/user.js +++ b/src/user.js @@ -95,6 +95,7 @@ function validateUsername(username) { // +/- can be tricky in emails if (/[^a-zA-Z0-9.]/.test(username)) return new UserError(UserError.BAD_USERNAME, 'Username can only contain alphanumerals and dot'); + // app emails are sent using the .app suffix if (username.indexOf('.app') !== -1) return new UserError(UserError.BAD_USERNAME, 'Username pattern is reserved for apps'); return null;