diff --git a/src/mail.js b/src/mail.js index 782173e3b..e92c297e3 100644 --- a/src/mail.js +++ b/src/mail.js @@ -959,10 +959,11 @@ async function addMailbox(name, domain, data, auditSource) { assert.strictEqual(typeof data, 'object'); assert.strictEqual(typeof auditSource, 'object'); - const { ownerId, ownerType, active, storageQuota, messagesQuota } = data; + const { ownerId, ownerType, active, storageQuota, messagesQuota, enablePop3 } = data; assert.strictEqual(typeof ownerId, 'string'); assert.strictEqual(typeof ownerType, 'string'); assert.strictEqual(typeof active, 'boolean'); + assert.strictEqual(typeof enablePop3, 'boolean'); assert(Number.isInteger(storageQuota) && storageQuota >= 0); assert(Number.isInteger(messagesQuota) && messagesQuota >= 0); @@ -973,13 +974,13 @@ async function addMailbox(name, domain, data, auditSource) { if (!OWNERTYPES.includes(ownerType)) throw new BoxError(BoxError.BAD_FIELD, 'bad owner type'); - [error] = await safe(database.query('INSERT INTO mailboxes (name, type, domain, ownerId, ownerType, active, storageQuota, messagesQuota) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', - [ name, exports.TYPE_MAILBOX, domain, ownerId, ownerType, active, storageQuota, messagesQuota ])); + [error] = await safe(database.query('INSERT INTO mailboxes (name, type, domain, ownerId, ownerType, active, storageQuota, messagesQuota, enablePop3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', + [ name, exports.TYPE_MAILBOX, domain, ownerId, ownerType, active, storageQuota, messagesQuota, enablePop3 ])); if (error && error.code === 'ER_DUP_ENTRY') throw new BoxError(BoxError.ALREADY_EXISTS, 'mailbox already exists'); if (error && error.code === 'ER_NO_REFERENCED_ROW_2' && error.sqlMessage.includes('mailboxes_domain_constraint')) throw new BoxError(BoxError.NOT_FOUND, `no such domain '${domain}'`); if (error) throw error; - await eventlog.add(eventlog.ACTION_MAIL_MAILBOX_ADD, auditSource, { name, domain, ownerId, ownerType, active, storageQuota, messageQuota: messagesQuota }); + await eventlog.add(eventlog.ACTION_MAIL_MAILBOX_ADD, auditSource, { name, domain, ownerId, ownerType, active, storageQuota, enablePop3, messageQuota: messagesQuota }); } async function updateMailbox(name, domain, data, auditSource) { diff --git a/src/routes/mail.js b/src/routes/mail.js index b24b2d475..ff4c7c4f2 100644 --- a/src/routes/mail.js +++ b/src/routes/mail.js @@ -179,6 +179,7 @@ async function addMailbox(req, res, next) { if (typeof req.body.ownerId !== 'string') return next(new HttpError(400, 'ownerId must be a string')); if (typeof req.body.ownerType !== 'string') return next(new HttpError(400, 'ownerType must be a string')); if (typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean')); + if (typeof req.body.enablePop3 !== 'boolean') return next(new HttpError(400, 'enablePop3 must be a boolean')); if (!Number.isInteger(req.body.storageQuota)) return next(new HttpError(400, 'storageQuota must be an integer')); if (req.body.storageQuota < 0) return next(new HttpError(400, 'storageQuota must be a postive integer or zero')); diff --git a/src/routes/test/mail-test.js b/src/routes/test/mail-test.js index 6eb06a11c..17f97a2ca 100644 --- a/src/routes/test/mail-test.js +++ b/src/routes/test/mail-test.js @@ -427,7 +427,7 @@ describe('Mail API', function () { it('add succeeds', async function () { const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`) - .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 }) + .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, enablePop3: false, storageQuota: 10, messagesQuota: 20 }) .query({ access_token: owner.token }); expect(response.status).to.equal(201); @@ -435,7 +435,7 @@ describe('Mail API', function () { it('cannot add again', async function () { const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`) - .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 }) + .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, enablePop3: true, storageQuota: 10, messagesQuota: 20 }) .query({ access_token: owner.token }) .ok(() => true); @@ -457,6 +457,8 @@ describe('Mail API', function () { expect(response.status).to.equal(200); expect(response.body.mailbox).to.be.an('object'); expect(response.body.mailbox.name).to.equal(MAILBOX_NAME); + expect(response.body.mailbox.active).to.equal(true); + expect(response.body.mailbox.enablePop3).to.equal(false); expect(response.body.mailbox.ownerId).to.equal(owner.id); expect(response.body.mailbox.ownerType).to.equal('user'); expect(response.body.mailbox.aliasName).to.equal(null); @@ -514,7 +516,7 @@ describe('Mail API', function () { it('add the mailbox', async function () { const response = await superagent.post(`${serverUrl}/api/v1/mail/${dashboardDomain}/mailboxes`) - .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20 }) + .send({ name: MAILBOX_NAME, ownerId: owner.id, ownerType: 'user', active: true, enablePop3: false, storageQuota: 10, messagesQuota: 20 }) .query({ access_token: owner.token }); expect(response.status).to.equal(201); diff --git a/src/test/mail-test.js b/src/test/mail-test.js index 4e736c77b..e53009541 100644 --- a/src/test/mail-test.js +++ b/src/test/mail-test.js @@ -119,16 +119,16 @@ describe('Mail', function () { describe('mailboxes', function () { it('add user mailbox succeeds', async function () { - await mail.addMailbox('girish', domain.domain, { ownerId: 'uid-0', ownerType: mail.OWNERTYPE_USER, active: true, storageQuota: 0, messagesQuota: 0 }, auditSource); + await mail.addMailbox('girish', domain.domain, { ownerId: 'uid-0', ownerType: mail.OWNERTYPE_USER, active: true, enablePop3: false, storageQuota: 0, messagesQuota: 0 }, auditSource); }); it('cannot add dup entry', async function () { - const [error] = await safe(mail.addMailbox('girish', domain.domain, { ownerId: 'uid-1', ownerType: mail.OWNERTYPE_GROUP, active: true, storageQuota: 0, messagesQuota: 0 }, auditSource)); + const [error] = await safe(mail.addMailbox('girish', domain.domain, { ownerId: 'uid-1', ownerType: mail.OWNERTYPE_GROUP, active: true, enablePop3: false, storageQuota: 0, messagesQuota: 0 }, auditSource)); expect(error.reason).to.be(BoxError.ALREADY_EXISTS); }); it('add app mailbox succeeds', async function () { - await mail.addMailbox('support', domain.domain, { ownerId: 'osticket', ownerType: 'user', active: true, storageQuota: 10, messagesQuota: 20}, auditSource); + await mail.addMailbox('support', domain.domain, { ownerId: 'osticket', ownerType: 'user', active: true, enablePop3: true, storageQuota: 10, messagesQuota: 20}, auditSource); }); it('get succeeds', async function () { @@ -139,6 +139,7 @@ describe('Mail', function () { expect(mailbox.creationTime).to.be.a(Date); expect(mailbox.storageQuota).to.be(10); expect(mailbox.messagesQuota).to.be(20); + expect(mailbox.enablePop3).to.be(true); }); it('get non-existent mailbox', async function () { @@ -147,11 +148,12 @@ describe('Mail', function () { }); it('update app mailbox succeeds', async function () { - await mail.updateMailbox('support', domain.domain, { ownerId: 'osticket', ownerType: 'user', active: true, storageQuota: 20, messagesQuota: 30}, auditSource); + await mail.updateMailbox('support', domain.domain, { ownerId: 'osticket', ownerType: 'user', active: true, enablePop3: true, storageQuota: 20, messagesQuota: 30}, auditSource); const mailbox = await mail.getMailbox('support', domain.domain); expect(mailbox.storageQuota).to.be(20); expect(mailbox.messagesQuota).to.be(30); + expect(mailbox.enablePop3).to.be(true); }); it('list mailboxes succeeds', async function () {