mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 10:52:17 -05:00
list well known folders works in dao... not yet in ui
This commit is contained in:
parent
14965a7c32
commit
9ed7a696b4
@ -26,28 +26,7 @@ define([], function() {
|
||||
secure: true,
|
||||
port: 465,
|
||||
host: 'smtp.gmail.com'
|
||||
},
|
||||
folders: [{
|
||||
type: 'Inbox',
|
||||
count: undefined,
|
||||
path: 'INBOX'
|
||||
}, {
|
||||
type: 'Sent',
|
||||
count: undefined,
|
||||
path: '[Gmail]/Gesendet'
|
||||
}, {
|
||||
type: 'Outbox',
|
||||
count: undefined,
|
||||
path: 'OUTBOX'
|
||||
}, {
|
||||
type: 'Drafts',
|
||||
count: undefined,
|
||||
path: '[Gmail]/Entw&APw-rfe'
|
||||
}, {
|
||||
type: 'Trash',
|
||||
count: undefined,
|
||||
path: '[Gmail]/Papierkorb'
|
||||
}]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -52,6 +52,10 @@ define(function(require) {
|
||||
};
|
||||
|
||||
$scope.$watch('currentFolder', function() {
|
||||
if (!getFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// production... in chrome packaged app
|
||||
if (window.chrome && chrome.identity) {
|
||||
initList();
|
||||
|
@ -1,11 +1,24 @@
|
||||
define(function(require) {
|
||||
'use strict';
|
||||
|
||||
var folders = require('js/app-config').config.gmail.folders;
|
||||
var appController = require('js/app-controller'),
|
||||
emailDao;
|
||||
|
||||
var NavigationCtrl = function($scope) {
|
||||
$scope.navOpen = false;
|
||||
$scope.folders = folders;
|
||||
|
||||
emailDao = appController._emailDao;
|
||||
|
||||
initFolders(function(folders) {
|
||||
$scope.folders = folders;
|
||||
$scope.apply();
|
||||
// select inbox as the current folder on init
|
||||
$scope.openFolder($scope.folders[0]);
|
||||
});
|
||||
|
||||
//
|
||||
// scope functions
|
||||
//
|
||||
|
||||
$scope.openNav = function() {
|
||||
$scope.navOpen = true;
|
||||
@ -19,8 +32,6 @@ define(function(require) {
|
||||
$scope.currentFolder = folder;
|
||||
$scope.closeNav();
|
||||
};
|
||||
// select inbox as the current folder on init
|
||||
$scope.openFolder($scope.folders[0]);
|
||||
|
||||
$scope.write = function(replyTo) {
|
||||
var replyToId = (replyTo) ? replyTo.uid : '',
|
||||
@ -38,6 +49,21 @@ define(function(require) {
|
||||
|
||||
window.open(url, 'Compose Message', 'toolbar=no,width=720,height=640,left=500,top=200,status=no,scrollbars=no,resize=no');
|
||||
};
|
||||
|
||||
//
|
||||
// helper functions
|
||||
//
|
||||
|
||||
function initFolders(callback) {
|
||||
emailDao.imapListFolders(function(err, folders) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(folders);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return NavigationCtrl;
|
||||
|
@ -105,9 +105,57 @@ define(function(require) {
|
||||
* List the folders in the user's IMAP mailbox.
|
||||
*/
|
||||
EmailDAO.prototype.imapListFolders = function(callback) {
|
||||
var self = this;
|
||||
var self = this,
|
||||
dbType = 'folders';
|
||||
|
||||
self._imapClient.listAllFolders(callback);
|
||||
// check local cache
|
||||
self._devicestorage.listItems(dbType, 0, null, function(err, stored) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!stored || stored.length < 1) {
|
||||
// no folders cached... fetch from server
|
||||
fetchFromServer();
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, stored[0]);
|
||||
});
|
||||
|
||||
function fetchFromServer() {
|
||||
var folders;
|
||||
|
||||
// fetch list from imap server
|
||||
self._imapClient.listWellKnownFolders(function(err, wellKnownFolders) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
folders = [
|
||||
wellKnownFolders.inbox,
|
||||
wellKnownFolders.sent, {
|
||||
type: 'Outbox',
|
||||
path: 'OUTBOX'
|
||||
},
|
||||
wellKnownFolders.drafts,
|
||||
wellKnownFolders.trash
|
||||
];
|
||||
|
||||
// cache locally
|
||||
// persist encrypted list in device storage
|
||||
self._devicestorage.storeList([folders], dbType, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, folders);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,21 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('List well known folders', function() {
|
||||
it('should work', function(done) {
|
||||
// clear folders from cache
|
||||
emailDao._devicestorage.removeList('folders', function(err) {
|
||||
expect(err).to.not.exist;
|
||||
|
||||
emailDao.imapListFolders(function(err, folders) {
|
||||
expect(err).to.not.exist;
|
||||
expect(folders.length).to.be.at.least(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('IMAP sync INBOX messages', function() {
|
||||
it('should work', function(done) {
|
||||
emailDao.imapSync({
|
||||
|
@ -218,11 +218,38 @@ define(function(require) {
|
||||
});
|
||||
|
||||
describe('IMAP: list folders', function() {
|
||||
it('should work', function(done) {
|
||||
imapClientStub.listAllFolders.yields();
|
||||
emailDao.imapListFolders(function(err) {
|
||||
expect(imapClientStub.listAllFolders.calledOnce).to.be.true;
|
||||
var dummyFolders = [{
|
||||
type: 'Inbox',
|
||||
path: 'INBOX'
|
||||
}, {
|
||||
type: 'Outbox',
|
||||
path: 'OUTBOX'
|
||||
}];
|
||||
|
||||
it('should work on empty local db', function(done) {
|
||||
devicestorageStub.listItems.yields(null, [dummyFolders]);
|
||||
|
||||
emailDao.imapListFolders(function(err, folders) {
|
||||
expect(err).to.not.exist;
|
||||
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
||||
expect(folders[0].type).to.equal('Inbox');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with local cache', function(done) {
|
||||
devicestorageStub.listItems.yields(null, []);
|
||||
imapClientStub.listWellKnownFolders.yields(null, {
|
||||
inbox: dummyFolders[0]
|
||||
});
|
||||
devicestorageStub.storeList.yields();
|
||||
|
||||
emailDao.imapListFolders(function(err, folders) {
|
||||
expect(err).to.not.exist;
|
||||
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
||||
expect(imapClientStub.listWellKnownFolders.calledOnce).to.be.true;
|
||||
expect(devicestorageStub.storeList.calledOnce).to.be.true;
|
||||
expect(folders[0].type).to.equal('Inbox');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user