One way to trigger privacy manager on invalid Caller ID?

This is for the benefit of the person who submitted Ticket number 3502 in the Bug Tracker - I think you could check for an invalid caller ID by sending your trunk to a custom context rather than directly to from-trunk. I haven’t been able to test this (I just don’t get too many invalid Caller ID calls here) but will throw it out - I HOPE my syntax is correct. Let’s assume that your provider normally sends 10 digit Caller IDs - you could send your trunk to a custom context in extensions_custom.conf called custom-trunk-cidcheck, which might look like this:

exten => _X!,1,Noop(Checking for invalid CallerID)
exten => _X!,n,GotoIf($[${LEN(${CALLERID(num)})} != 10]?notvalidcid)
exten => _X!,n,GotoIf($[${CALLERID(num):0:1} < 2]?notvalidcid)
exten => _X!,n,GotoIf($[${CALLERID(num):3:1} < 2]?notvalidcid)
exten => _X!,n,GotoIf($[${CALLERID(num):0:6} = 800555]?notvalidcid)
exten => _X!,n,GotoIf($[${CALLERID(num):0} = 8005551212]?notvalidcid)
exten => _X!,n,Goto(from-trunk,${EXTEN},1)
exten => _X!,n(notvalidcid),Set(CALLERID(all)=<>) 
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

The first line just prints an informative message in the CDR
The second line checks to see if the number is ten digits long, if not it rejects it.
The third line checks to see if the first digit is <2 (e.g. 0 or 1), if so it rejects it.
The fourth line checks to see if the fourth digit is <2 (e.g. 0 or 1), if so it rejects it.
The fifth line checks to see if the first six digits of the number are 800555, if so it rejects it.
The sixth line checks for a specific number, in this case 8005551212, and if it matches that number it rejects it.
If none of the patterns are matched by the seventh line it goes to from-trunk
On the eighth line, it sets the Caller ID name and number to null values (I hope!). That should trigger the privacy manager, assuming it’s enabled.
On the ninth line it goes to from-trunk.

As I say, this is untested code, sort of a concept I’m throwing out. I’m sure this could be made to work, but right now I don’t have time to test it and make sure it is 100% correct, and to be honest I don’t need anything like this on my system. But I didn’t think the ticket system was an appropriate place to post this response so I did it here in the forum. Feel free to correct my code, or tell me why this won’t work. :slight_smile: (And yes, I’m aware that this might “break” if you get calls from overseas that have longer CID’s than 10 digits - if that’s a concern you could change the “!= 10” in line 2 to “> 9”, make the target of the Goto “validcid”, and then add the validcid label to either line 7 or 9).