Fix the unreliable modem numbers prefix issues

Sometime, the modem will give 0611924312 as incoming text or
call number instead of +33611924312 (example in france).

This cause two issues cause of format missmatch:

* Notifications sometime come from "Unknown" when we actually know
the contact
* Text/Dial menu entries are duplicated with "Unknown" persons

We try here to fix boths issues with a simple idea. We will fallback
to a default prefix when it is missing (on phone like numbers,
composed of 10 numbers).

This prefix is an environment variable that cause 0 impact if missing.

* sxmo_contacts.sh will fix the recent numbers prefixes with the default
* sxmo_modemmonitor.sh will also fix the prefix with the default one

This should solve missmatch issues as both will use country code format

I only recommend to always store contacts in the prefixed format in the
contacts.tsv file.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
Stacy Harper 2021-04-03 00:01:29 +02:00 committed by Maarten van Gompel
parent df73a9af1c
commit 91fe7fbeab
4 changed files with 38 additions and 16 deletions

View file

@ -47,11 +47,9 @@ lookupcontactname() {
if [ "$1" = "--" ]; then
echo "Unknown number"
else
NUMBER="$1"
NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")"
CONTACT=$(sxmo_contacts.sh --all |
grep "$NUMBER:" | #this is not an exact match but a suffix match
#which also works if the + and country code are missing
#but may lead to false positives in rare cases (short numbers)
grep "^$NUMBER:" |
cut -d':' -f 2 |
sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace
)