1
0
mirror of https://github.com/moparisthebest/mail synced 2025-02-16 23:20:09 -05:00

Merge pull request #58 from whiteout-io/dev/WO-284

[WO-284] delete mails to trash folder
This commit is contained in:
Tankred Hase 2014-05-12 17:37:16 +02:00
commit 6c329b3772
2 changed files with 42 additions and 8 deletions

View File

@ -743,8 +743,26 @@ define(function(require) {
return; return;
} }
options.path = options.folder; var trash = _.findWhere(this._account.folders, {
this._imapClient.deleteMessage(options, callback); type: 'Trash'
});
// there's no known trash folder to move the mail to or we're in the trash folder,
// so we can purge the message
if (!trash || options.folder === trash.path) {
this._imapClient.deleteMessage({
path: options.folder,
uid: options.uid
}, callback);
return;
}
this._imapClient.moveMessage({
path: options.folder,
destination: trash.path,
uid: options.uid
}, callback);
}; };
/** /**

View File

@ -13,7 +13,7 @@ define(function(require) {
describe('Email Sync unit tests', function() { describe('Email Sync unit tests', function() {
var emailSync, keychainStub, imapClientStub, devicestorageStub; var emailSync, keychainStub, imapClientStub, devicestorageStub;
var emailAddress, mockkeyId, dummyEncryptedMail, var emailAddress, mockkeyId, dummyEncryptedMail, trashMailbox,
dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid, corruptedVerificationUuid, dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid, corruptedVerificationUuid,
nonWhitelistedMail; nonWhitelistedMail;
@ -106,6 +106,10 @@ define(function(require) {
expect(emailSync._keychain).to.equal(keychainStub); expect(emailSync._keychain).to.equal(keychainStub);
expect(emailSync._devicestorage).to.equal(devicestorageStub); expect(emailSync._devicestorage).to.equal(devicestorageStub);
expect(emailSync._mailreader).to.equal(mailreader); expect(emailSync._mailreader).to.equal(mailreader);
trashMailbox = {
type: 'Trash',
path: 'trash'
};
// init // init
emailSync.init({ emailSync.init({
@ -118,7 +122,7 @@ define(function(require) {
expect(emailSync._imapClient).to.not.exist; expect(emailSync._imapClient).to.not.exist;
expect(emailSync._smtpClient).to.not.exist; expect(emailSync._smtpClient).to.not.exist;
expect(emailSync._account.online).to.be.undefined; expect(emailSync._account.online).to.be.undefined;
emailSync._account.folders = []; emailSync._account.folders = [trashMailbox];
imapClientStub.login.yields(); imapClientStub.login.yields();
// this is set in the emailDao.onConnect // this is set in the emailDao.onConnect
@ -214,11 +218,11 @@ define(function(require) {
}); });
}); });
it('should work', function(done) { it('should move to trash', function(done) {
imapClientStub.deleteMessage.withArgs({ imapClientStub.moveMessage.withArgs({
path: path, path: path,
folder: path, uid: uid,
uid: uid destination: trashMailbox.path
}).yields(); }).yields();
emailSync._imapDeleteMessage({ emailSync._imapDeleteMessage({
@ -226,6 +230,18 @@ define(function(require) {
uid: uid uid: uid
}, done); }, done);
}); });
it('should purge message', function(done) {
imapClientStub.deleteMessage.withArgs({
path: trashMailbox.path,
uid: uid
}).yields();
emailSync._imapDeleteMessage({
folder: trashMailbox.path,
uid: uid
}, done);
});
}); });
describe('_imapListMessages', function() { describe('_imapListMessages', function() {