diff --git a/README.md b/README.md index ef8d697c..eec94cc5 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,17 @@ client.createMailbox('INBOX/Foo').then(() => { ... }); // Do the same on a server where the personal namespace is '' client.createMailbox('Foo').then(() => { ... }); ``` +## Delete mailbox + +Delete a folder with the given path with `deleteMailbox(path)`, automatically handling utf-7 encoding. + +Command: [DELETE](http://tools.ietf.org/html/rfc3501#section-6.3.4) + +Example + +```javascript +client.deleteMailbox('Foo').then(() => { ... }); +``` ## Select mailbox diff --git a/src/client-unit.js b/src/client-unit.js index f88f8ada..5b6ed753 100644 --- a/src/client-unit.js +++ b/src/client-unit.js @@ -572,6 +572,35 @@ describe('browserbox unit tests', () => { }) }) + describe('#deleteMailbox', () => { + beforeEach(() => { + sinon.stub(br, 'exec') + }) + + it('should call DELETE with a string payload', () => { + br.exec.withArgs({ + command: 'DELETE', + attributes: ['mailboxname'] + }).returns(Promise.resolve()) + + return br.deleteMailbox('mailboxname').then(() => { + expect(br.exec.callCount).to.equal(1) + }) + }) + + it('should call mutf7 encode the argument', () => { + // From RFC 3501 + br.exec.withArgs({ + command: 'DELETE', + attributes: ['~peter/mail/&U,BTFw-/&ZeVnLIqe-'] + }).returns(Promise.resolve()) + + return br.deleteMailbox('~peter/mail/\u53f0\u5317/\u65e5\u672c\u8a9e').then(() => { + expect(br.exec.callCount).to.equal(1) + }) + }) + }) + describe.skip('#listMessages', () => { beforeEach(() => { sinon.stub(br, 'exec') diff --git a/src/client.js b/src/client.js index e805e4e3..8117240c 100644 --- a/src/client.js +++ b/src/client.js @@ -359,6 +359,23 @@ export default class Client { } } + /** + * Delete a mailbox with the given path. + * + * DELETE details: + * https://tools.ietf.org/html/rfc3501#section-6.3.4 + * + * @param {String} path + * The path of the mailbox you would like to delete. This method will + * handle utf7 encoding for you. + * @returns {Promise} + * Promise resolves if mailbox was deleted. + */ + deleteMailbox (path) { + this.logger.debug('Deleting mailbox', path, '...') + return this.exec({ command: 'DELETE', attributes: [imapEncode(path)] }) + } + /** * Runs FETCH command *