Commit 98d040ee authored by Nico Josuttis's avatar Nico Josuttis

refactoring: make getRecipientsKeys more readable

parent 07afebb1
......@@ -120,11 +120,13 @@ Enigmail.hlp = {
var encrypt = EnigmailCommon.ENIG_UNDEF; // default encrypt flag is: maybe
var pgpMime = EnigmailCommon.ENIG_UNDEF; // default pgpMime flag is: maybe
var addresses="{"+EnigmailFuncs.stripEmail(emailAddrs.toLowerCase()).replace(/[, ]+/g, "}{")+"}";
var keyList=new Array;
// list of addresses not processed
// - string with { and } around each email to enable pattern matching with rules
var openAddresses = "{"+EnigmailFuncs.stripEmail(emailAddrs.toLowerCase()).replace(/[, ]+/g, "}{")+"}";
var foundAddresses = ""; // string of found addresses with { and } around
var keyList = new Array; // list of keys found for all Addresses
var rulesListObj= new Object;
var foundAddresses="";
// process recipient rules
if (enigmailSvc.getRulesData(rulesListObj)) {
......@@ -153,30 +155,32 @@ Enigmail.hlp = {
addrList=nodeText.toLowerCase().split(/[ ,;]+/);
for (var addrIndex=0; addrIndex < addrList.length; addrIndex++) {
var email = addrList[addrIndex];
var idx = addresses.indexOf(email);
let idx = openAddresses.indexOf(email);
while (idx >= 0) {
EnigmailCommon.DEBUG_LOG("enigmailMsgComposeHelper.js: getRecipientsKeys(): got matching rule for \""+email+"\"\n");
// process sign/sncrypt/ppgMime settings
sign = this.getFlagVal(sign, node, "sign");
encrypt = this.getFlagVal(encrypt, node, "encrypt");
pgpMime = this.getFlagVal(pgpMime, node, "pgpMime");
// extract found address
var keyIds=node.getAttribute("keyId");
var start=addresses.substring(0, idx+email.length).lastIndexOf("{");
var end=start+addresses.substring(start).indexOf("}")+1;
foundAddresses+=addresses.substring(start,end);
// process keys
let keyIds = node.getAttribute("keyId");
if (keyIds) {
if (keyIds != ".") {
keyList.push(keyIds.replace(/[ ,;]+/g, ", "));
if (keyIds != ".") { // if NOT "do not check further rules for this address"
var ids = keyIds.replace(/[ ,;]+/g, ", ");
keyList.push(ids);
var elem = {addr:email,keys:ids};
}
addresses = addresses.substring(0,start)+addresses.substring(end);
idx = addresses.indexOf(email);
let start = openAddresses.substring(0, idx+email.length).lastIndexOf("{");
let end = start + openAddresses.substring(start).indexOf("}")+1;
foundAddresses += openAddresses.substring(start,end);
openAddresses = openAddresses.substring(0,start) + openAddresses.substring(end);
idx = openAddresses.indexOf(email);
}
else {
var oldMatch = idx;
idx = addresses.substring(oldMatch+email.length).indexOf(email);
idx = openAddresses.substring(oldMatch+email.length).indexOf(email);
if (idx>=0) {
idx += oldMatch + email.length;
}
......@@ -186,7 +190,7 @@ Enigmail.hlp = {
}
else {
// "not" rule
addrList = addresses.replace(/\}\{/g, "},{").split(/,/);
addrList = openAddresses.replace(/\}\{/g, "},{").split(/,/);
var idx;
for (idx = 0; idx < addrList.length; idx++) {
if (nodeText.toLowerCase().indexOf(addrList[idx])>=0) {
......@@ -202,7 +206,9 @@ Enigmail.hlp = {
keyIds=node.getAttribute("keyId");
if (keyIds) {
if (keyIds != ".") {
keyList.push(keyIds.replace(/[ ,;]+/g, ", "));
var ids = keyIds.replace(/[ ,;]+/g, ", ");
keyList.push(ids);
var elem = {addr:email,keys:ids};
}
}
}
......@@ -243,8 +249,8 @@ Enigmail.hlp = {
pgpMime = this.getFlagVal(pgpMime, resultObj, "pgpMime");
if (resultObj.keyId.length>0) {
keyList.push(resultObj.keyId);
var replaceAddr=new RegExp("{"+addrList[i]+"}", "g");
addresses=addresses.replace(replaceAddr, "");
var replaceAddr = new RegExp("{"+addrList[i]+"}", "g");
openAddresses = openAddresses.replace(replaceAddr, "");
}
else {
// no key -> no encryption
......@@ -259,7 +265,7 @@ Enigmail.hlp = {
if (keyList.length>0) {
// sort key list and make it unique?
matchedKeysObj.value = keyList.join(", ");
matchedKeysObj.value += addresses.replace(/\{/g, ", ").replace(/\}/g, "");
matchedKeysObj.value += openAddresses.replace(/\{/g, ", ").replace(/\}/g, "");
}
// return result from combining flags
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment