mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 08:52:15 -05:00
changed html and text view
This commit is contained in:
parent
b1bc03b74b
commit
7e137549d0
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
@ -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'),
|
||||
|
@ -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('</') === -1) {
|
||||
// render text email
|
||||
page.find('#bodyItem').html('<textarea></textarea>');
|
||||
page.find('#bodyItem textarea').text(emailBody);
|
||||
|
||||
iframeDoc.write(emailBody);
|
||||
iframeDoc.close();
|
||||
} 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;
|
||||
|
||||
iframe.load(function() {
|
||||
// resize
|
||||
var newheight = iframeDoc.body.scrollHeight;
|
||||
var newwidth = iframeDoc.body.scrollWidth;
|
||||
iframe[0].height = (newheight) + 'px';
|
||||
iframe[0].width = (newwidth) + 'px';
|
||||
});
|
||||
|
||||
iframeDoc.write(emailBody);
|
||||
iframeDoc.close();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
<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><%- body %></p> -->
|
||||
<p class="ui-li-aside"><strong><%- displayDate %></strong></p>
|
||||
|
@ -21,8 +21,10 @@
|
||||
<p id="idMailDate"><%- sentDate %></p>
|
||||
</li>
|
||||
|
||||
<li id="bodyItem" style="font-size: 8pt; font-weight: normal; background-color: #FFFFFF">
|
||||
<iframe id="idMailContent" sandbox="allow-same-origin" width="100%" height="100%" frameborder="0" scrolling="no"></iframe>
|
||||
<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>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user