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

refactoring: make getRecipientsKeys more readable

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