diff --git a/src/ldap.js b/src/ldap.js index c81765e51..b63c0b0c4 100644 --- a/src/ldap.js +++ b/src/ldap.js @@ -130,9 +130,12 @@ function groupSearch(req, res, next) { }); } -function mailboxSearch(req, res, next) { - debug('mailbox search: dn %s, scope %s, filter %s (from %s)', req.dn.toString(), req.scope, req.filter.toString(), req.connection.ldap.id); +function getMailbox(req, res, next) { + debug('mailbox get: dn %s, scope %s, filter %s (from %s)', req.dn.toString(), req.scope, req.filter.toString(), req.connection.ldap.id); + if (!req.dn.rdns[0].attrs.cn) return next(new ldap.OperationsError('CN is required')); + + mailboxes.get( mailboxes.getAll(function (error, result) { if (error) return next(new ldap.OperationsError(error.toString())); @@ -251,7 +254,7 @@ function start(callback) { gServer.search('ou=groups,dc=cloudron', groupSearch); gServer.bind('ou=users,dc=cloudron', authenticateUser, authorizeUserForApp); - gServer.search('ou=mailboxes,dc=cloudron', mailboxSearch); + gServer.search('ou=mailboxes,dc=cloudron', getMailbox); gServer.bind('ou=mailboxes,dc=cloudron', authenticateUser, authorizeUserForMailbox); // this is the bind for addons (after bind, they might search and authenticate) diff --git a/src/mailboxdb.js b/src/mailboxdb.js index ef4674eef..5572a7321 100644 --- a/src/mailboxdb.js +++ b/src/mailboxdb.js @@ -87,26 +87,14 @@ function delByOwnerId(id, callback) { }); } -function postProcess(result) { - result.aliases = result.aliases ? result.aliases.split(',') : [ ]; -} - function get(name, callback) { assert.strictEqual(typeof name, 'string'); assert.strictEqual(typeof callback, 'function'); - var query = 'SELECT m1.name, m1.creationTime, GROUP_CONCAT(m2.name) AS aliases ' + - 'FROM mailboxes as m1 ' + - 'LEFT OUTER JOIN mailboxes as m2 ON m1.name = m2.aliasTarget ' + - 'WHERE m1.name=? AND m1.aliasTarget IS NULL ' + - 'GROUP BY m1.name'; - - database.query(query, [ name ], function (error, results) { + database.query('SELECT ' + MAILBOX_FIELDS + ' FROM mailboxes WHERE name = ? ', [ name ], function (error, results) { if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); if (results.length === 0) return callback(new DatabaseError(DatabaseError.NOT_FOUND)); - postProcess(results[0]); - callback(null, results[0]); }); }