Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions src/client-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
17 changes: 17 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down