mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 17:02:17 -05:00
Merge remote-tracking branch 'origin/pgp-format' into invitation
This commit is contained in:
commit
34dea03c5b
@ -35,7 +35,7 @@ define([], function() {
|
|||||||
* Strings are maintained here
|
* Strings are maintained here
|
||||||
*/
|
*/
|
||||||
app.string = {
|
app.string = {
|
||||||
subject: '[whiteout] Encrypted message',
|
subjectPrefix: '[whiteout] ',
|
||||||
message: 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg',
|
message: 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg',
|
||||||
cryptPrefix: '-----BEGIN PGP MESSAGE-----',
|
cryptPrefix: '-----BEGIN PGP MESSAGE-----',
|
||||||
cryptSuffix: '-----END PGP MESSAGE-----',
|
cryptSuffix: '-----END PGP MESSAGE-----',
|
||||||
|
@ -246,6 +246,7 @@ define(function(require) {
|
|||||||
messageBlock = email.body.split(str.cryptPrefix)[1].split(str.cryptSuffix)[0];
|
messageBlock = email.body.split(str.cryptPrefix)[1].split(str.cryptSuffix)[0];
|
||||||
// add prefix and suffix again
|
// add prefix and suffix again
|
||||||
email.body = str.cryptPrefix + messageBlock + str.cryptSuffix;
|
email.body = str.cryptPrefix + messageBlock + str.cryptSuffix;
|
||||||
|
email.subject = email.subject.split(str.subjectPrefix)[1];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Error parsing encrypted message block!'
|
errMsg: 'Error parsing encrypted message block!'
|
||||||
@ -273,9 +274,7 @@ define(function(require) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
decrypted = JSON.parse(decrypted);
|
i.body = decrypted;
|
||||||
i.subject = decrypted.subject;
|
|
||||||
i.body = decrypted.body;
|
|
||||||
|
|
||||||
after();
|
after();
|
||||||
});
|
});
|
||||||
@ -310,7 +309,7 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function fetchList(callback) {
|
function fetchList(callback) {
|
||||||
var encryptedList = [];
|
var headers = [];
|
||||||
|
|
||||||
// fetch imap folder's message list
|
// fetch imap folder's message list
|
||||||
self.imapListMessages({
|
self.imapListMessages({
|
||||||
@ -325,45 +324,50 @@ define(function(require) {
|
|||||||
|
|
||||||
// find encrypted messages by subject
|
// find encrypted messages by subject
|
||||||
emails.forEach(function(i) {
|
emails.forEach(function(i) {
|
||||||
if (i.subject === str.subject) {
|
if (i.subject.indexOf(str.subjectPrefix) !== -1) {
|
||||||
encryptedList.push(i);
|
headers.push(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// fetch message bodies
|
// fetch message bodies
|
||||||
fetchBodies(encryptedList, callback);
|
fetchBodies(headers, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchBodies(messageList, callback) {
|
function fetchBodies(headers, callback) {
|
||||||
var emails = [];
|
var emails = [];
|
||||||
|
|
||||||
if (messageList.length < 1) {
|
if (headers.length < 1) {
|
||||||
callback(null, emails);
|
callback(null, emails);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var after = _.after(messageList.length, function() {
|
var after = _.after(headers.length, function() {
|
||||||
callback(null, emails);
|
callback(null, emails);
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(messageList, function(messageItem) {
|
_.each(headers, function(header) {
|
||||||
self.imapGetMessage({
|
self.imapGetMessage({
|
||||||
folder: options.folder,
|
folder: options.folder,
|
||||||
uid: messageItem.uid
|
uid: header.uid
|
||||||
}, function(err, message) {
|
}, function(err, message) {
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set gotten attributes like body to message object containing list meta data like 'unread' or 'replied'
|
if (typeof message.body !== 'string' || message.body.indexOf(str.cryptPrefix) === -1 || message.body.indexOf(str.cryptSuffix) === -1) {
|
||||||
messageItem.id = message.id;
|
after();
|
||||||
messageItem.body = message.body;
|
return;
|
||||||
messageItem.html = message.html;
|
}
|
||||||
messageItem.attachments = message.attachments;
|
|
||||||
|
|
||||||
emails.push(messageItem);
|
// set gotten attributes like body to message object containing list meta data like 'unread' or 'replied'
|
||||||
|
header.id = message.id;
|
||||||
|
header.body = message.body;
|
||||||
|
header.html = message.html;
|
||||||
|
header.attachments = message.attachments;
|
||||||
|
|
||||||
|
emails.push(header);
|
||||||
after();
|
after();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -514,7 +518,7 @@ define(function(require) {
|
|||||||
*/
|
*/
|
||||||
EmailDAO.prototype.encryptForUser = function(email, receiverPubkey, callback) {
|
EmailDAO.prototype.encryptForUser = function(email, receiverPubkey, callback) {
|
||||||
var self = this,
|
var self = this,
|
||||||
pt = JSON.stringify(email),
|
pt = email.body,
|
||||||
receiverPubkeys = [receiverPubkey];
|
receiverPubkeys = [receiverPubkey];
|
||||||
|
|
||||||
// get own public key so send message can be read
|
// get own public key so send message can be read
|
||||||
@ -557,7 +561,7 @@ define(function(require) {
|
|||||||
|
|
||||||
// build encrypted text body
|
// build encrypted text body
|
||||||
email.body = greeting + MESSAGE + ct + SIGNATURE;
|
email.body = greeting + MESSAGE + ct + SIGNATURE;
|
||||||
email.subject = str.subject;
|
email.subject = str.subjectPrefix + email.subject;
|
||||||
|
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ define(function(require) {
|
|||||||
to: [{
|
to: [{
|
||||||
address: 'safewithme.testuser@gmail.com'
|
address: 'safewithme.testuser@gmail.com'
|
||||||
}], // list of receivers
|
}], // list of receivers
|
||||||
subject: "Hello", // Subject line
|
subject: "[whiteout] Hello", // Subject line
|
||||||
body: "Hello world" // plaintext body
|
body: "Hello world" // plaintext body
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -521,8 +521,10 @@ define(function(require) {
|
|||||||
it('should not list unencrypted messages', function(done) {
|
it('should not list unencrypted messages', function(done) {
|
||||||
imapClientStub.listMessages.yields(null, [{
|
imapClientStub.listMessages.yields(null, [{
|
||||||
uid: 413,
|
uid: 413,
|
||||||
|
subject: ''
|
||||||
}, {
|
}, {
|
||||||
uid: 414,
|
uid: 414,
|
||||||
|
subject: ''
|
||||||
}]);
|
}]);
|
||||||
imapClientStub.getMessagePreview.yields(null, {
|
imapClientStub.getMessagePreview.yields(null, {
|
||||||
body: 'asdf'
|
body: 'asdf'
|
||||||
@ -547,13 +549,13 @@ define(function(require) {
|
|||||||
it('should work', function(done) {
|
it('should work', function(done) {
|
||||||
imapClientStub.listMessages.yields(null, [{
|
imapClientStub.listMessages.yields(null, [{
|
||||||
uid: 413,
|
uid: 413,
|
||||||
subject: app.string.subject
|
subject: app.string.subjectPrefix + 'asd'
|
||||||
}, {
|
}, {
|
||||||
uid: 414,
|
uid: 414,
|
||||||
subject: app.string.subject
|
subject: app.string.subjectPrefix + 'asd'
|
||||||
}]);
|
}]);
|
||||||
imapClientStub.getMessagePreview.yields(null, {
|
imapClientStub.getMessagePreview.yields(null, {
|
||||||
body: 'asdf'
|
body: app.string.cryptPrefix + '\nasdf\n' + app.string.cryptSuffix
|
||||||
});
|
});
|
||||||
devicestorageStub.removeList.yields();
|
devicestorageStub.removeList.yields();
|
||||||
devicestorageStub.storeList.yields();
|
devicestorageStub.storeList.yields();
|
||||||
@ -582,20 +584,17 @@ define(function(require) {
|
|||||||
userId: "safewithme.testuser@gmail.com",
|
userId: "safewithme.testuser@gmail.com",
|
||||||
publicKey: publicKey
|
publicKey: publicKey
|
||||||
});
|
});
|
||||||
pgpStub.decrypt.yields(null, JSON.stringify({
|
pgpStub.decrypt.yields(null, 'test body');
|
||||||
body: 'test body',
|
|
||||||
subject: 'test subject'
|
|
||||||
}));
|
|
||||||
|
|
||||||
emailDao.listMessages({
|
emailDao.listMessages({
|
||||||
folder: 'INBOX',
|
folder: 'INBOX',
|
||||||
offset: 0,
|
offset: 0,
|
||||||
num: 2
|
num: 2
|
||||||
}, function(err, emails) {
|
}, function(err, emails) {
|
||||||
|
expect(err).to.not.exist;
|
||||||
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
expect(devicestorageStub.listItems.calledOnce).to.be.true;
|
||||||
expect(keychainStub.getReceiverPublicKey.calledTwice).to.be.true;
|
expect(keychainStub.getReceiverPublicKey.calledTwice).to.be.true;
|
||||||
expect(pgpStub.decrypt.calledTwice).to.be.true;
|
expect(pgpStub.decrypt.calledTwice).to.be.true;
|
||||||
expect(err).to.not.exist;
|
|
||||||
expect(emails.length).to.equal(2);
|
expect(emails.length).to.equal(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user