1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 10:22:18 -05:00

Sending email from client works

This commit is contained in:
Tankred Hase 2013-05-03 16:09:13 +02:00
parent eda008258d
commit b1bc03b74b
4 changed files with 65 additions and 8 deletions

View File

@ -29,8 +29,13 @@
this.changePage(loginView); this.changePage(loginView);
}, },
compose: function() { compose: function(to, reSubject, reBody) {
var composeView = new app.view.ComposeView(); var composeView = new app.view.ComposeView({
to: to,
reSubject: reSubject,
reBody: reBody,
dao: this.emailDao
});
this.changePage(composeView); this.changePage(composeView);
}, },

View File

@ -239,6 +239,9 @@ 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');
// generate a new UUID for the new email
email.set('id', util.UUID());
cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) { cloudstorage.putEncryptedItem(email, 'email', userId, 'outbox', function(err) {
callback(err); callback(err);
}); });

View File

@ -3,14 +3,63 @@
app.view.ComposeView = Backbone.View.extend({ app.view.ComposeView = Backbone.View.extend({
initialize: function() { initialize: function(args) {
this.template = _.template(app.util.tpl.get('compose')); this.template = _.template(app.util.tpl.get('compose'));
this.dao = args.dao;
}, },
render: function(eventName) { render: function(eventName) {
$(this.el).html(this.template()); var self = this,
page = $(this.el);
page.html(this.template());
page.find('#sendBtn').on('vmousedown', function() {
self.sendEmail();
});
return this; return this;
},
/**
* Send an email via the email dao
*/
sendEmail: function() {
var self = this,
page = $(this.el);
$.mobile.loading('show', {
text: 'sending...',
textVisible: true
});
// validate recipients
var to = page.find('#toInput').val().replace(/\s/g, '').split(/[,;]/);
if (!to || to.length < 1) {
window.alert('Seperate recipients with a comma!');
return;
}
var signature = '\n\nSent with https://mail.whiteout.io - get your mailbox for end-2-end encrypted messaging!';
var email = new app.model.Email({
from: self.dao.account.get('emailAddress'),
to: to,
subject: page.find('#subjectInput').val(),
body: page.find('#bodyTextarea').val() + signature
});
self.dao.sendEmail(email, function(err) {
$.mobile.loading('hide');
if (err) {
window.alert(JSON.stringify(err));
return;
}
//window.history.back();
});
} }
}); });
}()); }());

View File

@ -1,11 +1,11 @@
<div data-role="header" data-position="fixed"> <div data-role="header" data-position="fixed">
<input type="button" id="backBtn" data-icon="delete" value="Cancel" class="ui-btn-left"> <input type="button" id="backBtn" data-icon="delete" value="Cancel" class="ui-btn-left">
<h1>New Mail</h1> <h1>New Mail</h1>
<input type="button" id="backBtn" data-icon="check" data-iconpos="right" value="Send" class="ui-btn-right"> <input type="button" id="sendBtn" data-icon="check" data-iconpos="right" value="Send" class="ui-btn-right">
</div><!-- /header --> </div><!-- /header -->
<div data-role="content"> <div data-role="content">
<input type="email" name="to" id="to" placeholder="to:"/> <input type="email" name="to" id="toInput" placeholder="to:"/>
<input type="text" name="subject" id="subject" placeholder="subject:"/> <input type="text" name="subject" id="subjectInput" placeholder="subject:"/>
<textarea name="textarea" class="message-input" id="textarea-msg"></textarea> <textarea name="textarea" class="message-input" id="bodyTextarea"></textarea>
</div><!-- /content --> </div><!-- /content -->