title: How to do some task after Asterisk ReceiveFax function calling?
body: <p>I have asterisk Server installed:
  And I have created Dial-plan for Receive Fax:
  I want to do some task after successfully received fax. but, any line written after <code>ReceveFax</code> function ONLY called when Transmission is <strong>FAILED</strong>. If transmission is <strong>SUCCESS</strong> will never called any line after.</p>
  
  <blockquote>
    <p><strong>My Dial-Plan:</strong></p>
  </blockquote>
  
  <pre><code>;######################### FAX Dialplan Implementation Start ##########################
  
  exten =&gt; _15555551212,1,NoOp(Fax receiving from ${EXTEN})
  exten =&gt; _15555551212,n,Answer
  exten =&gt; _15555551212,n,Ringing
  exten =&gt; _15555551212,n,Macro(inboundfax)
  exten =&gt; _15555551212,n,NoOp(Done)
  
  exten =&gt; h,1, NoOp(Completed...)
  
  [macro-inboundfax]
  exten =&gt; s,1,NoOp(**** FAX RECEIVED from ${CALLERID(num)} ${STRFTIME(${EPOCH},,%c)} ****)
  exten =&gt; s,n,Set(FAXOPT(ecm)=yes)
  exten =&gt; s,n,Set(FILENAME=fax-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
  exten =&gt; s,n,Set(FAXFILE=${FILENAME}.tif)
  exten =&gt; s,n,Set(FAXOPT(ecm)=yes)
  exten =&gt; s,n,Set(FAXOPT(headerinfo)=Received by MYCOMPANY ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M)})
  exten =&gt; s,n,Set(FAXOPT(localstationid)=5555551212)
  exten =&gt; s,n,Set(FAXOPT(maxrate)=14400)
  exten =&gt; s,n,Set(FAXOPT(minrate)=4800)
  exten =&gt; s,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
  exten =&gt; s,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
  exten =&gt; s,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
  exten =&gt; s,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
  exten =&gt; s,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
  exten =&gt; s,n,NoOp(**** RECEIVING FAX : ${FAXFILE} ****)
  exten =&gt; s,n,Set(FAX_DEST=/var/www/html/private/fax/received)
  exten =&gt; s,n,Set(FAXDEST=/tmp)
  
  exten =&gt; s,n,DumpChan(3)
  
  exten =&gt; s,n,ReceiveFAX(${FAXDEST}/${FAXFILE})
  exten =&gt; s,n,Verbose(3,- Fax receipt completed with status: ${FAXSTATUS})
  
  exten =&gt; s,n,Verbose(Fax receipt completed with status: ${FAXSTATUS})
  
  exten =&gt; s,n,Verbose(FaxFile moving... ${FAXDEST}/${FAXFILE} -&gt; ${FAX_DEST}/)
  exten =&gt; s,n,System(mv ${FAXDEST}/${FAXFILE} ${FAX_DEST}/)
  exten =&gt; s,n,Verbose(Fax file moved.)
  
  exten =&gt; s,n,NoOp(Mail Sending...)
  ;exten =&gt; s,n,System(echo | mutt -a ${FAXDEST}/${FAXFILE} -s "received fax" testfax@gmail.com)
  exten =&gt; s,n,NoOp(Mail Sent)
  </code></pre>
  
  <p>Console Log: (While Receiving Fax)</p>
  
  <pre><code> == Using SIP RTP CoS mark 5
      -- Executing [15555551212@from-sip:1] NoOp("SIP/4001-0000000f", "Fax receiving from 15555551212") in new stack
      -- Executing [15555551212@from-sip:2] Answer("SIP/4001-0000000f", "") in new stack
      -- Executing [15555551212@from-sip:3] Ringing("SIP/4001-0000000f", "") in new stack
      -- Executing [15555551212@from-sip:4] Macro("SIP/4001-0000000f", "inboundfax") in new stack
      -- Executing [s@macro-inboundfax:1] NoOp("SIP/4001-0000000f", "**** FAX RECEIVED from 4001 Sat Jun 20 15:25:22 2015 ****") in new stack
      -- Executing [s@macro-inboundfax:2] Set("SIP/4001-0000000f", "FAXOPT(ecm)=yes") in new stack
      -- Executing [s@macro-inboundfax:3] Set("SIP/4001-0000000f", "FILENAME=fax-20150620-152522") in new stack
      -- Executing [s@macro-inboundfax:4] Set("SIP/4001-0000000f", "FAXFILE=fax-20150620-152522.tif") in new stack
      -- Executing [s@macro-inboundfax:5] Set("SIP/4001-0000000f", "FAXOPT(ecm)=yes") in new stack
      -- Executing [s@macro-inboundfax:6] Set("SIP/4001-0000000f", "FAXOPT(headerinfo)=Received by MYCOMPANY 2015-06-20 15:25") in new stack
      -- Executing [s@macro-inboundfax:7] Set("SIP/4001-0000000f", "FAXOPT(localstationid)=5555551212") in new stack
      -- Executing [s@macro-inboundfax:8] Set("SIP/4001-0000000f", "FAXOPT(maxrate)=14400") in new stack
      -- Executing [s@macro-inboundfax:9] Set("SIP/4001-0000000f", "FAXOPT(minrate)=4800") in new stack
      -- Executing [s@macro-inboundfax:10] NoOp("SIP/4001-0000000f", "FAXOPT(ecm) : yes") in new stack
      -- Executing [s@macro-inboundfax:11] NoOp("SIP/4001-0000000f", "FAXOPT(headerinfo) : Received by MYCOMPANY 2015-06-20 15:25") in new stack
      -- Executing [s@macro-inboundfax:12] NoOp("SIP/4001-0000000f", "FAXOPT(localstationid) : 5555551212") in new stack
      -- Executing [s@macro-inboundfax:13] NoOp("SIP/4001-0000000f", "FAXOPT(maxrate) : 14400") in new stack
      -- Executing [s@macro-inboundfax:14] NoOp("SIP/4001-0000000f", "FAXOPT(minrate) : 4800") in new stack
      -- Executing [s@macro-inboundfax:15] NoOp("SIP/4001-0000000f", "**** RECEIVING FAX : fax-20150620-152522.tif ****") in new stack
      -- Executing [s@macro-inboundfax:16] Set("SIP/4001-0000000f", "FAX_DEST=/var/www/html/private/fax/received") in new stack
      -- Executing [s@macro-inboundfax:17] Set("SIP/4001-0000000f", "FAXDEST=/tmp") in new stack
      -- Executing [s@macro-inboundfax:18] DumpChan("SIP/4001-0000000f", "3") in new stack
      --
      -- Dumping Info For Channel: SIP/4001-0000000f:
      -- ================================================================================
      -- Info:
      -- Name=               SIP/4001-0000000f
      -- Type=               SIP
      -- UniqueID=           1434794122.15
      -- LinkedID=           1434794122.15
      -- CallerIDNum=        4001
      -- CallerIDName=       FaxVoip SoftPhone
      -- ConnectedLineIDNum= (N/A)
      -- ConnectedLineIDName=(N/A)
      -- DNIDDigits=         15555551212
      -- RDNIS=              (N/A)
      -- Parkinglot=         default
      -- Language=           en
      -- State=              Up (6)
      -- Rings=              0
      -- NativeFormat=       (ulaw)
      -- WriteFormat=        slin
      -- ReadFormat=         ulaw
      -- RawWriteFormat=     ulaw
      -- RawReadFormat=      ulaw
      -- WriteTranscode=     Yes (slin)-&gt;(ulaw)
      -- ReadTranscode=      No
      -- 1stFileDescriptor=  26
      -- Framesin=           1
      -- Framesout=          0
      -- TimetoHangup=       0
      -- ElapsedTime=        0h0m0s
      -- DirectBridge=       &lt;none&gt;
      -- IndirectBridge=     &lt;none&gt;
      -- Context=            macro-inboundfax
      -- Extension=          s
      -- Priority=           18
      -- CallGroup=
      -- PickupGroup=
      -- Application=        DumpChan
      -- Data=               3
      -- Blocking_in=        (Not Blocking)
      --
      -- Variables:
      -- MACRO_DEPTH=1
      -- FAXDEST=/tmp
      -- FAX_DEST=/var/www/html/private/fax/received
      -- FAXFILE=fax-20150620-152522.tif
      -- FILENAME=fax-20150620-152522
      -- MACRO_PRIORITY=4
      -- MACRO_CONTEXT=from-sip
      -- MACRO_EXTEN=15555551212
      -- SIPCALLID=af6dfc5a-ee0f-1910-9de1-e06995d7f913@dsk-388
      -- SIPDOMAIN=XX.XX.XX.XX
      -- SIPURI=sip:4001@XX.XX.XX.XX:5065
      -- ================================================================================
      -- Executing [s@macro-inboundfax:19] ReceiveFAX("SIP/4001-0000000f", "/tmp/fax-20150620-152522.tif") in new stack
      -- Channel 'SIP/4001-0000000f' receiving FAX '/tmp/fax-20150620-152522.tif'
    == Using UDPTL CoS mark 5
      -- Channel 'SIP/4001-0000000f' FAX session '5' started
      -- FAX handle 0: [ 026.931800 ], entering CLOSING state
      -- FAX handle 0: [ 026.931866 ], entering CLOSING state
      -- Channel 'SIP/4001-0000000f' FAX session '5' is complete, result: 'SUCCESS' (FAX_SUCCESS), error: 'NO_ERROR', pages: 2, resolution: '204x98', transfer rate: '14400', remoteSID: ''
    == Spawn extension (macro-inboundfax, s, 19) exited non-zero on 'SIP/4001-0000000f' in macro 'inboundfax'
    == Spawn extension (from-sip, 15555551212, 4) exited non-zero on 'SIP/4001-0000000f'
  </code></pre>