# 
# old_revision [4da5728e2318b472a54f31e43525f581018581fe]
# 
# patch "callerid.c"
#  from [46aa3ee99eefb11d04cf9b09b9ce30e9e4c59678]
#    to [c6c4a45f5b118abe2a36e5c1172f283d0727e79e]
# 
# patch "channels/chan_sip.c"
#  from [84b8eb24eebcea7ccfa9d0365f82bb69b1249e56]
#    to [358264074e236cc41e2453ae01c6be0bc0f4db2b]
# 
# patch "include/asterisk/callerid.h"
#  from [30683d737dbddb00385afa5590fa2c779de9f290]
#    to [66db029e655e6a982caffaf8ce1cb1eb2035407c]
# 
============================================================
--- callerid.c	46aa3ee99eefb11d04cf9b09b9ce30e9e4c59678
+++ callerid.c	c6c4a45f5b118abe2a36e5c1172f283d0727e79e
@@ -631,6 +631,21 @@
 	return 1;
 }
 
+/*! \brief checks if string consists only of digits and '*#+[]-.( )'
+	\return 1 if string is valid fancy phone number
+	\return 0 if not
+*/
+int ast_is_fancy_phonenumber(char *n)
+{
+	int x;
+	if (ast_strlen_zero(n))
+		return 0;
+	for (x=0;n[x];x++)
+		if (!strchr("0123456789*#+[]-.( )", n[x]))
+			return 0;
+	return 1;
+}
+
 /*! \brief parse string for caller id information 
 	\return returns -1 on failure, otherwise 0
 */
============================================================
--- channels/chan_sip.c	84b8eb24eebcea7ccfa9d0365f82bb69b1249e56
+++ channels/chan_sip.c	358264074e236cc41e2453ae01c6be0bc0f4db2b
@@ -6984,7 +6984,8 @@
 		if ((c = strchr(of, ':')))
 			*c = '\0';
 		ast_copy_string(p->cid_num, of, sizeof(p->cid_num));
-		ast_shrink_phone_number(p->cid_num);
+		if (ast_is_fancy_phonenumber(p->cid_num))
+			ast_shrink_phone_number(p->cid_num);
 	}
 	if (ast_strlen_zero(of))
 		return 0;
@@ -7008,7 +7009,8 @@
 			if (*calleridname)
 				ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
 			ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
-			ast_shrink_phone_number(p->cid_num);
+			if (ast_is_fancy_phonenumber(p->cid_num))
+				ast_shrink_phone_number(p->cid_num);
 		}
 
 		if (p->rtp) {
@@ -7033,7 +7035,8 @@
 				ast_copy_string(p->context, user->context, sizeof(p->context));
 			if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num))  {
 				ast_copy_string(p->cid_num, user->cid_num, sizeof(p->cid_num));
-				ast_shrink_phone_number(p->cid_num);
+				if (ast_is_fancy_phonenumber(p->cid_num))
+					ast_shrink_phone_number(p->cid_num);
 			}
 			if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_num)) 
 				ast_copy_string(p->cid_name, user->cid_name, sizeof(p->cid_name));
@@ -7095,7 +7098,8 @@
 				if (*calleridname)
 					ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
 				ast_copy_string(p->cid_num, rpid_num, sizeof(p->cid_num));
-				ast_shrink_phone_number(p->cid_num);
+				if (ast_is_fancy_phonenumber(p->cid_num))
+					ast_shrink_phone_number(p->cid_num);
 			}
 			if (p->rtp) {
 				ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
@@ -7141,7 +7145,8 @@
 				}
 				if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num))  {
 					ast_copy_string(p->cid_num, peer->cid_num, sizeof(p->cid_num));
-					ast_shrink_phone_number(p->cid_num);
+					if (ast_is_fancy_phonenumber(p->cid_num))
+						ast_shrink_phone_number(p->cid_num);
 				}
 				if (!ast_strlen_zero(peer->cid_name) && !ast_strlen_zero(p->cid_name)) 
 					ast_copy_string(p->cid_name, peer->cid_name, sizeof(p->cid_name));
============================================================
--- include/asterisk/callerid.h	30683d737dbddb00385afa5590fa2c779de9f290
+++ include/asterisk/callerid.h	66db029e655e6a982caffaf8ce1cb1eb2035407c
@@ -171,6 +171,13 @@
  */
 extern int ast_isphonenumber(char *n);
 
+/*! \brief Check if a string consists only of digits and the characters that are
+    normally used to represent human-readable phone numbers, such as '#*+[].-( )'.
+    \param n number to be checked.
+    \return Returns 0 if n is a number, 1 if it's not.
+ */
+extern int ast_is_fancy_phonenumber(char *n);
+
 extern int ast_callerid_split(const char *src, char *name, int namelen, char *num, int numlen);
 
 extern char *ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown);
