From 79f71d5185f4a3a354ecdd206a683786dcd057cb Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Mon, 12 May 2014 12:23:43 +0200 Subject: [PATCH] [WO-284] delete mails to trash folder --- src/js/dao/email-sync.js | 22 ++++++++++++++++++++-- test/new-unit/email-sync-test.js | 28 ++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/js/dao/email-sync.js b/src/js/dao/email-sync.js index f5eb2ca..3606dfd 100644 --- a/src/js/dao/email-sync.js +++ b/src/js/dao/email-sync.js @@ -743,8 +743,26 @@ define(function(require) { return; } - options.path = options.folder; - this._imapClient.deleteMessage(options, callback); + var trash = _.findWhere(this._account.folders, { + 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); }; /** diff --git a/test/new-unit/email-sync-test.js b/test/new-unit/email-sync-test.js index 434e1cb..7b2d63b 100644 --- a/test/new-unit/email-sync-test.js +++ b/test/new-unit/email-sync-test.js @@ -13,7 +13,7 @@ define(function(require) { describe('Email Sync unit tests', function() { var emailSync, keychainStub, imapClientStub, devicestorageStub; - var emailAddress, mockkeyId, dummyEncryptedMail, + var emailAddress, mockkeyId, dummyEncryptedMail, trashMailbox, dummyDecryptedMail, mockKeyPair, account, verificationMail, verificationUuid, corruptedVerificationUuid, nonWhitelistedMail; @@ -106,6 +106,10 @@ define(function(require) { expect(emailSync._keychain).to.equal(keychainStub); expect(emailSync._devicestorage).to.equal(devicestorageStub); expect(emailSync._mailreader).to.equal(mailreader); + trashMailbox = { + type: 'Trash', + path: 'trash' + }; // init emailSync.init({ @@ -118,7 +122,7 @@ define(function(require) { expect(emailSync._imapClient).to.not.exist; expect(emailSync._smtpClient).to.not.exist; expect(emailSync._account.online).to.be.undefined; - emailSync._account.folders = []; + emailSync._account.folders = [trashMailbox]; imapClientStub.login.yields(); // this is set in the emailDao.onConnect @@ -214,11 +218,11 @@ define(function(require) { }); }); - it('should work', function(done) { - imapClientStub.deleteMessage.withArgs({ + it('should move to trash', function(done) { + imapClientStub.moveMessage.withArgs({ path: path, - folder: path, - uid: uid + uid: uid, + destination: trashMailbox.path }).yields(); emailSync._imapDeleteMessage({ @@ -226,6 +230,18 @@ define(function(require) { uid: uid }, 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() {