diff --git a/src/js/app-router.js b/src/js/app-router.js index bc0282d..d2e9fcc 100644 --- a/src/js/app-router.js +++ b/src/js/app-router.js @@ -29,11 +29,10 @@ this.changePage(loginView); }, - compose: function(to, reSubject, reBody) { + compose: function(userId, folder, messageId) { var composeView = new app.view.ComposeView({ - to: to, - reSubject: reSubject, - reBody: reBody, + folder: folder, + messageId: decodeURIComponent(messageId), dao: this.emailDao }); this.changePage(composeView); @@ -64,7 +63,7 @@ dao: this.emailDao }); this.changePage(readView); - readView.renderBody(); + readView.renderBody(true); }, changePage: function(page) { diff --git a/src/js/dao/email-dao.js b/src/js/dao/email-dao.js index 46c3109..41f34de 100644 --- a/src/js/dao/email-dao.js +++ b/src/js/dao/email-dao.js @@ -239,12 +239,34 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, naclCrypto, this.sendEmail = function(email, callback) { var userId = this.account.get('emailAddress'); + // validate email addresses + _.each(email.get('to'), function(address) { + if (!validateEmail(address)) { + callback({ + errMsg: 'Invalid recipient: ' + address + }); + return; + } + }); + if (!validateEmail(email.get('from'))) { + callback({ + errMsg: 'Invalid sender: ' + email.from + }); + return; + } + // generate a new UUID for the new email email.set('id', util.UUID()); + // send email to cloud service cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) { callback(err); }); + + function validateEmail(email) { + var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(email); + } }; }; \ No newline at end of file diff --git a/src/js/view/compose-view.js b/src/js/view/compose-view.js index 1431730..318a048 100644 --- a/src/js/view/compose-view.js +++ b/src/js/view/compose-view.js @@ -6,6 +6,10 @@ initialize: function(args) { this.template = _.template(app.util.tpl.get('compose')); this.dao = args.dao; + if (args.folder && args.messageId) { + // fetch reply-to email model + this.replyTo = args.dao.getItem(args.folder, args.messageId); + } }, render: function(eventName) { @@ -40,7 +44,7 @@ return; } - var signature = '\n\nSent with https://mail.whiteout.io - get your mailbox for end-2-end encrypted messaging!'; + var signature = '\n\nSent with whiteout.io - get your mailbox for end-2-end encrypted messaging!\nhttps://mail.whiteout.io'; var email = new app.model.Email({ from: self.dao.account.get('emailAddress'), diff --git a/src/js/view/read-view.js b/src/js/view/read-view.js index 9b77989..e9c7f53 100644 --- a/src/js/view/read-view.js +++ b/src/js/view/read-view.js @@ -10,24 +10,36 @@ render: function(eventName) { $(this.el).html(this.template(this.model.toJSON())); + this.renderBody(); + return this; }, - renderBody: function() { - var emailBody = this.model.get('body'), - iframe = $('#idMailContent'), - iframeDoc = iframe[0].contentDocument || iframe[0].contentWindow.document; + renderBody: function(tryHtml) { + var page = $(this.el), + emailBody = this.model.get('body'); - iframe.load(function() { - // resize - var newheight = iframeDoc.body.scrollHeight; - var newwidth = iframeDoc.body.scrollWidth; - iframe[0].height = (newheight) + 'px'; - iframe[0].width = (newwidth) + 'px'; - }); + if (!tryHtml && emailBody.indexOf(''); + page.find('#bodyItem textarea').text(emailBody); - iframeDoc.write(emailBody); - iframeDoc.close(); + } else if (tryHtml && emailBody.indexOf('/folders/<%- folder %>/read/<%- id %>"> -

<%- from[0].name %>

+

<%- from[0].name || from[0].address %>

<%- subject %>

<%- displayDate %>

diff --git a/src/tpl/read.html b/src/tpl/read.html index 645069f..46c75c9 100644 --- a/src/tpl/read.html +++ b/src/tpl/read.html @@ -21,8 +21,10 @@

<%- sentDate %>

-
  • - +
  • +
    + +