mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
starte implementing logout and send email
This commit is contained in:
parent
1d5ba5d003
commit
d49d95ab16
@ -152,15 +152,15 @@ define(['jquery', 'ImapClient', 'SmtpClient', 'js/dao/email-dao', 'js/dao/keycha
|
||||
keychain = new KeychainDAO(cloudstorage);
|
||||
imapClient = new ImapClient(imapOptions);
|
||||
smtpClient = new SmtpClient(smtpOptions);
|
||||
emailDao = new EmailDAO(cloudstorage, keychain, imapClient, smtpClient);
|
||||
emailDao = new EmailDAO(keychain, imapClient, smtpClient);
|
||||
|
||||
// init email dao
|
||||
var account = new app.model.Account({
|
||||
var account = {
|
||||
emailAddress: userId,
|
||||
symKeySize: app.config.symKeySize,
|
||||
symIvSize: app.config.symIvSize,
|
||||
asymKeySize: app.config.asymKeySize
|
||||
});
|
||||
};
|
||||
emailDao.init(account, password, callback);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ define(function(require) {
|
||||
jsonDB = require('js/dao/lawnchair-dao'),
|
||||
devicestorage = require('js/dao/devicestorage-dao'),
|
||||
app = require('js/app-config');
|
||||
require('js/model/account-model');
|
||||
|
||||
/**
|
||||
* A high-level Data-Access Api for handling Email synchronization
|
||||
@ -30,7 +29,7 @@ define(function(require) {
|
||||
self.account = account;
|
||||
|
||||
// validate email address
|
||||
var emailAddress = account.get('emailAddress');
|
||||
var emailAddress = account.emailAddress;
|
||||
if (!validateEmail(emailAddress)) {
|
||||
callback({
|
||||
errMsg: 'The user email address must be specified!'
|
||||
@ -70,8 +69,8 @@ define(function(require) {
|
||||
crypto.init({
|
||||
emailAddress: emailAddress,
|
||||
password: password,
|
||||
keySize: account.get('symKeySize'),
|
||||
rsaKeySize: account.get('asymKeySize'),
|
||||
keySize: account.symKeySize,
|
||||
rsaKeySize: account.asymKeySize,
|
||||
storedKeypair: storedKeypair
|
||||
}, function(err, generatedKeypair) {
|
||||
if (err) {
|
||||
@ -89,6 +88,65 @@ define(function(require) {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// New IMAP/SMTP implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* Cleanup by logging the user off.
|
||||
*/
|
||||
EmailDAO.prototype.destroy = function(callback) {
|
||||
var self = this;
|
||||
|
||||
self._imapClient.logout(callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send an email client side via STMP.
|
||||
*/
|
||||
EmailDAO.prototype.smtpSend = function(email, callback) {
|
||||
var self = this;
|
||||
|
||||
// validate the email input
|
||||
if (!email.to || !email.from || !email.to[0].address || !email.from[0].address) {
|
||||
callback({
|
||||
errMsg: 'Invalid email object!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self._smtpClient.send(email, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* List the folders in the user's IMAP mailbox.
|
||||
*/
|
||||
EmailDAO.prototype.imapListFolders = function(callback) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* List messages from an imap folder. This will not yet fetch the email body.
|
||||
* @param {String} options.folderName The name of the imap folder.
|
||||
* @param {Number} offset The offset of items to fetch (0 is the last stored item)
|
||||
* @param {Number} num The number of items to fetch (null means fetch all)
|
||||
*/
|
||||
EmailDAO.prototype.imapListMessages = function(options, callback) {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an email messsage including the email body from imap
|
||||
* @param {String} options.messageId The
|
||||
*/
|
||||
EmailDAO.prototype.imapGetMessage = function(options, callback) {
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// Old cloud storage implementation
|
||||
//
|
||||
|
||||
/**
|
||||
* Fetch an email with the following id
|
||||
*/
|
||||
@ -333,15 +391,10 @@ define(function(require) {
|
||||
}
|
||||
|
||||
function send(email) {
|
||||
if (self._smtpClient) {
|
||||
// send email directly client side
|
||||
self._smtpClient.send(email, callback);
|
||||
} else {
|
||||
// send email via cloud service
|
||||
self._cloudstorage.deliverEmail(email, userId, recipient, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
// send email via cloud service
|
||||
self._cloudstorage.deliverEmail(email, userId, recipient, function(err) {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -349,6 +402,10 @@ define(function(require) {
|
||||
// helper functions
|
||||
//
|
||||
|
||||
/**
|
||||
* Validates an email address
|
||||
*/
|
||||
|
||||
function validateEmail(email) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(email);
|
||||
|
20
test/new-unit/app-controller-test.js
Normal file
20
test/new-unit/app-controller-test.js
Normal file
@ -0,0 +1,20 @@
|
||||
define(function() {
|
||||
'use strict';
|
||||
|
||||
var expect = chai.expect;
|
||||
|
||||
describe('App Controller unit tests', function() {
|
||||
|
||||
beforeEach(function() {});
|
||||
|
||||
afterEach(function() {});
|
||||
|
||||
describe('init', function() {
|
||||
it('should not explode', function() {
|
||||
expect(true).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@ -10,7 +10,7 @@ define(function() {
|
||||
afterEach(function() {});
|
||||
|
||||
describe('init', function() {
|
||||
it('should fail due to error in imap login', function() {
|
||||
it('should not explode', function() {
|
||||
expect(true).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,6 @@ define(function(require) {
|
||||
EmailDAO = require('js/dao/email-dao'),
|
||||
SmtpClient = require('SmtpClient'),
|
||||
ImapClient = require('ImapClient'),
|
||||
Account = require('js/model/account-model'),
|
||||
app = require('js/app-config'),
|
||||
expect = chai.expect;
|
||||
|
||||
@ -15,18 +14,30 @@ define(function(require) {
|
||||
asymKeySize: 512
|
||||
};
|
||||
|
||||
var dummyMail = {
|
||||
from: [{
|
||||
name: 'Whiteout Test',
|
||||
address: 'whiteout.test@t-online.de'
|
||||
}], // sender address
|
||||
to: [{
|
||||
address: 'safewithme.testuser@gmail.com'
|
||||
}], // list of receivers
|
||||
subject: "Hello", // Subject line
|
||||
body: "Hello world" // plaintext body
|
||||
};
|
||||
|
||||
describe('Email DAO unit tests', function() {
|
||||
|
||||
var emailDao, account,
|
||||
keychainStub, imapClientStub, smtpClientStub;
|
||||
|
||||
beforeEach(function() {
|
||||
account = new Account({
|
||||
account = {
|
||||
emailAddress: emaildaoTest.user,
|
||||
symKeySize: app.config.symKeySize,
|
||||
symIvSize: app.config.symIvSize,
|
||||
asymKeySize: emaildaoTest.asymKeySize
|
||||
});
|
||||
};
|
||||
|
||||
keychainStub = sinon.createStubInstance(KeychainDAO);
|
||||
imapClientStub = sinon.createStubInstance(ImapClient);
|
||||
@ -38,7 +49,6 @@ define(function(require) {
|
||||
afterEach(function() {});
|
||||
|
||||
describe('init', function() {
|
||||
|
||||
it('should fail due to error in imap login', function(done) {
|
||||
imapClientStub.login.yields(42);
|
||||
|
||||
@ -59,7 +69,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
it('should initialize', function(done) {
|
||||
it('should init with new keygen', function(done) {
|
||||
imapClientStub.login.yields();
|
||||
keychainStub.getUserKeyPair.yields();
|
||||
keychainStub.putUserKeyPair.yields();
|
||||
@ -74,6 +84,47 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('IMAP/SMTP tests', function() {
|
||||
beforeEach(function(done) {
|
||||
imapClientStub.login.yields();
|
||||
keychainStub.getUserKeyPair.yields();
|
||||
keychainStub.putUserKeyPair.yields();
|
||||
|
||||
emailDao.init(account, emaildaoTest.passphrase, function(err) {
|
||||
expect(imapClientStub.login.calledOnce).to.be.true;
|
||||
expect(keychainStub.getUserKeyPair.calledOnce).to.be.true;
|
||||
expect(keychainStub.putUserKeyPair.calledOnce).to.be.true;
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
imapClientStub.logout.yields();
|
||||
emailDao.destroy(function(err) {
|
||||
expect(imapClientStub.logout.calledOnce).to.be.true;
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('send an email via STMP bad case', function(done) {
|
||||
emailDao.smtpSend({}, function(err) {
|
||||
expect(smtpClientStub.send.called).to.be.false;
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('send an email via STMP good case', function(done) {
|
||||
smtpClientStub.send.yields();
|
||||
emailDao.smtpSend(dummyMail, function(err) {
|
||||
expect(smtpClientStub.send.calledOnce).to.be.true;
|
||||
expect(err).to.not.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@ -21,7 +21,7 @@ function startTests() {
|
||||
require(
|
||||
[
|
||||
'test/new-unit/email-dao-test',
|
||||
'test/new-unit/cloudstorage-dao-test'
|
||||
'test/new-unit/app-controller-test'
|
||||
], function() {
|
||||
//Tests loaded, run tests
|
||||
mocha.run();
|
||||
|
Loading…
Reference in New Issue
Block a user