mirror of
https://github.com/moparisthebest/mail
synced 2024-11-11 11:45:02 -05:00
sending email to multiple receivers works
This commit is contained in:
parent
6d0e562351
commit
87d26383f5
@ -153,20 +153,13 @@ define(function(require) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.sendToOutbox = function() {
|
$scope.sendToOutbox = function() {
|
||||||
var to, email;
|
var email;
|
||||||
|
|
||||||
// validate recipients
|
|
||||||
to = $scope.to.replace(/\s/g, '').split(/[,;]/);
|
|
||||||
if (!to || to.length < 1) {
|
|
||||||
$scope.onError({
|
|
||||||
errMsg: 'Seperate recipients with a comma!',
|
|
||||||
sync: true
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// build email model for smtp-client
|
||||||
email = {
|
email = {
|
||||||
to: [], // list of receivers
|
to: [],
|
||||||
|
cc: [],
|
||||||
|
bcc: [],
|
||||||
subject: $scope.subject, // Subject line
|
subject: $scope.subject, // Subject line
|
||||||
body: $scope.body // use parsed plaintext body
|
body: $scope.body // use parsed plaintext body
|
||||||
};
|
};
|
||||||
@ -174,13 +167,34 @@ define(function(require) {
|
|||||||
name: '',
|
name: '',
|
||||||
address: emailDao._account.emailAddress
|
address: emailDao._account.emailAddress
|
||||||
}];
|
}];
|
||||||
to.forEach(function(address) {
|
|
||||||
email.to.push({
|
|
||||||
name: '',
|
|
||||||
address: address
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// validate recipients and gather public keys
|
||||||
|
email.receiverKeys = []; // gather public keys for emailDao._encrypt
|
||||||
|
|
||||||
|
appendReceivers($scope.to, email.to);
|
||||||
|
appendReceivers($scope.cc, email.cc);
|
||||||
|
appendReceivers($scope.bcc, email.bcc);
|
||||||
|
|
||||||
|
function appendReceivers(srcField, destField) {
|
||||||
|
srcField.forEach(function(recipient) {
|
||||||
|
// validate address
|
||||||
|
if (!util.validateEmailAddress(recipient.address)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// append address to email model
|
||||||
|
destField.push({
|
||||||
|
address: recipient.address
|
||||||
|
});
|
||||||
|
|
||||||
|
// add public key to list of recipient keys
|
||||||
|
if (recipient.key && recipient.key.publicKey) {
|
||||||
|
email.receiverKeys.push(recipient.key.publicKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// persist the email locally for later smtp transmission
|
||||||
emailDao.store(email, function(err) {
|
emailDao.store(email, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
$scope.onError(err);
|
$scope.onError(err);
|
||||||
|
@ -882,51 +882,17 @@ define(function(require) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate email addresses
|
// public key found... encrypt and send
|
||||||
for (var i = email.to.length - 1; i >= 0; i--) {
|
self._encrypt({
|
||||||
if (!util.validateEmailAddress(email.to[i].address)) {
|
email: email,
|
||||||
callback({
|
keys: email.receiverKeys // this Array is set in writer controller
|
||||||
errMsg: 'Invalid recipient: ' + email.to[i].address
|
}, function(err, email) {
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!util.validateEmailAddress(email.from[0].address)) {
|
|
||||||
callback({
|
|
||||||
errMsg: 'Invalid sender: ' + email.from
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only support single recipient for e-2-e encryption
|
|
||||||
// check if receiver has a public key
|
|
||||||
self._keychain.getReceiverPublicKey(email.to[0].address, function(err, receiverPubkey) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate public key
|
self._smtpClient.send(email, callback);
|
||||||
if (!receiverPubkey) {
|
|
||||||
callback({
|
|
||||||
errMsg: 'User has no public key yet!'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// public key found... encrypt and send
|
|
||||||
self._encrypt({
|
|
||||||
email: email,
|
|
||||||
keys: [receiverPubkey.publicKey]
|
|
||||||
}, function(err, email) {
|
|
||||||
if (err) {
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self._smtpClient.send(email, callback);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user