From 3599be95f4efb94200d4971b4be91bed5646aa8a Mon Sep 17 00:00:00 2001 From: noneofyourbusiness Date: Thu, 27 May 2021 19:07:35 +0200 Subject: [PATCH] verify numbers with pn --- scripts/core/sxmo_contactmenu.sh | 17 +++++++++++------ scripts/core/sxmo_contacts.sh | 1 - scripts/modem/sxmo_modemcall.sh | 2 +- scripts/modem/sxmo_modemmonitor.sh | 23 ++++++++++++++++++++--- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scripts/core/sxmo_contactmenu.sh b/scripts/core/sxmo_contactmenu.sh index 8b3d5af..de9b03a 100755 --- a/scripts/core/sxmo_contactmenu.sh +++ b/scripts/core/sxmo_contactmenu.sh @@ -4,14 +4,19 @@ . "$(dirname "$0")/sxmo_common.sh" valid_number() { - number="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" + if pn valid "$1"; then + echo "$1" + return + fi - if echo "$number" | grep -q "^+[0-9]\{11\}$"; then - echo "$number" - else - notify-send "\"$number\" is not a valid phone number" - notify-send "Valid format is \"+[0-9]{11}\"" + REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")" + if pn valid "$REFORMATTED"; then + echo "$REFORMATTED" + return fi + + notify-send "\""$1"\" is not a valid phone number" + exit } newcontact() { diff --git a/scripts/core/sxmo_contacts.sh b/scripts/core/sxmo_contacts.sh index 003f2e9..6094fa8 100755 --- a/scripts/core/sxmo_contacts.sh +++ b/scripts/core/sxmo_contacts.sh @@ -18,7 +18,6 @@ LOGFILE="$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv prepare_contacts_list() { cut -f3 | - sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" | tac | awk '!($0 in a){a[$0]; print}' | sed '/^[[:space:]]*$/d' | diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index d565180..822bccb 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -53,7 +53,7 @@ vid_to_number() { } number_to_contactname() { - NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" + NUMBER="$1" CONTACT=$(sxmo_contacts.sh --all | grep "^$NUMBER:" | cut -d':' -f 2 | diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index a9559d1..b420753 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -35,6 +35,21 @@ modem_n() { err "Couldn't find modem - is your modem enabled? Disabling modem monitor" } +cleanupnumber() { + if pn valid "$1"; then + echo "$1" + return + fi + + REFORMATTED="$(pn find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1")" + if [ -n "$REFORMATTED" ]; then + echo "$REFORMATTED" + return + fi + + echo "$1" +} + lookupnumberfromcallid() { VOICECALLID=$1 mmcli -m "$(modem_n)" --voice-list-calls -o "$VOICECALLID" -K | @@ -47,16 +62,15 @@ lookupcontactname() { if [ "$1" = "--" ]; then echo "Unknown number" else - NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")" CONTACT=$(sxmo_contacts.sh --all | - grep "^$NUMBER:" | + grep "^$1:" | cut -d':' -f 2 | sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace ) if [ -n "$CONTACT" ]; then echo "$CONTACT" else - echo "Unknown ($NUMBER)" + echo "Unknown ($1)" fi fi } @@ -70,6 +84,7 @@ checkforfinishedcalls() { cut -d'/' -f2 ); do FINISHEDNUMBER="$(lookupnumberfromcallid "$FINISHEDCALLID")" + FINISHEDNUMBER="$(cleanupnumber "$FINISHEDNUMBER")" mmcli -m "$(modem_n)" --voice-delete-call "$FINISHEDCALLID" rm -f "$CACHEDIR/${FINISHEDCALLID}.monitoredcall" @@ -142,6 +157,7 @@ checkforincomingcalls() { # Determine the incoming phone number echo "sxmo_modemmonitor: Incoming Call:">&2 INCOMINGNUMBER=$(lookupnumberfromcallid "$VOICECALLID") + INCOMINGNUMBER="$(cleanupnumber "$INCOMINGNUMBER")" CONTACTNAME=$(lookupcontactname "$INCOMINGNUMBER") xset dpms force on @@ -181,6 +197,7 @@ checkfornewtexts() { grep sms.content.number | sed -E 's/^sms\.content\.number\s+:\s+//' )" + NUM="$(cleanupnumber "$NUM")" TIME="$(echo "$TEXTDATA" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')" mkdir -p "$LOGDIR/$NUM"