mirror of
https://github.com/moparisthebest/mail
synced 2024-11-26 02:42:17 -05:00
implement get message from imap in email dao and app controller
This commit is contained in:
parent
feae2b0c2b
commit
fa3abc3487
@ -85,10 +85,14 @@ define(function(require) {
|
||||
|
||||
} else if (cmd === 'getEmail') {
|
||||
// list emails from folder
|
||||
var mail = self._emailDao.getItem(args.folder, args.messageId);
|
||||
self._emailDao.imapGetMessage({
|
||||
folder: args.folder,
|
||||
uid: args.messageId
|
||||
}, function(err, email) {
|
||||
callback({
|
||||
err: null,
|
||||
email: mail
|
||||
err: err,
|
||||
email: email
|
||||
});
|
||||
});
|
||||
|
||||
} else if (cmd === 'sendEmail') {
|
||||
|
@ -156,9 +156,30 @@ define(function(require) {
|
||||
* @param {String} options.messageId The
|
||||
*/
|
||||
EmailDAO.prototype.imapGetMessage = function(options, callback) {
|
||||
var self = this,
|
||||
message;
|
||||
|
||||
// validate options
|
||||
if (!options.folder || !options.uid) {
|
||||
callback({
|
||||
errMsg: 'Not yet implemented!'
|
||||
errMsg: 'Invalid options!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
function messageReady(err, gottenMessage) {
|
||||
message = gottenMessage;
|
||||
}
|
||||
|
||||
function attachmentReady(err, attmt) {
|
||||
message.parsedAttachment = attmt;
|
||||
callback(null, message);
|
||||
}
|
||||
|
||||
self._imapClient.getMessage({
|
||||
path: options.folder,
|
||||
uid: options.uid
|
||||
}, messageReady, attachmentReady);
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -1,4 +1,4 @@
|
||||
<a href="#accounts/<%- account %>/folders/<%- folder %>/read/<%- id %>">
|
||||
<a href="#accounts/<%- account %>/folders/<%- folder %>/read/<%- uid %>">
|
||||
<h3><%- from[0].name || from[0].address %></h3>
|
||||
<p><strong><%- subject %></strong></p>
|
||||
<!-- <p><%- body %></p> -->
|
||||
|
@ -108,6 +108,21 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -108,7 +108,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('send email via SMTP', function() {
|
||||
describe('SMTP: send email', function() {
|
||||
it('should fail due to back input', function(done) {
|
||||
emailDao.smtpSend({}, function(err) {
|
||||
expect(smtpClientStub.send.called).to.be.false;
|
||||
@ -117,7 +117,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
it('send an email via STMP good case', function(done) {
|
||||
it('should work', function(done) {
|
||||
smtpClientStub.send.yields();
|
||||
emailDao.smtpSend(dummyMail, function(err) {
|
||||
expect(smtpClientStub.send.calledOnce).to.be.true;
|
||||
@ -127,7 +127,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('list IMAP folders', function() {
|
||||
describe('IMAP: list folders', function() {
|
||||
it('should work', function(done) {
|
||||
imapClientStub.listFolders.yields();
|
||||
emailDao.imapListFolders(function(err) {
|
||||
@ -138,7 +138,7 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('list IMAP messages from folder', function() {
|
||||
describe('IMAP: list messages from folder', function() {
|
||||
it('should fail due to bad options', function(done) {
|
||||
emailDao.imapListMessages({}, function(err) {
|
||||
expect(imapClientStub.listMessages.called).to.be.false;
|
||||
@ -160,6 +160,46 @@ define(function(require) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('IMAP: get message content from', function() {
|
||||
it('should fail due to bad options', function(done) {
|
||||
emailDao.imapGetMessage({
|
||||
folder: 'INBOX'
|
||||
}, function(err) {
|
||||
expect(imapClientStub.getMessage.called).to.be.false;
|
||||
expect(err).to.exist;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse message body and attachement', function(done) {
|
||||
var uid = 415,
|
||||
newImapClientStub = {
|
||||
getMessage: function() {}
|
||||
};
|
||||
sinon.stub(newImapClientStub, 'getMessage', function(options, messageReady, attachmentReady) {
|
||||
messageReady(null, {
|
||||
uid: uid
|
||||
});
|
||||
attachmentReady(null, {
|
||||
uint8Array: new Uint8Array(42)
|
||||
});
|
||||
});
|
||||
emailDao._imapClient = newImapClientStub;
|
||||
|
||||
emailDao.imapGetMessage({
|
||||
folder: 'INBOX',
|
||||
uid: uid
|
||||
}, function(err, message) {
|
||||
expect(newImapClientStub.getMessage.calledOnce).to.be.true;
|
||||
expect(err).to.not.exist;
|
||||
expect(message.uid).to.equal(uid);
|
||||
expect(message.parsedAttachment.uint8Array.length).to.equal(42);
|
||||
emailDao._imapClient = imapClientStub;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user