- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2019 01:22 PM
Hi All - We have a change in requirement where we want to mask 16 digit credit card information in inbound email body but not 20 digit numbers as they are not credit card. I've below script that works perfectly but it masks any number over 12 digits -- i don't want to mask 20 digits number.
Thoughts on how i need to modify the bolded portion??
(function executeRule(current, previous /*null when async*/) {
var emailVars = [current.body,current.subject,current.body_text];
var arr = [];
for(e = 0; e < emailVars.length; e++) {
var wt = emailVars[e].match(/(https:\/\/.*wetransfer\.com)(.*)[^\s]/g);
var matches = emailVars[e].match(/(https:\/\/.*wetransfer\.com)(.*)[^\s]|([\d]){4}([ -])?([\d]){4}([ -])?([\d]){4}([ -])?([\d]){4}/g);
if(matches){
for(var i = 0; i < 16; i++) {
if(!wt || matches[i] != wt[0]) {
var numCount = 0;
var maskedCredCard = '';
for(var j = 0; j < matches[i].length; j++) {
if(matches[i][j] == '-' ||matches[i][j] == ' '|| numCount >= 12) {
maskedCredCard += matches[i][j];
}
else if(numCount < 12) {
maskedCredCard += '*';
numCount++;
}
}
if(e == 0) {
current.body = current.body.replace(matches[i] ,maskedCredCard);
}
else if(e == 1) {
current.subject = current.subject.replace(matches[i] ,maskedCredCard);
}
else if(e == 2) {
current.body_text = current.body_text.replace(matches[i], maskedCredCard);
}
} //closes WT if statement
}//closes matches for loop
} //closes if there are matches
} //closes loop through email variables
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2019 01:12 PM
Hi,
Replace this below line and check
var numbers = email_body.match(/\d+/g).map(Number);
WITH
var numbers = email_body.match(/\s\d+/g).map(Number);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 11:21 AM
So where do you want to block if you don't want to block the number if it exits in URL?
Share me one of your actual mails with dummy number present and tell me what exactly you wanted to mask and which ones you want to skip.
Also would appreciate if you could mark my comment(s) as helpful if they are helping.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 11:32 AM
Hi,
the code that i give will work for any string if the string contains the URL anywhere as long as the url is in the given format by you.
It can have phrases before and after the URL, that will still work.
Let me know if anything does not work here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 12:48 PM
It's not working if the URL contains 16 digits because they are being blocked even though it's part of the URL and not credit card number in the URL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2019 12:57 PM
Also cc_number shows "out of scope" warning line in 4 places:
for (i=0;i<16;i++) {
if(numCount <12) {
maskedCredCard += '*';
}
else {
maskedCredCard += cc_number[i];
}
numCount++;
}
// gs.print("CC number in "+emailVars[e]+" is "+maskedCredCard+"---"+cc_number);
} //if j matches
if(e == 0 && credit_card_found == 1) {
current.body = current.body.replace(cc_number ,maskedCredCard);
}
else if(e == 1 && credit_card_found == 1) {
current.subject = current.subject.replace(cc_number ,maskedCredCard);
}
else if(e == 2 && credit_card_found == 1) {
current.body_text = current.body_text.replace(cc_number, maskedCredCard);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2019 11:29 AM
Thats strnage.
Can you share the body text for which you are facing this issue.