changed html and text view

This commit is contained in:
Tankred Hase 2013-05-04 13:02:17 +02:00
parent b1bc03b74b
commit 7e137549d0
6 changed files with 61 additions and 22 deletions

View File

@ -29,11 +29,10 @@
this.changePage(loginView); this.changePage(loginView);
}, },
compose: function(to, reSubject, reBody) { compose: function(userId, folder, messageId) {
var composeView = new app.view.ComposeView({ var composeView = new app.view.ComposeView({
to: to, folder: folder,
reSubject: reSubject, messageId: decodeURIComponent(messageId),
reBody: reBody,
dao: this.emailDao dao: this.emailDao
}); });
this.changePage(composeView); this.changePage(composeView);
@ -64,7 +63,7 @@
dao: this.emailDao dao: this.emailDao
}); });
this.changePage(readView); this.changePage(readView);
readView.renderBody(); readView.renderBody(true);
}, },
changePage: function(page) { changePage: function(page) {

View File

@ -239,12 +239,34 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, naclCrypto,
this.sendEmail = function(email, callback) { this.sendEmail = function(email, callback) {
var userId = this.account.get('emailAddress'); 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 // generate a new UUID for the new email
email.set('id', util.UUID()); email.set('id', util.UUID());
// send email to cloud service
cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) { cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) {
callback(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);
}
}; };
}; };

View File

@ -6,6 +6,10 @@
initialize: function(args) { initialize: function(args) {
this.template = _.template(app.util.tpl.get('compose')); this.template = _.template(app.util.tpl.get('compose'));
this.dao = args.dao; 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) { render: function(eventName) {
@ -40,7 +44,7 @@
return; 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({ var email = new app.model.Email({
from: self.dao.account.get('emailAddress'), from: self.dao.account.get('emailAddress'),

View File

@ -10,12 +10,23 @@
render: function(eventName) { render: function(eventName) {
$(this.el).html(this.template(this.model.toJSON())); $(this.el).html(this.template(this.model.toJSON()));
this.renderBody();
return this; return this;
}, },
renderBody: function() { renderBody: function(tryHtml) {
var emailBody = this.model.get('body'), var page = $(this.el),
iframe = $('#idMailContent'), emailBody = this.model.get('body');
if (!tryHtml && emailBody.indexOf('</') === -1) {
// render text email
page.find('#bodyItem').html('<textarea></textarea>');
page.find('#bodyItem textarea').text(emailBody);
} else if (tryHtml && emailBody.indexOf('</') !== -1) {
// render html email inside a sandboxed iframe
var iframe = page.find('#idMailContent'),
iframeDoc = iframe[0].contentDocument || iframe[0].contentWindow.document; iframeDoc = iframe[0].contentDocument || iframe[0].contentWindow.document;
iframe.load(function() { iframe.load(function() {
@ -29,6 +40,7 @@
iframeDoc.write(emailBody); iframeDoc.write(emailBody);
iframeDoc.close(); iframeDoc.close();
} }
}
}); });

View File

@ -1,5 +1,5 @@
<a href="#accounts/<%- account %>/folders/<%- folder %>/read/<%- id %>"> <a href="#accounts/<%- account %>/folders/<%- folder %>/read/<%- id %>">
<h3><%- from[0].name %></h3> <h3><%- from[0].name || from[0].address %></h3>
<p><strong><%- subject %></strong></p> <p><strong><%- subject %></strong></p>
<!-- <p><%- body %></p> --> <!-- <p><%- body %></p> -->
<p class="ui-li-aside"><strong><%- displayDate %></strong></p> <p class="ui-li-aside"><strong><%- displayDate %></strong></p>

View File

@ -21,8 +21,10 @@
<p id="idMailDate"><%- sentDate %></p> <p id="idMailDate"><%- sentDate %></p>
</li> </li>
<li id="bodyItem" style="font-size: 8pt; font-weight: normal; background-color: #FFFFFF"> <li id="bodyItem" style="background-color: #FFFFFF">
<div style="font-size: 8pt; font-weight: normal">
<iframe id="idMailContent" sandbox="allow-same-origin" width="100%" height="100%" frameborder="0" scrolling="no"></iframe> <iframe id="idMailContent" sandbox="allow-same-origin" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>
</div>
</li> </li>
</ul> </ul>