home *** CD-ROM | disk | FTP | other *** search
/ Merciful 3 / Merciful_Release_3.bin / software / c / crashmailv1.22reg.lha / CrashMail / rexx / RequestBot.rexx < prev    next >
OS/2 REXX Batch file  |  1996-02-07  |  3KB  |  109 lines

  1. /*
  2.  
  3.    RequestBot.rexx
  4.  
  5.    This is a robot that lets you request textfiles that are then sent
  6.    to you as a netmail. The robot understand two commands:
  7.  
  8.    %GET <file>       Requests a textfile
  9.    %LIST             Lists all available textfiles
  10.  
  11.    Configure as "rx RequestBot.rexx %r" (with path if needed) in CrashPrefs.
  12.  
  13. */
  14.  
  15. /* Configuration */
  16.  
  17. crashwrite = "Work:UMS/CrashMail/CrashWrite"
  18. inbound = "MAIL:Inbound"
  19. listformat = "%-20.20s %7l %.50c"  /* Passed to c:list as lformat */
  20. directory = "MAIL:Text"
  21.  
  22. /* Enf of configuration */
  23.  
  24. if right(directory,1)~=":" & right(directory,1)~="/" then do
  25.  directory=directory || "/"
  26. end
  27.  
  28. IF ~SHOW(Libraries,'rexxsupport.library') THEN
  29.     IF ~ADDLIB("rexxsupport.library",0,-30,0) THEN EXIT
  30.  
  31. parse arg file
  32.  
  33. kg=TRUE
  34.  
  35. to=""
  36. toaddr=""
  37. from=""
  38. fromaddr=""
  39.  
  40. call open('file',file,'R')
  41.  
  42. do while kg=TRUE
  43.  str = readln('file')
  44.  
  45.  if eof('file') then do
  46.    kg=FALSE
  47.  end
  48.  else if length(str)=0 then do
  49.    kg=FALSE
  50.  end
  51.  else do
  52.    if left(str,5)="From:" then parse var str 'From: 'fromaddr'@'dummy' ('fromname')'
  53.    if left(str,3)="To:" then parse var str 'To: 'toaddr'@'dummy' ('toname')'
  54.  end
  55. end
  56.  
  57. call open('out','T:RequestBot.tmp','W')
  58.  
  59. kg=TRUE
  60.  
  61. do while kg=TRUE
  62.     str = readln('file')
  63.  
  64.     if left(str,3)="---" then do
  65.      kg=FALSE
  66.     end
  67.     else if left(str,1)="%" then do
  68.      parse var str "%"command" "file
  69.      parse upper var command command
  70.      if command='GET' then do
  71.       if pos(":",file)~=0 | pos("/",file)~=0 then do
  72.        call writeln('out',left(str,20) || "Illegal file name")
  73.       end
  74.       else if exists(directory||file) then do
  75.        address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "'file'" DIR "'inbound'"' directory||file
  76.        call writeln('out',left(str,20) || "File sent")
  77.       end
  78.       else do
  79.        call writeln('out',left(str,20) || "File not found")
  80.       end
  81.      end
  82.      else if command='LIST' then do
  83.       address command 'c:list >T:RequestList.tmp' directory 'lformat "'listformat'"'
  84.       address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "List of available files" DIR "'inbound'" T:RequestList.tmp'
  85.       call writeln('out',left(str,20) || "List sent")
  86.       call delete("T:RequestList.tmp")
  87.      end
  88.      else do
  89.       call writeln('out',left(str,20) || "Unknown command")
  90.      end
  91.     end
  92.  
  93.     if eof('file') then do
  94.       kg=FALSE
  95.     end
  96. end
  97.  
  98. call close('file')
  99. call close('out')
  100.  
  101. /* Send the mail using CrashWrite */
  102.  
  103. address command crashwrite 'FN "RequestBot" FA 'toaddr' TN "'fromname'" TA 'fromaddr' SUBJ "Response to your request" DIR "'inbound'" T:RequestBot.tmp'
  104. call delete("T:RequestBot.tmp")
  105. address command 'Run >NIL: <NIL: rx "address 'CRASHMAIL' toss"'
  106.  
  107. exit 10
  108.  
  109.