1
0
mirror of https://github.com/moparisthebest/mail synced 2024-10-31 15:25:01 -04:00

list email in new ui works, remove command pattern bloat from app-controller

This commit is contained in:
Tankred Hase 2013-09-04 21:01:32 +02:00
parent 1259d0c160
commit cf8a12c75c
3 changed files with 37 additions and 164 deletions

View File

@ -34,84 +34,7 @@ define(function(require) {
} }
}; };
/** self.fetchOAuthToken = function(password, callback) {
* Executes a number of commands
*/
self.execute = function(cmd, args, callback) {
if (cmd === 'login') {
// login user
fetchOAuthToken(args.password, function(err, userId) {
callback({
err: err,
userId: userId
});
});
} else if (cmd === 'listFolders') {
// list folders in users mailbox
self._emailDao.imapListFolders(function(err, folders) {
callback({
err: err,
folders: folders
});
});
} else if (cmd === 'syncEmails') {
// self._emailDao.syncFromCloud(args.folder, function(err) {
// callback({
// err: err
// });
// });
// Syncing to local storage is not yet supported for imap
callback({
err: 'Not yet implemented!'
});
} else if (cmd === 'listEmails') {
// list emails from folder
self._emailDao.imapListMessages(args, function(err, emails) {
callback({
err: err,
emails: emails
});
});
} else if (cmd === 'getEmail') {
// list emails from folder
self._emailDao.imapGetMessage({
folder: args.folder,
uid: args.messageId
}, function(err, email) {
callback({
err: err,
email: email
});
});
} else if (cmd === 'sendEmail') {
// list emails from folder
self._emailDao.smtpSend(args.email, function(err) {
callback({
err: err
});
});
} else {
// error: invalid message from sandbox
callback({
err: {
errMsg: 'Invalid message posted from sandbox!'
}
});
}
};
//
// Helper methods
//
function fetchOAuthToken(password, callback) {
// get OAuth Token from chrome // get OAuth Token from chrome
chrome.identity.getAuthToken({ chrome.identity.getAuthToken({
'interactive': true 'interactive': true
@ -139,7 +62,7 @@ define(function(require) {
} }
); );
} };
self.login = function(userId, password, token, callback) { self.login = function(userId, password, token, callback) {
var auth, imapOptions, smtpOptions, var auth, imapOptions, smtpOptions,

View File

@ -1,28 +1,40 @@
define(function() { define(function(require) {
'use strict'; 'use strict';
var Email = function(unread) { var appController = require('js/app-controller');
this.from = [{
name: 'Whiteout Support',
address: 'support@whiteout.io'
}]; // sender address
this.to = [{
address: 'max.musterman@gmail.com'
}]; // list of receivers
this.unread = unread;
this.sentDate = '7:23 PM';
this.subject = "Welcome Max"; // Subject line
this.body = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy."; // plaintext body
};
var MessageListCtrl = function($scope) { var MessageListCtrl = function($scope) {
$scope.folderName = 'Inbox'; $scope.folderName = 'Inbox';
$scope.emails = [new Email(true), new Email(true), new Email(false), new Email(false), new Email(false), new Email(false)];
$scope.select = function(email) { $scope.select = function(email) {
$scope.selected = email; $scope.selected = email;
}; };
fetchList(function(err, emails) {
if (err) {
console.log(err);
return;
}
$scope.emails = emails;
$scope.$apply();
});
}; };
function fetchList(callback) {
appController.fetchOAuthToken('passphrase', function(err) {
if (err) {
console.log(err);
return;
}
appController._emailDao.imapListMessages({
folder: 'INBOX',
offset: -6,
num: 0
}, callback);
});
}
return MessageListCtrl; return MessageListCtrl;
}); });

View File

@ -49,76 +49,14 @@ define(function(require) {
}); });
}); });
describe('execute', function() { describe('login', function() {
describe('login', function() { it('should work', function(done) {
it('should work', function(done) { controller.fetchOAuthToken(appControllerTest.passphrase, function(err, userId) {
controller.execute('login', { expect(err).to.not.exist;
password: appControllerTest.passphrase expect(userId).to.equal(appControllerTest.user);
}, function(resArgs) { expect($.ajax.calledOnce).to.be.true;
expect(resArgs.err).to.not.exist; expect(window.chrome.identity.getAuthToken.calledOnce).to.be.true;
expect(resArgs.userId).to.equal(appControllerTest.user); done();
expect($.ajax.calledOnce).to.be.true;
expect(window.chrome.identity.getAuthToken.calledOnce).to.be.true;
done();
});
});
});
describe('sendEmail', function() {
it('should work', function(done) {
controller._emailDao.smtpSend.yields();
controller.execute('sendEmail', {
password: appControllerTest.passphrase
}, function(resArgs) {
expect(resArgs.err).to.not.exist;
expect(controller._emailDao.smtpSend.calledOnce).to.be.true;
done();
});
});
});
describe('listFolders', function() {
it('should work', function(done) {
controller._emailDao.imapListFolders.yields(null, ['inbox', 'sent']);
controller.execute('listFolders', {
password: appControllerTest.passphrase
}, function(resArgs) {
expect(resArgs.err).to.not.exist;
expect(resArgs.folders[1]).to.equal('sent');
expect(controller._emailDao.imapListFolders.calledOnce).to.be.true;
done();
});
});
});
describe('listEmails', function() {
it('should work', function(done) {
controller._emailDao.imapListMessages.yields(null, []);
controller.execute('listEmails', {
folder: 'INBOX',
offset: 0,
num: 10
}, function(resArgs) {
expect(resArgs.err).to.not.exist;
expect(resArgs.emails).to.a('Array');
expect(controller._emailDao.imapListMessages.calledOnce).to.be.true;
done();
});
});
});
describe('getEmail', function() {
it('should work', function(done) {
controller._emailDao.imapGetMessage.yields(null, {});
controller.execute('getEmail', {
folder: 'INBOX',
messageId: 415
}, function(resArgs) {
expect(resArgs.err).to.not.exist;
expect(resArgs.email).to.a('Object');
expect(controller._emailDao.imapGetMessage.calledOnce).to.be.true;
done();
});
}); });
}); });
}); });