mirror of
https://github.com/moparisthebest/mail
synced 2024-11-11 19:55:06 -05:00
[WO-18] review and error handling
This commit is contained in:
parent
cd93e8866f
commit
ab43098fe5
@ -38,7 +38,7 @@ define([], function() {
|
|||||||
*/
|
*/
|
||||||
app.string = {
|
app.string = {
|
||||||
subjectPrefix: '[whiteout] ',
|
subjectPrefix: '[whiteout] ',
|
||||||
invitationSubject: 'Invitation to your secure eMail experience',
|
invitationSubject: 'Invitation to a private conversation',
|
||||||
invitationMessage: 'I would like to invite you to a private conversation. To read my encrypted messages, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/jjgghafhamholjigjoghcfcekhkonijg',
|
invitationMessage: 'I would like to invite you to a private conversation. To read my encrypted messages, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/jjgghafhamholjigjoghcfcekhkonijg',
|
||||||
message: 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/jjgghafhamholjigjoghcfcekhkonijg',
|
message: 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/jjgghafhamholjigjoghcfcekhkonijg',
|
||||||
cryptPrefix: '-----BEGIN PGP MESSAGE-----',
|
cryptPrefix: '-----BEGIN PGP MESSAGE-----',
|
||||||
|
@ -8,8 +8,8 @@ define(function(require) {
|
|||||||
dbType = 'email_OUTBOX';
|
dbType = 'email_OUTBOX';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High level business object that orchestrates the local outbox.
|
* High level business object that orchestrates the local outbox.
|
||||||
* The local outbox takes care of the emails before they are being sent.
|
* The local outbox takes care of the emails before they are being sent.
|
||||||
* It also checks periodically if there are any mails in the local device storage to be sent.
|
* It also checks periodically if there are any mails in the local device storage to be sent.
|
||||||
*/
|
*/
|
||||||
var OutboxBO = function(emailDao, invitationDao) {
|
var OutboxBO = function(emailDao, invitationDao) {
|
||||||
@ -47,6 +47,9 @@ define(function(require) {
|
|||||||
var self = this,
|
var self = this,
|
||||||
emails;
|
emails;
|
||||||
|
|
||||||
|
// if a _processOutbox call is still in progress when a new timeout kicks
|
||||||
|
// in, since sending mails might take time, ignore it. otherwise, mails
|
||||||
|
// could get sent multiple times
|
||||||
if (self._outboxBusy) {
|
if (self._outboxBusy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,25 +75,28 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process the next pending mail
|
||||||
function processMails() {
|
function processMails() {
|
||||||
// in the navigation controller, this updates the folder count
|
|
||||||
|
|
||||||
if (emails.length === 0) {
|
if (emails.length === 0) {
|
||||||
|
// in the navigation controller, this updates the folder count
|
||||||
self._outboxBusy = false;
|
self._outboxBusy = false;
|
||||||
callback(null, 0);
|
callback(null, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// in the navigation controller, this updates the folder count
|
||||||
callback(null, emails.length);
|
callback(null, emails.length);
|
||||||
var email = emails.shift();
|
var email = emails.shift();
|
||||||
checkReceivers(email);
|
checkReceivers(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check whether there are unregistered receivers, i.e. receivers without a public key
|
||||||
function checkReceivers(email) {
|
function checkReceivers(email) {
|
||||||
var unregisteredUsers, receiverChecked;
|
var unregisteredUsers, receiverChecked;
|
||||||
|
|
||||||
unregisteredUsers = [];
|
unregisteredUsers = [];
|
||||||
receiverChecked = _.after(email.to.length, function() {
|
receiverChecked = _.after(email.to.length, function() {
|
||||||
|
// invite unregistered users if necessary
|
||||||
if (unregisteredUsers.length > 0) {
|
if (unregisteredUsers.length > 0) {
|
||||||
invite(unregisteredUsers);
|
invite(unregisteredUsers);
|
||||||
return;
|
return;
|
||||||
@ -99,10 +105,13 @@ define(function(require) {
|
|||||||
sendEncrypted(email);
|
sendEncrypted(email);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// find out if there are unregistered users
|
||||||
email.to.forEach(function(recipient) {
|
email.to.forEach(function(recipient) {
|
||||||
self._emailDao._keychain.getReceiverPublicKey(recipient.address, function(err, key) {
|
self._emailDao._keychain.getReceiverPublicKey(recipient.address, function(err, key) {
|
||||||
if (err) {
|
if (err) {
|
||||||
// stop processing
|
self._outboxBusy = false;
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!key) {
|
if (!key) {
|
||||||
@ -114,39 +123,50 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// invite the unregistered receivers, if necessary
|
||||||
function invite(addresses) {
|
function invite(addresses) {
|
||||||
var sender = self._emailDao._account.emailAddress;
|
var sender = self._emailDao._account.emailAddress;
|
||||||
|
|
||||||
var invitationFinished = _.after(addresses.length, function() {
|
var invitationFinished = _.after(addresses.length, function() {
|
||||||
// after all of the invitations are checked and sent (if necessary),
|
// after all of the invitations are checked and sent (if necessary),
|
||||||
//
|
|
||||||
processMails();
|
processMails();
|
||||||
});
|
});
|
||||||
|
|
||||||
// send invite
|
// check which of the adresses has pending invitations
|
||||||
addresses.forEach(function(recipient) {
|
addresses.forEach(function(recipient) {
|
||||||
var recipientAddress = recipient.address;
|
var recipientAddress = recipient.address;
|
||||||
|
|
||||||
self._invitationDao.check({
|
self._invitationDao.check({
|
||||||
recipient: recipientAddress,
|
recipient: recipientAddress,
|
||||||
sender: sender
|
sender: sender
|
||||||
}, function(err, status) {
|
}, function(err, status) {
|
||||||
|
if (err) {
|
||||||
|
self._outboxBusy = false;
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (status === InvitationDAO.INVITE_PENDING) {
|
if (status === InvitationDAO.INVITE_PENDING) {
|
||||||
// the recipient is already invited, we're done here.
|
// the recipient is already invited, we're done here.
|
||||||
invitationFinished();
|
invitationFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the recipient is not yet invited, so let's do that
|
// the recipient is not yet invited, so let's do that
|
||||||
self._invitationDao.invite({
|
self._invitationDao.invite({
|
||||||
recipient: recipientAddress,
|
recipient: recipientAddress,
|
||||||
sender: sender
|
sender: sender
|
||||||
}, function(err, status) {
|
}, function(err, status) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.errMsg);
|
self._outboxBusy = false;
|
||||||
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status !== InvitationDAO.INVITE_SUCCESS) {
|
if (status !== InvitationDAO.INVITE_SUCCESS) {
|
||||||
console.error('could not successfully invite ' + recipientAddress);
|
self._outboxBusy = false;
|
||||||
|
callback({
|
||||||
|
errMsg: 'could not successfully invite ' + recipientAddress
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,26 +176,28 @@ define(function(require) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// send an invitation to the unregistered user, aka the recipient
|
||||||
function sendInvitationMail(recipient, sender) {
|
function sendInvitationMail(recipient, sender) {
|
||||||
var to = (recipient.name || recipient.address).split('@')[0].split('.')[0].split(' ')[0],
|
var to = (recipient.name || recipient.address).split('@')[0].split('.')[0].split(' ')[0],
|
||||||
invitationMail = {
|
invitationMail = {
|
||||||
from: [sender],
|
from: [sender],
|
||||||
to: [recipient],
|
to: [recipient],
|
||||||
subject: str.invitationSubject,
|
subject: str.subjectPrefix + str.invitationSubject,
|
||||||
body: 'Hi ' + to + ',\n\n' + str.invitationMessage + '\n\n\n' + str.signature
|
body: 'Hi ' + to + ',\n\n' + str.invitationMessage + '\n\n\n' + str.signature
|
||||||
};
|
};
|
||||||
|
|
||||||
// send invitation mail
|
// send invitation mail
|
||||||
self._emailDao.send(invitationMail, function(err) {
|
self._emailDao.send(invitationMail, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err.errMsg);
|
self._outboxBusy = false;
|
||||||
|
callback(err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
invitationFinished();
|
invitationFinished();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendEncrypted(email) {
|
function sendEncrypted(email) {
|
||||||
self._emailDao.encryptedSend(email, function(err) {
|
self._emailDao.encryptedSend(email, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user