mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
integrate mailreader
This commit is contained in:
parent
3d2fdc7f8c
commit
3f1aea5ebb
13
Gruntfile.js
13
Gruntfile.js
@ -133,12 +133,13 @@ module.exports = function(grunt) {
|
||||
'imap-client/node_modules/inbox/node_modules/node-shims/src/*.js',
|
||||
'imap-client/node_modules/inbox/node_modules/utf7/src/utf7.js',
|
||||
'imap-client/node_modules/inbox/node_modules/xoauth2/src/xoauth2.js',
|
||||
'imap-client/node_modules/mimelib/src/mimelib.js',
|
||||
'imap-client/node_modules/mimelib/node_modules/addressparser/src/addressparser.js',
|
||||
'imap-client/node_modules/mimelib/node_modules/encoding/src/encoding.js',
|
||||
'imap-client/node_modules/mimelib/node_modules/encoding/node_modules/iconv-lite/src/*.js',
|
||||
'imap-client/node_modules/mailparser/src/*.js',
|
||||
'imap-client/node_modules/mime/src/mime.js',
|
||||
'mailreader/src/*.js',
|
||||
'mailreader/node_modules/mailparser/src/*.js',
|
||||
'mailreader/node_modules/mailparser/node_modules/encoding/src/encoding.js',
|
||||
'mailreader/node_modules/mailparser/node_modules/mimelib/src/mimelib.js',
|
||||
'mailreader/node_modules/mailparser/node_modules/mimelib/node_modules/addressparser/src/addressparser.js',
|
||||
'mailreader/node_modules/mailparser/node_modules/encoding/node_modules/iconv-lite/src/*.js',
|
||||
'mailreader/node_modules/mailparser/node_modules/mime/src/mime.js',
|
||||
'pgpmailer/src/*.js',
|
||||
'pgpmailer/node_modules/simplesmtp/src/*',
|
||||
'pgpbuilder/src/*.js',
|
||||
|
@ -11,7 +11,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"crypto-lib": "https://github.com/whiteout-io/crypto-lib/tarball/master",
|
||||
"imap-client": "https://github.com/whiteout-io/imap-client/tarball/master",
|
||||
"imap-client": "https://github.com/whiteout-io/imap-client/tarball/dev/offline-bug",
|
||||
"mailreader": "https://github.com/whiteout-io/mailreader/tarball/master",
|
||||
"pgpmailer": "https://github.com/whiteout-io/pgpmailer/tarball/dev/pgpbuilder",
|
||||
"pgpbuilder": "https://github.com/whiteout-io/pgpbuilder/tarball/master",
|
||||
"requirejs": "2.1.10"
|
||||
|
@ -6,6 +6,7 @@ define(function(require) {
|
||||
|
||||
var $ = require('jquery'),
|
||||
ImapClient = require('imap-client'),
|
||||
mailreader = require('mailreader'),
|
||||
PgpMailer = require('pgpmailer'),
|
||||
EmailDAO = require('js/dao/email-dao'),
|
||||
RestDAO = require('js/dao/rest-dao'),
|
||||
@ -117,7 +118,7 @@ define(function(require) {
|
||||
onError: console.error
|
||||
};
|
||||
|
||||
imapClient = new ImapClient(imapOptions);
|
||||
imapClient = new ImapClient(imapOptions, mailreader);
|
||||
pgpMailer = new PgpMailer(smtpOptions, self._pgpbuilder);
|
||||
|
||||
imapClient.onError = function(err) {
|
||||
@ -356,7 +357,7 @@ define(function(require) {
|
||||
pgp = new PGP();
|
||||
self._crypto = pgp;
|
||||
self._pgpbuilder = pgpbuilder = new PgpBuilder({}); // set the worker path?!
|
||||
self._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage, pgpbuilder);
|
||||
self._emailDao = emailDao = new EmailDAO(keychain, pgp, userStorage, pgpbuilder, mailreader);
|
||||
self._outboxBo = new OutboxBO(emailDao, keychain, userStorage, invitationDao);
|
||||
};
|
||||
|
||||
|
@ -6,11 +6,12 @@ define(function(require) {
|
||||
str = require('js/app-config').string,
|
||||
config = require('js/app-config').config;
|
||||
|
||||
var EmailDAO = function(keychain, crypto, devicestorage, pgpbuilder) {
|
||||
var EmailDAO = function(keychain, crypto, devicestorage, pgpbuilder, mailreader) {
|
||||
this._keychain = keychain;
|
||||
this._crypto = crypto;
|
||||
this._devicestorage = devicestorage;
|
||||
this._pgpbuilder = pgpbuilder;
|
||||
this._mailreader = mailreader;
|
||||
};
|
||||
|
||||
//
|
||||
@ -969,7 +970,7 @@ define(function(require) {
|
||||
decrypted = decrypted || err.errMsg || 'Error occurred during decryption';
|
||||
|
||||
// this is a very primitive detection if we have PGP/MIME or PGP/INLINE
|
||||
if (decrypted.indexOf('Content-Transfer-Encoding:') === -1 && decrypted.indexOf('Content-Type:') === -1) {
|
||||
if (!self._mailreader.isRfc(decrypted)) {
|
||||
message.body = decrypted;
|
||||
message.decrypted = true;
|
||||
message.decryptingBody = false;
|
||||
@ -980,7 +981,7 @@ define(function(require) {
|
||||
// parse the decrypted MIME message
|
||||
self._imapParseMessageBlock({
|
||||
message: message,
|
||||
block: decrypted
|
||||
raw: decrypted
|
||||
}, function(error) {
|
||||
if (error) {
|
||||
message.decryptingBody = false;
|
||||
@ -1204,7 +1205,7 @@ define(function(require) {
|
||||
};
|
||||
|
||||
EmailDAO.prototype._imapParseMessageBlock = function(options, callback) {
|
||||
this._imapClient.parseDecryptedMessageBlock(options, callback);
|
||||
this._mailreader.parseRfc(options, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ define(function(require) {
|
||||
PgpBuilder = require('pgpbuilder'),
|
||||
PGP = require('js/crypto/pgp'),
|
||||
DeviceStorageDAO = require('js/dao/devicestorage-dao'),
|
||||
mailreader = require('mailreader'),
|
||||
str = require('js/app-config').string,
|
||||
expect = chai.expect;
|
||||
|
||||
@ -116,7 +117,7 @@ define(function(require) {
|
||||
pgpStub = sinon.createStubInstance(PGP);
|
||||
devicestorageStub = sinon.createStubInstance(DeviceStorageDAO);
|
||||
|
||||
dao = new EmailDAO(keychainStub, pgpStub, devicestorageStub, pgpBuilderStub);
|
||||
dao = new EmailDAO(keychainStub, pgpStub, devicestorageStub, pgpBuilderStub, mailreader);
|
||||
dao._account = account;
|
||||
|
||||
expect(dao._keychain).to.equal(keychainStub);
|
||||
@ -478,14 +479,12 @@ define(function(require) {
|
||||
|
||||
describe('_imapParseMessageBlock', function() {
|
||||
it('should parse a message', function(done) {
|
||||
imapClientStub.parseDecryptedMessageBlock.yields(null, {});
|
||||
var parseRfc = sinon.stub(mailreader, 'parseRfc').withArgs({}).yields();
|
||||
|
||||
dao._imapParseMessageBlock(function(err, msg) {
|
||||
expect(err).to.not.exist;
|
||||
expect(msg).to.exist;
|
||||
dao._imapParseMessageBlock({}, function() {
|
||||
expect(parseRfc.calledOnce).to.be.true;
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@ -1206,14 +1205,14 @@ define(function(require) {
|
||||
body: '-----BEGIN PGP MESSAGE-----asdasdasd-----END PGP MESSAGE-----'
|
||||
};
|
||||
|
||||
mimeBody = 'Content-Transfer-Encoding: Content-Type:';
|
||||
mimeBody = 'Content-Type: asdasdasd';
|
||||
parsedBody = 'body? yes.';
|
||||
|
||||
keychainStub.getReceiverPublicKey.withArgs(message.from[0].address).yieldsAsync(null, mockKeyPair.publicKey);
|
||||
pgpStub.decrypt.withArgs(message.body, mockKeyPair.publicKey.publicKey).yieldsAsync(null, mimeBody);
|
||||
parseStub = sinon.stub(dao, '_imapParseMessageBlock', function(o, cb) {
|
||||
expect(o.message).to.equal(message);
|
||||
expect(o.block).to.equal(mimeBody);
|
||||
expect(o.raw).to.equal(mimeBody);
|
||||
|
||||
o.message.body = parsedBody;
|
||||
cb(null, o.message);
|
||||
|
Loading…
Reference in New Issue
Block a user