mirror of
https://github.com/moparisthebest/mail
synced 2025-02-17 23:40:22 -05:00
composing and sending email works
This commit is contained in:
parent
f2a14ad65b
commit
da3dc17cb4
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
routes: {
|
routes: {
|
||||||
'': 'login',
|
'': 'login',
|
||||||
'compose': 'compose',
|
'compose/:userId': 'compose',
|
||||||
|
'compose/:userId/folders/:folder': 'compose',
|
||||||
'accounts/:userId/folders': 'folders',
|
'accounts/:userId/folders': 'folders',
|
||||||
'accounts/:userId/folders/:folder': 'messagelist',
|
'accounts/:userId/folders/:folder': 'messagelist',
|
||||||
'accounts/:userId/folders/:folder/read/:messageId': 'read',
|
'accounts/:userId/folders/:folder/read/:messageId': 'read',
|
||||||
@ -21,8 +22,9 @@
|
|||||||
|
|
||||||
compose: function(userId, folder, messageId) {
|
compose: function(userId, folder, messageId) {
|
||||||
var composeView = new app.view.ComposeView({
|
var composeView = new app.view.ComposeView({
|
||||||
|
account: userId,
|
||||||
folder: folder,
|
folder: folder,
|
||||||
messageId: decodeURIComponent(messageId)
|
messageId: (messageId) ? decodeURIComponent(messageId) : null
|
||||||
});
|
});
|
||||||
this.changePage(composeView);
|
this.changePage(composeView);
|
||||||
},
|
},
|
||||||
@ -60,12 +62,6 @@
|
|||||||
page.render();
|
page.render();
|
||||||
$('body').append(pageEl);
|
$('body').append(pageEl);
|
||||||
|
|
||||||
// handle back click
|
|
||||||
pageEl.on('vmousedown', '#backBtn', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
window.history.back();
|
|
||||||
});
|
|
||||||
|
|
||||||
// change page for link buttons on vmousedown instead of waiting on vmouseup
|
// change page for link buttons on vmousedown instead of waiting on vmouseup
|
||||||
pageEl.on('vmousedown', 'a[data-role="button"]', function(e) {
|
pageEl.on('vmousedown', 'a[data-role="button"]', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -5,14 +5,16 @@
|
|||||||
|
|
||||||
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.account = args.account;
|
||||||
|
this.folder = args.folder;
|
||||||
|
|
||||||
if (args.folder && args.messageId) {
|
if (args.folder && args.messageId) {
|
||||||
// fetch reply-to email model
|
// fetch reply-to email model
|
||||||
this.replyTo = args.dao.getItem(args.folder, args.messageId);
|
this.replyTo = args.dao.getItem(args.folder, args.messageId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(eventName) {
|
render: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
page = $(this.el);
|
page = $(this.el);
|
||||||
|
|
||||||
@ -23,6 +25,12 @@
|
|||||||
self.fillFields();
|
self.fillFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle back button
|
||||||
|
page.find('#backBtn').on('vmousedown', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
self.goBackToLastPage();
|
||||||
|
});
|
||||||
|
// handle send button
|
||||||
page.find('#sendBtn').on('vmousedown', function() {
|
page.find('#sendBtn').on('vmousedown', function() {
|
||||||
self.sendEmail();
|
self.sendEmail();
|
||||||
});
|
});
|
||||||
@ -79,23 +87,39 @@
|
|||||||
var signature = '\n\nSent with whiteout mail - get your free mailbox for end-2-end encrypted messaging!\nhttps://mail.whiteout.io';
|
var signature = '\n\nSent with whiteout mail - get your free 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.account,
|
||||||
to: to,
|
to: to,
|
||||||
subject: page.find('#subjectInput').val(),
|
subject: page.find('#subjectInput').val(),
|
||||||
body: page.find('#bodyTextarea').val() + signature
|
body: page.find('#bodyTextarea').val() + signature
|
||||||
});
|
});
|
||||||
|
|
||||||
self.dao.sendEmail(email, function(err) {
|
// post message to main window
|
||||||
|
app.util.postMessage('sendEmail', {
|
||||||
|
email: email.toJSON()
|
||||||
|
}, function(resArgs) {
|
||||||
|
var err = resArgs.err;
|
||||||
|
|
||||||
$.mobile.loading('hide');
|
$.mobile.loading('hide');
|
||||||
if (err) {
|
if (err) {
|
||||||
window.alert(JSON.stringify(err));
|
window.alert(JSON.stringify(err));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.history.back();
|
self.goBackToLastPage();
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go back to the last activity
|
||||||
|
* depending from where to compose dialog was opened
|
||||||
|
*/
|
||||||
|
goBackToLastPage: function() {
|
||||||
|
if (this.folder) {
|
||||||
|
window.location = '#accounts/' + this.account + '/folders/' + this.folder;
|
||||||
|
} else {
|
||||||
|
window.location = '#accounts/' + this.account + '/folders';
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}());
|
}());
|
@ -54,6 +54,16 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function initDAO() {
|
||||||
|
var util = new cryptoLib.Util(window, uuid);
|
||||||
|
var crypto = new app.crypto.Crypto(window, util);
|
||||||
|
var cloudstorage = new app.dao.CloudStorage(window, $);
|
||||||
|
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
||||||
|
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
|
||||||
|
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
|
||||||
|
emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain);
|
||||||
|
}
|
||||||
|
|
||||||
function startApp() {
|
function startApp() {
|
||||||
// init email dao and dependencies
|
// init email dao and dependencies
|
||||||
initDAO();
|
initDAO();
|
||||||
@ -107,6 +117,14 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else if (cmd === 'sendEmail') {
|
||||||
|
// list emails from folder
|
||||||
|
sendEmail(args.email, function(err) {
|
||||||
|
callback({
|
||||||
|
err: err
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// error: invalid message from sandbox
|
// error: invalid message from sandbox
|
||||||
callback({
|
callback({
|
||||||
@ -117,16 +135,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initDAO() {
|
|
||||||
var util = new cryptoLib.Util(window, uuid);
|
|
||||||
var crypto = new app.crypto.Crypto(window, util);
|
|
||||||
var cloudstorage = new app.dao.CloudStorage(window, $);
|
|
||||||
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
|
||||||
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
|
|
||||||
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
|
|
||||||
emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain);
|
|
||||||
}
|
|
||||||
|
|
||||||
function login(userId, password, callback) {
|
function login(userId, password, callback) {
|
||||||
var account = new app.model.Account({
|
var account = new app.model.Account({
|
||||||
emailAddress: userId,
|
emailAddress: userId,
|
||||||
@ -134,8 +142,12 @@
|
|||||||
symIvSize: app.config.symIvSize,
|
symIvSize: app.config.symIvSize,
|
||||||
asymKeySize: app.config.asymKeySize
|
asymKeySize: app.config.asymKeySize
|
||||||
});
|
});
|
||||||
|
|
||||||
emailDao.init(account, password, callback);
|
emailDao.init(account, password, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendEmail(email, callback) {
|
||||||
|
var em = new app.model.Email(email);
|
||||||
|
emailDao.sendEmail(em, callback);
|
||||||
|
}
|
||||||
|
|
||||||
}());
|
}());
|
@ -35,5 +35,5 @@
|
|||||||
|
|
||||||
<div data-role="footer" data-position="fixed">
|
<div data-role="footer" data-position="fixed">
|
||||||
<h4></h4>
|
<h4></h4>
|
||||||
<a href="#compose" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
|
<a href="#compose/<%- account %>" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
|
||||||
</div><!-- /footer -->
|
</div><!-- /footer -->
|
@ -10,5 +10,5 @@
|
|||||||
<div data-role="footer" data-position="fixed">
|
<div data-role="footer" data-position="fixed">
|
||||||
<input type="button" data-icon="refresh" id="refreshBtn" data-iconpos="notext" class="ui-btn-left">
|
<input type="button" data-icon="refresh" id="refreshBtn" data-iconpos="notext" class="ui-btn-left">
|
||||||
<h4></h4>
|
<h4></h4>
|
||||||
<a href="#compose" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
|
<a href="#compose/<%- account %>/folders/<%- folder %>" data-role="button" data-icon="plus" data-iconpos="notext" class="ui-btn-right"></a>
|
||||||
</div><!-- /footer -->
|
</div><!-- /footer -->
|
Loading…
Reference in New Issue
Block a user