Help SIPAddHeader

HI, I am implementing a Exchange voice mail 2010 with Alcatel PBX. As per some lack of feature regarding SIP into Alcatel I cannot use directly ALCATEL-EXCHANGE so I find a solution putting beetwen Alcatel and exchange an Asterisk box.
It’s work in teory but I need to manage some staff.
I have created by FreePBX GUI an Inbound Route DDI that goes calling into " macro-bridge_oxe_vmexchange2010".

exten => 3999,1,Set(__FROM_DID=${EXTEN})
exten => 3999,n,Gosub(app-blacklist-check,s,1)
exten => 3999,n,ExecIf($[ “${CALLERID(name)}” = “” ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 3999,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 3999,n,Set(CALLERPRES()=allowed_not_screened)
exten => 3999,n(dest-ext),Goto(macro-bridge_oxe_vmexchange2010,s,1)

Ok now I need to take as variable the “To: <sip:2517” field from INVITE sent by Alcatel to asterisk, create a "${NAME_VARIABLE} "

<— SIP read from UDP:10.9.6.3:5060 —>
INVITE sip:3999@172.16.52.123;user=phone SIP/2.0
Allow: INVITE, ACK, CANCEL, BYE, PRACK, NOTIFY, SUBSCRIBE, OPTIONS, UPDATE, INFO
Supported: replaces,timer,100rel
User-Agent: OmniPCX Enterprise R9.0 h1.301.50
Session-Expires: 1800;refresher=uac
Min-SE: 900
P-Asserted-Identity: “XXXXXXXXXXXX” sip:2542@10.9.6.3;user=phone
Content-Type: application/sdp
To: sip:2517@10.9.6.3;user=phone
From: “Spirandelli Anto” sip:2542@10.9.6.3;user=phone;tag=e820d4c806c4d2b4a614efc453a901c8
Contact: sip:10.9.6.3;transport=UDP
Call-ID: 1e895421198aaf0dbc72e3311026bc9f@10.9.6.3
CSeq: 1673491919 INVITE
Via: SIP/2.0/UDP 10.9.6.3;branch=z9hG4bK62eefc447156487b7b994dc440a9ad17
Max-Forwards: 70
Content-Length: 332

v=0
o=OXE 1309461452 1309461452 IN IP4 10.9.6.3
s=abs
c=IN IP4 10.9.6.11
t=0 0
m=audio 32632 RTP/AVP 18 8 0 97
a=sendrecv
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=ptime:30
a=maxptime:40
a=rtpmap:8 PCMA/8000
a=ptime:20
a=maxptime:30
a=rtpmap:0 PCMU/8000
a=ptime:20
a=maxptime:30
a=rtpmap:97 telephone-event/8000

and put it by SIPAddHeader into “macro-bridge_oxe_vmexchange2010” that calls exchange VM

[macro-bridge_oxe_vmexchange2010]
; ARG1 - extension
; ARG2 - DIRECTDIAL/BUSY
; ARG3 - RETURN makes macro return, otherwise hangup
exten => s,1,Macro(user-callerid,SKIPTTL)
exten => s,n,GotoIf($[“foo${DB(${BLKVM_OVERRIDE})}” != “fooTRUE”]?vmx,1)
exten => s,n,Noop(CAME FROM: ${NODEST} - Blocking VM cause of key: ${DB(BLKVM_OVERRIDE)})
exten => s,n,Hangup
exten => vmx,1,GotoIf($["${ARG2}" = “DIRECTDIAL”]?3)
exten => vmx,2,SIPAddHeader(Diversion:<tel: ${NAME_VARIABLE}>;reason=no-answer;screen=no;privacy=off)
exten => vmx,3,Dial(SIP/Exchange/3999)
exten => vmx,4,Hangup

Is that possible?
Please help

Get the SIP To header then use a regular expression to extract the user field.

Hi David and thanks for reply. I had a look on voip-info.org/wiki/view/Asterisk+Expressions but I am really confused about regolar expression. Could you please help me more in detail? First of all, What Am I asking is possible?
Thanks in advance
Best regards

I believe it is possible if I have understood your question correctly.

For a basic grounding in regular expressions, type “man 7 regex” at the shell prompt; Asterisk uses the standard Unix regular expression library.

Hi gusys, problem solved!!!

exten => 3999,1,Set(__FROM_DID=${EXTEN})
exten => 3999,n,Gosub(app-blacklist-check,s,1)
exten => 3999,n,ExecIf($[ “${CALLERID(name)}” = “” ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 3999,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => 3999,n,Set(CALLERPRES()=allowed_not_screened)
exten => 3999,n,Set(exchdiversion=${SIP_HEADER(To)})
exten => 3999,n,Set(exchdiversion=${CUT(exchdiversion,@,1)})
exten => 3999,n,Set(exchdiversion=${CUT(exchdiversion,:,2)})
exten => 3999,n,Set(exchdiversion=${IF($["${exchdiversion}"=“3999”]?${CALLERID(number)}:${exchdiversion})})
exten => 3999,n(dest-ext),Goto(macro-bridge_oxe_vmexchange2010,s,1)

Thanks