home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / popc221h.zip / lamailer.cmd < prev    next >
OS/2 REXX Batch file  |  1995-05-31  |  6KB  |  182 lines

  1. /**********************************************************************
  2.    LaMailer.cmd - Mail Delivery Agent for LaMail        
  3.    Copyright - Anonymous Software
  4.    J.Poltorak@bradford.ac.uk
  5.  
  6.    Modified by Claudio Fahey for popclient for OS/2
  7.    e-mail: claudio@uclink.berkeley.edu
  8.    Modified again by Clark Gaylord for popclient 2.21a
  9.    e-mail: cgaylord@vt.edu                     
  10.                                                
  11.    2.21a: Add PMPOPUP support.  Use POPUPBIFF environment variable.
  12.             If POPUPBIFF='YES' and pmpopup.exe is in the path, then
  13.             pop up a message about incoming mail.
  14.    2.21b: Unique file name (thanks to Mike Baum, baum@micf.nist.gov)
  15.           Escape '&' in 'from' and 'subject' before calling pmpopup
  16.    2.21c: Handle multi-line from: and subject: per Mike Baum.
  17.    2.21d and e: No changes to LaMailer.cmd
  18.    2.21f: Take out POPUPBIFF support; this is now part or PopCliD.cmd
  19. **********************************************************************/
  20.  
  21. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  22. call SysLoadFuncs
  23.  
  24. parse arg '-dest ' maildir ' -to ' to
  25. /* 'To' is not used. */
  26.  
  27. date = date('o')
  28. time = time()
  29. mailbox = maildir
  30. inbox  = mailbox'\inbox.ndx'
  31.  
  32. /**********************************************************************
  33. Here's where we get a unique filename.  The need to be careful was 
  34. pointed out by Mike Baum.
  35. We let SysTempFileName pull its weight.
  36. **********************************************************************/
  37. parse value date time with  2 yy'/'mon'/'dd  hh':'+1 m +1 mm':'ss
  38. msg = SysTempFileName( mailbox'\'mon || dd || yy || hh || m'.'mm || '??' )
  39.  
  40. /**********************************************************************
  41. I'll leave Mike's code here in case anyone wants to use it.  CKG
  42.  
  43. fexist.0 = 1
  44. msg =  mailbox'\'mon || dd || yy || hh || m'.'mm || ss
  45. do while fexist.0                     
  46.     call SysFileTree msg,fexist,'F'
  47.     if fexist.0 then do
  48.         ss = ss + 1
  49.         msg = mailbox'\'mon || dd || yy || hh || m'.'mm || right(ss,2,'0')
  50.     end
  51. end
  52. **********************************************************************/
  53.  
  54.  
  55. header_state = 1
  56. flag. = 0           /* Work flags - building the From: or Subject: fields. */
  57. subject = ''
  58.  
  59. do while lines() \= 0
  60.     line=linein()
  61.     if line = '' then header_state = 0
  62.     if (header_state) then do
  63.         token=word(line,1)
  64.         if (substr(token,length(token))=':') then do
  65.             /* If this is a header tag reset the work flags.   */
  66.             flag. = 0
  67.         end
  68.         Select
  69.             when token = 'From:' then do
  70.                 /* Start to build From: field */
  71.                 fromline = subword(line,2)      
  72.                 flag.f = 1                      
  73.                 /* Build-in-progress */ 
  74.                 end
  75.             when token = 'Subject:' then do
  76.                 /* Start to build Subject: field */
  77.                 subject = strip(subword(line,2))
  78.                 flag.s = 1
  79.                 end
  80.             when flag.f = 1 then
  81.                 /* Still working on From: ... */
  82.                 fromline = fromline||line
  83.             when flag.s = 1 then
  84.                 /* Still working on Subject: ... */
  85.                 subject = subject' 'strip(line)
  86.             Otherwise NOP
  87.         end
  88.     end
  89.  
  90.     call lineout msg, line
  91. end
  92.  
  93. parse var fromline fullname '<' from '>'
  94. if from = '' then do
  95.     from = word(fullname,1)
  96.     fullname = ''
  97. end
  98.  
  99. call index
  100. call lineout msg
  101.  
  102. /* I added this section.  CKG */
  103. SAY 'Mail:' From Subject
  104. SAY PopUpExe
  105. SAY From
  106. SAY Subject
  107. SAY Mailbox
  108. SAY Inbox
  109.  
  110. /* Do we want BIFF and is PMPOPUP available */
  111. /**********************************************************************
  112. This feature is now moved to PopCliD.cmd ... if you want a message-by-
  113. message BIFF, then uncomment this part.  Note that you still get a list
  114. in the text-window; I've just taken out the PMPOPUP messages.
  115.  
  116. PopUpBiff = Value('POPUPBIFF',,'OS2ENVIRONMENT')
  117. IF (PopUpBiff = 'YES') THEN DO
  118.     PopUpExe = SysSearchPath( 'PATH', 'pmpopup.exe')
  119.     IF (PopUpExe\='') THEN DO
  120.         From = RmPipe( From )
  121.         Subject = RmPipe( Subject )
  122.         IF (Subject = '') THEN
  123.             "@start" PopUpExe "New mail from" From
  124.         ELSE
  125.             "@start" PopUpExe "New mail from" From "about" Subject
  126.     END
  127. END
  128. **********************************************************************/
  129.  
  130. EXIT
  131.  
  132. index:
  133.    nickname = copies(' ',8)
  134.    fullname = strip(fullname)
  135.    from = strip(from)
  136.    parse value from with userid '@' nodename '.'
  137.    size = copies(' ',12)
  138.    f1 = copies(' ',8)
  139.    seen = ' '
  140.    from_to = ' '
  141.    f2 = ' '
  142.    call lineout inbox, nickname,
  143.        left(userid,8),
  144.        left(nodename,8),
  145.        translate(filespec('n',msg),' ','.'),
  146.        size,
  147.        date,
  148.        substr(time,1,5),
  149.        f1,
  150.        seen,
  151.        from_to,
  152.        f2,
  153.        fullname'01'x ||subject'0101'x ||from
  154. return
  155.  
  156. EscChar:
  157.     PARSE ARG Needle, Haystack
  158.     OutString = ''
  159.     DO Until (Length(Haystack) = 0)
  160.         IF (Pos(Needle, Haystack) > 0) THEN DO
  161.             OutString = ,
  162.                 OutString ||,
  163.                 Left( Haystack, Pos(Needle, Haystack)-1 ) ||,
  164.                 ' ^' ||,
  165.                 Needle
  166.             Haystack = SubStr( Haystack, Pos(Needle, Haystack)+1 )
  167.         END
  168.         ELSE DO
  169.             OutString = OutString || Haystack
  170.             Haystack = ''
  171.         END
  172.     end  
  173.     Return OutString
  174.  
  175. RmPipe:
  176.     PARSE ARG String
  177.     String = EscChar( '&', String )
  178.     String = EscChar( '|', String )
  179.     String = EscChar( '>', String )
  180.     String = EscChar( '<', String )
  181.     Return String
  182.