home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / avmnfax-1.33.lha / avmNfax / rexx / handlefax.avm < prev    next >
Text File  |  1994-06-24  |  15KB  |  574 lines

  1. /* TITLE: avm:rexx/handlefax.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername mailbox .
  23. if symbol('mailbox') ~= 'VAR' | mailbox = '' then mailbox = 'manual'
  24. options failat 50
  25.  
  26. 'turnoffvoicemode'
  27.  
  28. 'assumemode' 'Unknown'
  29.  
  30. 'setserial' '19200' '8' 'N' '1' '7Wire'
  31. action = rc
  32. select
  33.   when action = 0 then nop
  34.   when action = 14 then nop
  35.   when action = 16 then nop
  36.   otherwise signal arexxerror
  37. end
  38.  
  39. isTrapFax:
  40. faxprogram = upper(getclip('AVMFaxProgram'))
  41. if faxprogram = 'TRAPFAX' then do
  42.  
  43. call showDebugger('Starting TrapFax reception.')
  44. call time('r')
  45. /*----------------------------------------*/
  46. address rexx 'setuptfax.avm'
  47. /*----------------------------------------*/
  48.  
  49. 'writeline' 'ATA'
  50.  
  51. address command "trapfax:tfaxdoor getty"
  52. call showDebugger('TrapFax reception ' || time('e'))
  53.  
  54. isGPFax:
  55. end; else if faxprogram = 'GPFAX' then do
  56.  
  57. call showDebugger('Starting GPFax reception.')
  58. call time('r')
  59.  
  60. address rexx_gpfax 'listen'
  61. address rexx_gpfax 'recfax'
  62. faxresult = rc
  63. address rexx_gpfax 'unlisten'
  64. call showDebugger('GPFax result is' faxresult)
  65. call showDebugger('GPFax done ' || time('e'))
  66.  
  67. isEFax:
  68. end; else if faxprogram = 'EFAX' then do
  69. /* create a unique filename */
  70. efaxFileName = makeUniqueFile()
  71. call time('r')
  72. address command 'avm:gnu/efax -p' servername '-r' voiceFile(mailbox, efaxFileName)
  73. efaxLength = time('e')
  74.  
  75. end
  76.  
  77. doneRecFax:
  78. 'delay' 2
  79. action = rc
  80. select
  81.   when action = 0 then nop
  82.   when action = 12 then signal stdabort
  83.   when action = 14 then signal stderror
  84.   when action = 16 then signal stderror
  85.   otherwise signal arexxerror
  86. end
  87.  
  88. 'writeline' 'AT+FCLASS=0'
  89.  
  90. 'readline' '2'
  91. action = rc
  92. if action = 0 then value = result
  93. select
  94.   when action = 0 then nop
  95.   when action = 10 then nop
  96.   when action = 12 then signal stdabort
  97.   when action = 14 then signal stderror
  98.   when action = 16 then signal stderror
  99.   otherwise signal arexxerror
  100. end
  101.  
  102. 'readline' '2'
  103. action = rc
  104. if action = 0 then value = result
  105. select
  106.   when action = 0 then nop
  107.   when action = 10 then nop
  108.   when action = 12 then signal stdabort
  109.   when action = 14 then signal stderror
  110.   when action = 16 then signal stderror
  111.   otherwise signal arexxerror
  112. end
  113.  
  114. createLog:
  115. handle = makeUniqueFile()
  116. call initLogEntry()
  117.  
  118. log.comment = 'Fax attempted.'
  119. log.type = 'Try_FAX'
  120. if faxprogram = 'GPFAX' then do
  121.   if faxresult <= 5 then signal gotfaxgpfax
  122. end; else if faxprogram = 'TRAPFAX' then do
  123.   call open('cfaxlstfl', 'trapfax:trapfax.log', 'r')
  124.   call open('cfaxnrfl', 'trapfax:incoming/trapfax.sequence', 'r')
  125.   cfaxnr = readln('cfaxnrfl')
  126.   cnewfaxnr = right(cfaxnr, 4, '0')
  127.  
  128.   do forever
  129.     cfax = readln('cfaxlstfl')
  130.     cfaxlsnr = right(left(cfax, 6), 4)
  131.     if cfaxlsnr = cfaxnr | eof('cfaxlstfl') then break
  132.   end
  133.   call close('cfaxlstfl'); call close('cfaxnrfl')
  134.   if left(cfax, 1) ~= 'E' then signal gotfaxtrapfax
  135. end; else if faxprogram = 'EFAX' then do
  136.  
  137. if exists(voiceFile(mailbox, efaxFileName) || '.001') then signal gotfaxefax
  138. end
  139.  
  140. signal finished
  141.  
  142. gotfaxgpfax:
  143. address rexx_gpfax 'reportlog' 1
  144. faxfilename = result
  145. log.filename = result
  146.  
  147. address rexx_gpfax 'reportlog' 6
  148. log.length = result
  149. address rexx_gpfax 'reportlog' 2
  150. log.comment = result 'page(s) received.'
  151.  
  152. address rexx_gpfax 'reportlog' 4
  153. log.returnnumber = result
  154. log.type = 'fax'
  155. signal finished
  156.  
  157. gotfaxtrapfax:
  158. faxfilename = 'trapfax:incoming/In-' || cfaxnr || '.FAX'
  159. log.filename = faxfilename
  160. myvar = right(left(cfax, 54), 5)
  161. myvar = (left(myvar, 2)*60) + (right(myvar, 2))
  162. log.length = myvar
  163. myvar = right(left(cfax, 47), 2); myvar = strip(myvar, 'L')
  164. log.comment = myvar 'page(s)'
  165. myvar = right(left(cfax, 45), 22)
  166. myvar = strip(myvar, 'T')
  167. log.returnnumber = myvar; log.type = 'fax'
  168. signal finished
  169.  
  170. gotfaxefax:
  171. log.filename = efaxFileName
  172. faxfilename = efaxFileName
  173. log.type = 'fax'
  174. log.length = efaxLength
  175. base = voiceFile(mailbox, efaxFileName) || '.'
  176. do i = 1 to 999
  177.   if ~exists(base || right(i, 3, '0')) then break
  178. end
  179. log.comment = i - 1 'page(s).'
  180.  
  181. log.returnNumber = getclip(upper(servername || '.faxid'))
  182. signal finished
  183.  
  184. finished:
  185. call saveLogEntry(mailbox, handle)
  186.  
  187. call loadMailbox(mailbox)
  188. if upper(log.type) = 'FAX' & mailbox.autofaxforwardb = 1 & mailbox.autofaxforwardscript ~= "" then do
  189.   handle = makeUniqueFile()
  190.   call initLogEntry(); log.origmailbox = mailbox
  191.   log.filename = voiceFile(mailbox, faxfilename); log.type = 'fax'
  192.   log.returnsendfunc = mailbox.autofaxforwardscript; log.returninterval = 5
  193.   log.returnretry = 3; log.returnnumber = mailbox.autofaxforward
  194.   call saveLogEntry('Outgoing', handle)
  195. end
  196.  
  197. exit
  198.  
  199. /* TITLE: avm:rexx/simplestdtail.avm */
  200. /* This is the standard tail */
  201. exit
  202.  
  203. exit
  204.  
  205. mailboxDir: procedure
  206.     parse arg mailbox
  207.  
  208.     return 'avm:' || mailbox || '/'
  209.  
  210. logFile: procedure
  211.     parse arg mailbox, magiccookie
  212.  
  213.     return 'avm:' || mailbox || '/logs/' || magiccookie
  214.  
  215. voiceFile: procedure
  216.     parse arg mailbox, magiccookie
  217.  
  218.         if (verify(magiccookie, '/:', 'M') = 0) then
  219.           return 'avm:' || mailbox || '/voices/' || magiccookie
  220.         else
  221.           return magiccookie
  222.  
  223. makeUniqueFile: procedure
  224.     if arg() ~= 0 then do
  225.         rc = "makeUniqueFile: bad args"
  226.         signal error
  227.     end
  228.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  229.  
  230. convertToDate: procedure
  231.     if arg() ~= 1 then do
  232.         rc = "convertToDate: bad args"
  233.         signal error
  234.     end
  235.     parse arg timeInC
  236.  
  237.     actualTime = (timeInC - (2922)*86400) // (86400)
  238.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  239.  
  240.     return actualDate /* returning it in 'internal' format */
  241.  
  242. convertToTime: procedure
  243.     if arg() ~= 1 then do
  244.         rc = "convertToTime: bad args"
  245.         signal error
  246.     end
  247.     parse arg timeInC
  248.     
  249.     actualTime = (timeInC - (2922)*86400) // (86400)
  250.  
  251.     return actualTime
  252.  
  253. cTime: procedure
  254.     /* 2922 = 8*365 + 2 */
  255.     /* 86400 = 24*60*60 */
  256.     return (date('i')+2922)*86400 + time('s')
  257.  
  258. /* this returns a handle that you must use after initializing log. */
  259. initLogEntry: procedure expose log.
  260.     if arg() ~= 0 then do
  261.         rc = "initLogEntry: bad args"
  262.         signal error
  263.     end
  264.     
  265.     drop log.
  266.         log. = ''
  267.  
  268.         acidname = getclip(address() || 'CIDNAME')
  269.         acidnumber = getclip(address() || 'CIDNUMBER')
  270.  
  271.     /* 2922 = 8*365 + 2 */
  272.     /* 86400 = 24*60*60 */
  273.     log.time = (date('i')+2922)*86400 + time('s')
  274.     log.cidname = acidname
  275.     log.cidnumber = acidnumber
  276.  
  277.     return
  278.  
  279. loadLogEntry: procedure expose log.
  280.     if arg() ~= 2 then do
  281.         rc = "loadLogEntry: bad args"
  282.         signal error
  283.     end
  284.     parse arg mailbox, handle
  285.  
  286.         drop log.
  287.         log. = ''
  288.  
  289.     if ~exists(mailboxDir(mailbox)) then do
  290.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  291.         return
  292.     end
  293.  
  294.     opened = open(handle, logFile(mailbox, handle), 'r')
  295.         if opened then do
  296.         call showDebugger('Loading entry' logFile(mailbox, handle))
  297.         do while ~eof(handle)
  298.             line = readln(handle)
  299.             parse upper var line variable '=' value
  300.             log.variable = value
  301.         end
  302.         call close(handle)
  303.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  304.     return
  305.  
  306. /* pass a handle here */
  307. saveLogEntry: procedure expose log.
  308.     if arg() ~= 2 then do
  309.         rc = "saveLogEntry: bad args"
  310.         signal error
  311.     end
  312.     parse arg mailbox, handle
  313.  
  314.     if ~exists(mailboxDir(mailbox)) then do
  315.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  316.         return
  317.     end
  318.  
  319.     opened = open(handle, logFile(mailbox, handle), 'w')
  320.  
  321.     if opened then do
  322.         call showDebugger('Saving entry' logFile(mailbox, handle))
  323.         call writeln(handle, 'TYPE=' || log.type)
  324.         call writeln(handle, 'TIME=' || log.time)
  325.         call writeln(handle, 'LENGTH=' || log.length)
  326.  
  327.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  328.  
  329.         call writeln(handle, 'CIDNAME=' || log.cidname)
  330.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  331.  
  332.         call writeln(handle, 'COMMENT=' || log.comment)
  333.  
  334.