--- channels/chan_sip.c.orig 2010-11-11 22:57:22.000000000 +0100 +++ channels/chan_sip.c 2011-01-06 09:38:37.000000000 +0100 @@ -10871,8 +10871,6 @@ static void initreqprep(struct sip_reque } if (ast_strlen_zero(l)) l = default_callerid; - if (ast_strlen_zero(n)) - n = l; /* Allow user to be overridden */ if (!ast_strlen_zero(p->fromuser)) l = p->fromuser; @@ -10886,17 +10884,26 @@ static void initreqprep(struct sip_reque ast_string_field_set(p, fromname, n); if (sip_cfg.pedanticsipchecking) { - ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0); - n = tmp_n; + if (!ast_strlen_zero(n)) { + ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0); + n = tmp_n; + } ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0); l = tmp_l; } ourport = ntohs(p->ourip.sin_port); - if (!sip_standard_port(p->socket.type, ourport) && ast_strlen_zero(p->fromdomain)) - snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, d, ourport, p->tag); - else - snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, d, p->tag); + if (!sip_standard_port(p->socket.type, ourport) && ast_strlen_zero(p->fromdomain)) { + if (ast_strlen_zero(n)) + snprintf(from, sizeof(from), ";tag=%s", l, d, ourport, p->tag); /* also legal without <> */ + else + snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, d, ourport, p->tag); + } else { + if (ast_strlen_zero(n)) + snprintf(from, sizeof(from), ";tag=%s", l, d, p->tag); /* also legal without <> */ + else + snprintf(from, sizeof(from), "\"%s\" ;tag=%s", n, l, d, p->tag); + } /* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */ if (!ast_strlen_zero(p->fullcontact)) {