From f4401d2033d7d3a165fcf70e8b8317185e13493d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 11 Aug 2020 20:55:57 -0500 Subject: [PATCH] Allow calls from blocked caller id --- Main.hs | 4 ++-- Util.hs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Main.hs b/Main.hs index b61b118..23d27ab 100644 --- a/Main.hs +++ b/Main.hs @@ -1246,11 +1246,11 @@ mapToBackend backendHost (JID { jidNode = Nothing }) = parseJID backendHost mapLocalpartToBackend backendHost localpart | Just ('+', tel) <- T.uncons localpart', T.all isDigit tel = result - | Just _ <- parsePhoneContext localpart = result + | Just _ <- parsePhoneContext localpart' = result | otherwise = Nothing where -- Unescape local and strip any @suffix in case this is a tel-like SIP uri - (localpart', _) = T.breakOn (s"@") $ unescapeJid localpart + localpart' = sanitizeTelCandidate $ fst $ T.breakOn (s"@") $ unescapeJid localpart result = parseJID (localpart' ++ s"@" ++ backendHost) localpartToURI localpart diff --git a/Util.hs b/Util.hs index 3d21bc6..62f2fed 100644 --- a/Util.hs +++ b/Util.hs @@ -67,6 +67,23 @@ unescapeJid txt = fromString result ("20", ' '), ("22", '"'), ("26", '&'), ("27", '\''), ("2f", '/'), ("3a", ':'), ("3c", '<'), ("3e", '>'), ("40", '@'), ("5c", '\\') ] +-- To handle blocked callers, etc +sanitizeTelCandidate :: Text -> Text +sanitizeTelCandidate candidate + | T.length candidate < 3 = + s"13;phone-context=anonymous.phone-context.soprani.ca" + | candidate == s"Restricted" = + s"14;phone-context=anonymous.phone-context.soprani.ca" + | candidate == s"anonymous" = + s"15;phone-context=anonymous.phone-context.soprani.ca" + | candidate == s"Anonymous" = + s"16;phone-context=anonymous.phone-context.soprani.ca" + | candidate == s"unavailable" = + s"17;phone-context=anonymous.phone-context.soprani.ca" + | candidate == s"Unavailable" = + s"18;phone-context=anonymous.phone-context.soprani.ca" + | otherwise = candidate + parsePhoneContext :: Text -> Maybe (Text, Text) parsePhoneContext txt = hush $ Atto.parseOnly ( (,) <$> Atto.takeWhile isDigit <* Atto.string (s";phone-context=") <*> Atto.takeTill (Atto.inClass " ;") -- 2.45.2