1
0
mirror of https://github.com/moparisthebest/mail synced 2025-02-16 15:10:10 -05:00

cleanup and integrate new imap-client

This commit is contained in:
Tankred Hase 2013-08-29 19:32:34 +02:00
parent a8d49a632c
commit bc9e635270
3 changed files with 28 additions and 19 deletions

View File

@ -154,6 +154,7 @@ define(function(require) {
// validate public key // validate public key
if (!receiverPubkey) { if (!receiverPubkey) {
// user hasn't registered a public key yet... invite
callback({ callback({
errMsg: 'No public key found for: ' + email.from errMsg: 'No public key found for: ' + email.from
}); });
@ -165,13 +166,6 @@ define(function(require) {
}); });
}; };
/**
* Encrypt an email symmetrically
*/
// EmailDAO.prototype.encryptForNewUser = function(email, callback) {
// };
/** /**
* Encrypt an email asymmetrically for an exisiting user with their public key * Encrypt an email asymmetrically for an exisiting user with their public key
*/ */
@ -179,7 +173,7 @@ define(function(require) {
var self = this, var self = this,
ptItems = [email], ptItems = [email],
receiverPubkeys = [receiverPubkey], receiverPubkeys = [receiverPubkey],
to, greeting, ct, i; i;
// add attachment to encryption batch and remove from email object // add attachment to encryption batch and remove from email object
if (email.attachments) { if (email.attachments) {
@ -197,14 +191,8 @@ define(function(require) {
return; return;
} }
// get first name of recipient // replace body and subject of the email with encrypted versions
to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0]; email = self.frameEncryptedMessage(email, encryptedList[0]);
greeting = 'Hi ' + to + ',\n\n';
// build encrypted text body
ct = btoa(JSON.stringify(encryptedList[0]));
email.body = greeting + MESSAGE + PREFIX + ct + SUFFIX + SIGNATURE;
email.subject = SUBJECT;
// add encrypted attachments // add encrypted attachments
if (encryptedList.length > 1) { if (encryptedList.length > 1) {
@ -222,6 +210,27 @@ define(function(require) {
}); });
}; };
/**
* Frames an encrypted message in base64 Format
*/
EmailDAO.prototype.frameEncryptedMessage = function(email, ct) {
var to, greeting, ctBase64;
// get first name of recipient
to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0];
greeting = 'Hi ' + to + ',\n\n';
// build encrypted text body
ctBase64 = btoa(JSON.stringify(ct));
email.body = greeting + MESSAGE + PREFIX + ctBase64 + SUFFIX + SIGNATURE;
email.subject = SUBJECT;
return email;
};
/**
* Send an actual message object via smtp
*/
EmailDAO.prototype.send = function(email, callback) { EmailDAO.prototype.send = function(email, callback) {
var self = this; var self = this;
@ -381,7 +390,7 @@ define(function(require) {
self._imapClient.getMessage({ self._imapClient.getMessage({
path: options.folder, path: options.folder,
uid: options.uid, uid: options.uid,
onMessageBody: messageReady, onMessage: messageReady,
/*onAttachment: attachmentReady*/ /*onAttachment: attachmentReady*/
}); });
}; };

View File

@ -42,7 +42,7 @@ define(['jquery', 'underscore', 'backbone', 'js/app-config'], function($, _, Bac
parseAttachments: function() { parseAttachments: function() {
var attachments = this.model.attachments; var attachments = this.model.attachments;
if (!attachments) { if (!attachments || attachments.length < 1) {
// remove link if no attachments are present // remove link if no attachments are present
$(this.el).find('#attachmentItem').remove(); $(this.el).find('#attachmentItem').remove();
return; return;

View File

@ -272,7 +272,7 @@ define(function(require) {
it('should parse message body without attachement', function(done) { it('should parse message body without attachement', function(done) {
var uid = 415; var uid = 415;
imapClientStub.getMessage.yieldsTo('onMessageBody', null, { imapClientStub.getMessage.yieldsTo('onMessage', null, {
uid: uid, uid: uid,
body: '' body: ''
}); });