C
C WF -- Wollongong filter
C Forwards VMS mail to one TCP/IP node through the Wollongong gateway.
C This is elegant but it gets the job done.
     
      CHARACTER FF/'0C'X/
      CHARACTER NAME*12,RECORD*80
     
      OPEN(UNIT=7,FILE='MAIL.OUT',TYPE='OLD',READONLY)
      OPEN(UNIT=8,FILE='MAIL.TMP',TYPE='NEW')
     
C Scan the input file for a FORM FEED record; this begins mail msg
      DO WHILE (.TRUE.)
        READ(7,'(Q,A)',END=999)LEN,RECORD
     
        IF ((LEN.EQ.1).AND.(RECORD(1:1).EQ.FF(1:1))) THEN
      READ(7,'(Q,A)',END=999)LEN,RECORD
     
C Found FF record but this is not conclusive (FF record can be in text)
C Read next record for 'From: ...'
      IF(RECORD(1:5).EQ.'From:') THEN
     
C Write out last two records so we don't get ahead of ourselves
      WRITE(8,'(A)')FF
      WRITE(8,'(A<LEN>)')RECORD
     
C Now get the recipient line (To: ...)
110   READ(7,'(Q,A)',END=999)LEN,RECORD
      IF(RECORD(1:3).NE.'To:') THEN
        WRITE(8,'(A<LEN>)')RECORD
        GOTO 110
     
C Found the recipient line
      ELSE
     
C Is it a forwarded message from VMSmail (MAIL> SET FORWARD MAILER) or
C an IP/TCP message (To: MAILER!<...  )
        IF(RECORD(5:11).EQ.'MAILER!') THEN
     
C This is IP/TCP message; write the record and return to FF scan (write
C remainder of message
      WRITE(8,'(A<LEN>)')RECORD
      ELSE
     
C Here is a forward VMSmail message; create the correct entry for the MAILER
      WRITE(NAME,'(A)')RECORD(5:LEN)
     
CCC  --->  Change the UW-CHEM nodename
      WRITE(8,'(A,''MAILER!<'',A,''@UW-CHEM>'')')RECORD(1:4),
     1 NAME(1:LEN-4)
     
      ENDIF !if(record(5:11
     
      ENDIF !if(record(1:3
     
      ELSE
C FF record but not the beginning a message; write FF and next record
      WRITE(8,'(A)')FF
      WRITE(8,'(A<LEN>)')RECORD
      ENDIF !if(record(1:5
     
      ELSE
C Just write the record to the output file
      WRITE(8,'(A<LEN>)')RECORD
      ENDIF !if ((len
     
      ENDDO !while
999   END
