home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / comm / mail / YAMscripts.lha / Fileserver.rexx < prev    next >
OS/2 REXX Batch file  |  1996-12-05  |  3KB  |  78 lines

  1. /* YAM file server. Version:1.1 11-Nov-96
  2.      The script understands 3 types of requests
  3.     1. request index  - list of files in the directory.  It's created when a
  4.                         request is encountered, you don't need to do it yourself.
  5.     2. request help   - send helpfile
  6.        request info
  7.     3. request <file> - send a file    
  8.      Send comments, bug reports or hate mail to knikulai@utu.fi.  You can also
  9.      test this script by sending mail to me.
  10. */
  11. Options Results
  12.  
  13. folder=0            /* Number of the folder where messages are */
  14. sdir='packed:FileServer/'    /* Full path to the directory where files are kept */
  15. helpname='packed:FileServer/HelpFile.txt' /* Full path to the helpfile */
  16.  
  17. call addlib('rexxsupport.library',0,-30,0)
  18.  
  19. /* YAM is probably already running, but let's be cautious */
  20. if show('P','YAM')=0 then do           /* YAM is not running yet, so let's start it */
  21.   address command 'run <>nil: yam:yam nocheck'
  22.   i=0
  23.   do until show('P','YAM')>0 | i=3     /* Let's not wait more than 30 seconds */
  24.     address command 'sys:rexxc/WaitForPort YAM'
  25.     i=i+1
  26.   end /* do */
  27.   if show('P','YAM')=0 then do         /* Something went wrong, let's quit */
  28.     address command 'RequestChoice <>nil: "Error!" "Can not start YAM!" ":-("'
  29.     exit
  30.   end
  31. end
  32.  
  33. /* Now we know YAM is up and running */
  34.  
  35. address 'YAM' 'SetFolder ' || folder      /* Set current folder */
  36. address 'YAM' 'GetFolderInfo MAX'    /* How many messages are there? */
  37. n=result
  38. address command 'list >t:YFSindex.txt nohead dates ' || sdir
  39. do i=0 to n-1    /* Process all messages */
  40.     address 'YAM' 'SetMail' i        /* Set current message */
  41.     address 'YAM' 'GetMailInfo SUBJECT'    /* Get subject line */
  42.     subj=upper(result)
  43.     address 'YAM' 'GetMailInfo FILE'        /* get filename */
  44.     fs=statef(result)                       
  45.         fcomment=word(fs,words(fs))             /* get the last word (filenote) */
  46.         deleted=pos('D',fcomment)>0             /* true, if message was deleted */
  47.     if ~deleted & left(subj,8)='REQUEST ' then do
  48.         address 'YAM' 'MailDelete'
  49.         req=strip(word(subj,2))        /* What was requested? */
  50.         filename=sdir || req        /* Default is a file */
  51.         if req='HELP' then filename=helpname
  52.         if req='INFO' then filename=helpname
  53.         if req='INDEX' then filename='t:YFSindex.txt'            
  54.         address 'YAM' 'MailReply'
  55.         ft='text/plain'
  56.  
  57. /* Add the required filetypes here */
  58.         if pos('.GIF',req) >0 then ft='image/gif'
  59.         if pos('.JPG',req) >0 then ft='image/jpeg'
  60.         if pos('.MPG',req) >0 then ft='video/mpeg'
  61.         if pos('.WAV',req) >0 then ft='audio/basic'
  62.         if pos('.LHA',req) >0 then ft='application/octet-stream'        
  63.         if pos('.LZH',req) >0 then ft='application/octet-stream'        
  64.         if pos('.LZX',req) >0 then ft='application/octet-stream'
  65.  
  66.         desc=' "" MIME '        
  67.         address 'YAM' 'WriteAttach '|| filename || desc || ft 
  68.         if ~exists(filename) then do 
  69.             address 'YAM' 'WriteSubject "Requested file not found, index sent"'
  70.             address 'YAM' 'WriteLetter t:YFSindex.txt'
  71.             end
  72.         address 'YAM' 'WriteQueue'        
  73.     end /*if left(subj,8)='REQUEST ' then*/
  74. end /*do*/
  75. address 'YAM' 'MailSendAll'
  76. /* call delete('t:YFSindex.txt') */  
  77. exit
  78.