1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -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
if (!receiverPubkey) {
// user hasn't registered a public key yet... invite
callback({
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
*/
@ -179,7 +173,7 @@ define(function(require) {
var self = this,
ptItems = [email],
receiverPubkeys = [receiverPubkey],
to, greeting, ct, i;
i;
// add attachment to encryption batch and remove from email object
if (email.attachments) {
@ -197,14 +191,8 @@ define(function(require) {
return;
}
// 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
ct = btoa(JSON.stringify(encryptedList[0]));
email.body = greeting + MESSAGE + PREFIX + ct + SUFFIX + SIGNATURE;
email.subject = SUBJECT;
// replace body and subject of the email with encrypted versions
email = self.frameEncryptedMessage(email, encryptedList[0]);
// add encrypted attachments
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) {
var self = this;
@ -381,7 +390,7 @@ define(function(require) {
self._imapClient.getMessage({
path: options.folder,
uid: options.uid,
onMessageBody: messageReady,
onMessage: messageReady,
/*onAttachment: attachmentReady*/
});
};

View File

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

View File

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