home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / chang09m.zip / ihave.cmd < prev    next >
OS/2 REXX Batch file  |  1995-08-10  |  3KB  |  126 lines

  1. /* Implements posting with IHAVE command */
  2.  
  3. if RxFuncQuery("SockLoadFuncs") then do
  4.   rc = RxFuncAdd("SockLoadFuncs", "rxSock", "SockLoadFuncs")
  5.   rc = SockLoadFuncs()
  6. end  /* Do */
  7.  
  8. crLf = d2c(13) || d2c(10)
  9. tmpFName = "ihavetmp.!@#"
  10. '@erase' tmpFName '2>nul'
  11. call stream "inews.log", "c", "seek <0"
  12. fromID = ""
  13. newsGroups = ""
  14. interval = time('E')
  15. seqNo = lineIn("SEQF")
  16.  
  17. nntp_neighbor = VALUE('NNTPNEIGHBOR',,'OS2ENVIRONMENT')
  18.  
  19. hostAddr = SockGetHostID()
  20. rc = SockGetHostByAddr(hostAddr, host.!)
  21.  
  22. message_id = "<D"date('S')"T"time('S')"X"seqNo"@"host.!name">"
  23.  
  24. call rewrite
  25.  
  26. rc =SockGetHostByName(nntp_neighbor, "host.!")
  27. if (rc = 0) then do
  28.   call lineOut "inews.log", "Unable to resolve name of nntp neighbor."
  29.   exit 1
  30. end
  31. server = host.!addr
  32.  
  33. sock = SockSocket("AF_INET", "SOCK_STREAM", "IPPROTO_TCP")
  34. if (sock = -1) then do
  35.   call lineOut "inews.log", "Error opening socket: " errno
  36.   exit errno
  37. end
  38.  
  39. server.!family = "AF_INET"
  40. server.!port = 119
  41. server.!addr = server
  42.  
  43. rc = SockConnect(sock, "server.!")
  44. if (sock = -1) then do
  45.   call lineOut "inews.log", "Error connecting socket: " errno
  46.   exit errno
  47. end
  48.  
  49. rc = SockRecv(sock, "data", 8000)
  50.  
  51. rc = SockSend(sock, "ihave" message_id || crLf)
  52. rc = SockRecv(sock, "data", 8000)
  53.  
  54. parse var data sockRc '0D'x restOfLine
  55. parse var sockRc sockRc ' ' junk
  56.  
  57. if (sockRc \= 335) then do
  58.   call lineOut "inews.log", date("U") time(),
  59.         "Error IHAVE refused:" sockRc
  60.   rc = SockClose(sock)
  61.   exit sockRc
  62. end
  63.  
  64. inLine = lineIn(tmpFName)
  65. do while lines(tmpFName) > 0
  66.   rc = SockSend(sock, inLine || crLf)
  67.   inLine = lineIn(tmpFName)
  68. end
  69. rc = SockSend(sock, "."||crLf)
  70. rc = SockRecv(sock, "data", 8000)
  71.  
  72. call stream tmpFName, "Command", "Close"
  73.  
  74. parse var data sockRc '0D'x restOfLine
  75. parse var sockRc sockRc ' ' junk
  76.  
  77. call lineOut "inews.log", date("U") time() "IHAVE (6/13/95)"
  78. call lineOut "inews.log", date("U") time() "IHAVE spooling news to",
  79.         newsGroups "from" fromID
  80. interval = time("E")
  81. if (sockRc = 235) then do
  82.   '@rnews <'||tmpFName
  83.   call lineOut "inews.log", date("U") time(),
  84.         "IHAVE processed 1 article in" strip(time("E"),,'0'),
  85.         "seconds"
  86.   call lineOut "inews.log", ""
  87. end  /* Do */
  88. else do
  89.   call lineOut "inews.log", date("U") time(),
  90.         "Error IHAVE refused:" sockRc
  91.   '@erase' tmpFName '2>nul'
  92.   rc = SockClose(sock)
  93.   exit sockRc
  94. end  /* Do */
  95.  
  96. '@erase' tmpFName '2>nul'
  97.  
  98. rc = SockClose(sock)
  99. exit
  100.  
  101. rewrite: procedure expose message_id tmpFName fromID newsGroups
  102.  
  103. inLine = lineIn()
  104. do while inLine <> ''
  105.   parse var inLine lineType ':' lineValue
  106.   call lineOut tmpFName, inLine
  107.   if lineType = "Newsgroups" then
  108.     newsGroups = lineValue
  109.   if lineType = "From" then
  110.     fromID = lineValue
  111.   if lineType = "Subject" then do
  112.     call lineOut tmpFname, "Date:" date() time()
  113.     call lineOut tmpFName, "Message-ID:" message_id
  114.     call lineOut tmpFName, "Path: kserver!not-for-mail"
  115.   end
  116.   inLine = lineIn()
  117. end /* do */
  118.  
  119. do while lines() > 0
  120.   call lineOut tmpFName, inLine
  121.   inLine = lineIn()
  122. end /* do */
  123.  
  124. call stream tmpFName, 'Command', 'Close'
  125. return
  126.