Mercurial > prosody-modules
changeset 6338:1691e2054766
mod_voipms_carddav: Fix phone number normalization
| author | Chaz Kettleson <chaz@pyr3x.com> |
|---|---|
| date | Sat, 11 Oct 2025 09:52:31 -0400 |
| parents | 0570f1e2edf4 |
| children | 972ec5f0acc0 |
| files | mod_voipms_carddav/mod_voipms_carddav.lua |
| diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_voipms_carddav/mod_voipms_carddav.lua Thu Oct 09 14:17:11 2025 +0100 +++ b/mod_voipms_carddav/mod_voipms_carddav.lua Sat Oct 11 09:52:31 2025 -0400 @@ -50,6 +50,23 @@ return s end + local function normalize_us_phone_number(number) + if not number then return "" end + + local digits = number:gsub("%D", "") + + if #digits == 11 and digits:sub(1, 1) == "1" then + digits = digits:sub(2) + end + + if #digits ~= 10 then + return "" + end + + return "+1" .. digits + end + + for vcard_block in response_body:gmatch("BEGIN:VCARD(.-)END:VCARD") do local fn = vcard_block:match("FN:(.-)\r?\n") or "Unknown" fn = clean_string(fn) @@ -57,6 +74,7 @@ for tel_type, tel_number in vcard_block:gmatch("TEL;TYPE=([^:]+):([^\r\n]+)") do tel_type = clean_string(tel_type):lower() tel_number = clean_string(tel_number) + tel_number = normalize_us_phone_number(tel_number) table.insert(contacts, { name = fn,
