Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: Bob Harris <harris@zk3.dec.com>
To: johnson@isn.dac.neu.edu (Chris Johnson)
Subject: Re: VAX/VMS -> ALPHA/TRU64 migration tool.
Date: 1999/10/29	[thread overview]
Message-ID: <291019990911363982%harris@zk3.dec.com> (raw)
In-Reply-To: 7v2aq8$qi3$1@isn.dac.neu.edu

[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]

In article <7v2aq8$qi3$1@isn.dac.neu.edu>, Chris Johnson
<johnson@isn.dac.neu.edu> wrote:
>     We're getting ride of our VAXen and migrating to an ALPHA w/
>TRU64 UNIX.  The big issue is to move the mail.  I can extract it to
>text files on the VAX with the MAIL utility.  I wrote a little PERL
>script to convert the text into something acceptable to sendmail &
>Pine & IMAP.  Doesn't always work.  First off, intermixed with
>Internet mail is local intra-VMS mail which has no Internet headers.
>Second, even when there are only Internet SMTP message in there it
>still doesn't always work.  I've found one reason; the Y2K change a
>few years ago.  The headers were changed for Y2K complaince.  Some
>users have mail upwards of nine years old or more.
>
>     So, I'm looking for a tool, C, Perl, don't care pretty much,
>which can move these extracted mail files into a sendmail/Pine folder
>format a lot more reliably than what I have.  I can't imaging I'm THE
>only person to go through this.  Unfortunately I just don't have the
>time to do it myself.  We're tring to do this by 31-Dec-1999 and there
>are roughly 1000 users (gulp!).

Here is a fortran program that someone gave me from the newsgroups
which I used about 4 years ago when I switched from OpenVMS to UNIX. 
If you do not have a fortran compiler, then maybe you can use the code
to help you write a 'C' version.



c From: Mark London <MRL@PFC.MIT.EDU>
c Newsgroups: comp.os.vms
c Subject: VMS to Unix mail converter.
c Message-ID: <950118122414.2be1d319@PFC.MIT.EDU>
c Date: Wed, 18 Jan 1995 12:24:14 -0500 (EST)
c Organization: Info-Vax<==>Comp.Os.Vms Gateway
c X-Gateway-Source-Info: Mailing List
c Lines: 455
c 
c Someone was nice enough to send me a copy of a program to convert vms
mail
c files to unix mail files.  It did have a few problems which I fixed,
mainly
c that it did not work with v4 mail format, and that it did not convert
vms
c network addresses.  Here it is. 
c
c program v2u_mail
c
c       convert mail files from VMS to UNIX
c
c       V2U_MAIL, a hack by Rob Riepel (rob@ssvax1.ssd.loral.com)
c
c         This program was whipped up to convert my VMSmail to Unix.  I
c         hope it works for you too.  If you make improvements, please
c         let me know.  If you're seriously into hackery, use the
callable
c         mail interface to parse through the VMSmail messages, and make
c         sure the Unix mail headers conform to the relevant RFCs.
c
c       INSTRUCTIONS
c       ============
c
c       v2u_mail will will read standard VMSmail files and convert them
c       to Unix file files.  To use the program, first compile and link
c       it.
c
c          $ FOR V2U_MAIL
c          $ LIN V2U_MAIL
c
c       Next, assign the logical MAIL_DIR to point to the directory
where
c       all your VMSmail is stashed.
c
c          $ ASSIGN SYS$LOGIN_DEVICE:[MY_HOME.MAIL] MAIL_DIR
c
c       Move to the directory where you want the Unix mail folders, and
c       run V2U_MAIL.
c
c          $ SET DEFAULT [MY_HOME.UNIX_MAIL]
c          $ RUN [MY_HOME.V2U_MAIL]V2U_MAIL
c
c       A Unix mail file will be created for each folder in your
VMSmail.
c
c       This version has been modified by mrl@pfc.mit.edu.  Changes are:
c       It now changes VMS network address to IP network address, i.e. 
c       IN%"MRL@PFC.MIT.EDU" changed to MRL@PFC.MIT.EDU
c       It now changes decnet addresses to IP addresses, i.e. 
c       MERLOT::MRL changed to MRL@MERLOT.PFC.MIT.EDU
c       The above is done only if UCX$BIND_DOMAIN is a logical name
defined
c       to be the domain that the decnet addresses are located in.
c       Modified to work with VMS V4 mail format.
c       Change lines that start with "From" to ">From" so mailer does
not
c       think it's the beginning of a new message.
c

        implicit integer*4 (a-z)

        common  /count/ mcount

        character       cbuf*2048
        integer*4       ibuf(2048), mcount /0/
        integer*4       rlen
        equivalence     (cbuf,ibuf)

        common /domain/ domain,ldomain
        character       domain*80

        common /host/ host,lhost
        character       host*80

        ldomain = SYS_TRNLNM('UCX$BIND_DOMAIN',domain)
        if (.not.ldomain) then 
            ldomain = 0
        else 
            call str$trim(domain,domain,ldomain)
        endif

        lhost = SYS_TRNLNM('UCX$INET_HOST',host)
        if (.not.lhost) then 
            lhost = 0
        else 
            call str$trim(host,host,lhost)
        endif

c       open the mail file, twice

        open(   unit=10,
     &          file='mail_dir:mail.mai',
     &          access='keyed',
     &          key=(1:8:integer,10:48:character),
     &          blocksize=2048,
     &          organization='indexed',
     &          recordtype='variable',
     &          form='formatted',
     &          shared,
     &          readonly,
     &          status='old')

        open(   unit=11,
     &          file='mail_dir:mail.mai',
     &          access='keyed',
     &          key=(1:8:integer,10:48:character),
     &          blocksize=2048,
     &          organization='indexed',
     &          recordtype='variable',
     &          form='formatted',
     &          shared,
     &          readonly,
     &          status='old')

c       read and process the first record

        read(10,'(Q,A2048)',keyge='A',keyid=1)rlen,cbuf
        call process_record(ibuf,ibuf,cbuf,rlen)

c       process the remaining records

        do while (1 .eq. 1)
            read(10,'(Q,A2048)',end=100)rlen,cbuf
            call process_record(ibuf,ibuf,cbuf,rlen)
        end do

c       we're done, write out the last folder's message count and leave

  100   continue
        if (mcount .gt. 0) write(6,10)null,mcount
   10   format(a1,i5,' messages')
        close(10)
        call exit
        end

        subroutine process_record(bbuf,ibuf,cbuf,rlen)

c       this is where all the work gets done

        implicit integer*4 (a-z)

        common  /count/ mcount

        byte         bytes(2), bbuf(2048)
        integer*2    dlen
        integer*4    ibuf(2048)
        character    cbuf*2048, folder*39, null*1, line*2048, name*80
        character    from*255, to*255, cc*255, subject*255, date*25
        character*3  aday(7) /'Mon','Tue','Wed','Thu','Fri','Sat','Sun'/
        character    ctime*80
        logical      iam

        equivalence  (dlen,bytes)

        common /domain/ domain,ldomain
        character       domain*80

        common /host/ host,lhost
        character       host*80

        save folder, flen

        null = char(0)

c       open a new UNIX mail file for each VMS mail folder

        len = index(cbuf(10:),null)
        if (folder(1:flen) .ne. cbuf(10:10+len-1)) then
            close(20)
            flen = len
            folder(1:len) = cbuf(10:10+len-1)
            folder(flen+1:) = '.'
            if (mcount .gt. 0) write(6,10)null,mcount
   10       format(a1,i5,' messages')
            mcount = 0
            write(6,20)folder(1:flen)
   20       format(1x,'Processing folder ',a,t50,'...',$)
            open(20,name=folder(1:flen+1),status='new',recl=2048,
     &              carriagecontrol='list')
        endif

c       count the messages

        mcount = mcount + 1

c       parse out the from, to, subject, etc...

        if (bbuf(63).eq.5) then 
            base = 89
        else 
            base = 65
        endif

        from_len = 0
        cc_len = 0
        to_len = 0
        subject_len = 0
        do while (bbuf(base).ne.5)
            base = base + 2
            bytes(1) = bbuf(base)
            bytes(2) = bbuf(base+1)
            if (bbuf(base-2).eq.0.and.dlen.gt.0) then 
                from_len = dlen
                from = cbuf(base+2:base+from_len+1)
                if (index(from,'%"').gt.0) then
                    if (index(from,'::').gt.0) then 
                        from_len = from_len - index(from,'::') - 1
                        from = from(index(from,'::')+2:)
                    endif
                    from_len = from_len - index(from,'%"') - 2
                    from = from(index(from,'%"')+2:)
                    from =
from(:index(from,'"')-1)//from(index(from,'"')+1:)
                else if (index(from,'::').gt.0.and.ldomain.gt.0) then 
                    from_len = from_len + ldomain
                    from = from(index(from,'::')+2:index(from,' ')-1)
     &                  //'@'//from(:index(from,'::')-1)//'.'
     &                  //domain(:ldomain)//from(index(from,' '):)
                else if (lhost.gt.0) then
                    from_len = from_len + lhost + 1
                    from = from(:index(from,' ')-1)
     &                  //'@'//host(:lhost)//from(index(from,' '):)
                endif
                from_len_short = index(from,' ') - 1
            else if (bbuf(base-2).eq.1.and.dlen.gt.0) then 
                to_len = dlen
                to = cbuf(base+2:base+to_len+1)
            else if (bbuf(base-2).eq.2.and.dlen.gt.0) then 
                subject_len = dlen
                subject = cbuf(base+2:base+subject_len+1)
            else if (bbuf(base-2).eq.3.and.dlen.gt.0) then 
                cc_len = dlen
                cc = cbuf(base+2:base+cc_len+1)
            endif
            base = base + dlen + 2
        enddo

c       do the time thing

        call lib$day_of_week(ibuf(1),day)
        call lib$sys_asctim(time_len,ctime,ibuf(1),)
        ctime(5:5) = char(ichar(ctime(5:5)) + 32)
        ctime(6:6) = char(ichar(ctime(6:6)) + 32)
        date = ' '//aday(day)//' '//ctime(4:6)//' '//ctime(1:2)//' '//
     &          ctime(13:20)//' '//ctime(8:11)

c       write out the mail header

        write(20,60)from(1:from_len_short),date,
     &              from(1:from_len_short),date,
     &              to(1:to_len)
        if (cc_len .gt. 0)write(20,62)cc(1:cc_len)
        write(20,64)from(1:from_len),subject(1:subject_len)

   60   format(    'From ',2a,/,
     &             'Return-path: <',a,'>'/,
     &             'Date: ',a,/
     &             'To: ',a)
   62   format(    'Cc: ',a)
   64   format(    'From: ',a,/,
     &             'Subject: ',a,/,
     &             'Status: RO',/)

c       attempt to read the body as a mail file record
c       and write out the records to the new file

        read(11,'(Q,A2048)',keyid=0,key=ibuf(15),err=80)rlen,cbuf
        base = 49

        do while (base .lt. rlen)
            bytes(1) = bbuf(base)
            bytes(2) = bbuf(base+1)
d           write(6,*)dlen
c           write(20,'(1x,A)')cbuf(base+2:base+dlen+1)
            if  ( cbuf(base+2:base+2+4) .eq. 'From '
     &      .and. dlen .gt. 4 ) then
                write(20,'(A,A)')'>',cbuf(base+2:base+dlen+1)
            else
                write(20,'(A)')cbuf(base+2:base+dlen+1)
            endif
            base = base + dlen + 2
        end do
        write(20,'(/)')
        return

c       body is in a separte file, open it and copy it to the new
c       mail file

   80   continue
        write(name,100)ibuf(15),ibuf(16)
  100   format('mail_dir:mail$',2Z8.8,'.mai')
        inquire(file=name,exist=iam)
        if(.not.iam)write(name,100)ibuf(16),ibuf(15)
d       write(6,110)name
d 110   format(1x,'>',a,'<')
        open(12,name=name,status='old',readonly,recl=2048,err=140)
  120   continue
            read(12,'(Q,A)',end=140)llen,line
d           write(6,*)llen
c           write(20,'(1x,A)')line(1:llen)
            if (line(1:5).eq.'From '.and.llen.gt.4) then
                line = '>'//line
                llen = llen + 1
            endif
            write(20,'(A)')line(1:llen)
        go to 120

  140   continue
        write(20,'(/)')
        close(12)
        return
        end


        INTEGER FUNCTION SYS_TRNLNM(INPUT,OUTPUT)

        IMPLICIT INTEGER (A-Z)

        CHARACTER*(*) INPUT,OUTPUT

        PARAMETER LNM$_STRING = '2'X

        IF (INDEX(INPUT,']').GT.0) THEN
           SYS_TRNLNM = .FALSE.
           RETURN
        END IF

        CALL INIT_ITMLST        ! Initialize item list
        IF (OUTPUT.NE.'DEFINED') CALL ADD_2_ITMLST_WITH_RET
     &          (LEN(OUTPUT),LNM$_STRING,%LOC(OUTPUT),%LOC(OLEN))
        CALL END_ITMLST(TRNLNM_ITMLST)  ! Get address of itemlist

        EINPUT = INDEX(INPUT,':') - 1
        IF (EINPUT.LE.0) CALL STR$TRIM(OUTPUT,INPUT,EINPUT)

        SYS_TRNLNM = SYS$TRNLNM(,'LNM$FILE_DEV',INPUT(:EINPUT),,
     &          %VAL(TRNLNM_ITMLST))

        IF (SYS_TRNLNM.AND.OUTPUT.NE.'DEFINED') OUTPUT = OUTPUT(:OLEN)

        RETURN
        END


C       A set of routines to easily create item lists.  It allows one
C  to easily create item lists without the need for declaring arrays
C  or itemlist size.  Thus, the code can be easily changed to add or
C  delete item list codes.
C
C  Here is an example of how to use the routines (prints file to a
queue):
C
C       CALL INIT_ITMLST        ! Initialize item list
C                               ! Now add items to list
C       CALL ADD_2_ITMLST(LEN,SJC$_FILE_SPECIFICATION,%LOC(FILENAME))
C       CALL ADD_2_ITMLST(9,SJC$_QUEUE,%LOC(QUEUE))
C       CALL END_ITMLST(SNDJBC_ITMLST)  ! Get address of itemlist
C       IER =
SYS$SNDJBCW(,%VAL(SJC$_ENTER_FILE),,%VAL(SNDJBC_ITMLST),IOSB,,)
C
C  NOTE: These routines don't presently allow return length address
C  in item list.
C
        SUBROUTINE ITMLST_SUBS

        IMPLICIT INTEGER (A-Z)

        DATA SAVE_ITMLST_ADDRESS/0/,NUM_ITEMS/0/,QUEUE_HEADER/0/

        ENTRY INIT_ITMLST

        IF (QUEUE_HEADER.EQ.0) THEN     ! First time INIT_ITMLST ever
called?
           CALL LIB$GET_VM(8,QUEUE_HEADER)  ! Yes, create queue header
pointer
           CALL LIB$MOVC3(4,0,%VAL(QUEUE_HEADER))       ! Zero out
header
           CALL LIB$MOVC3(4,0,%VAL(QUEUE_HEADER+4))     ! Zero out
header
        ELSE IF (SAVE_ITMLST_ADDRESS.GT.0) THEN ! Clean out old item
list
           CALL LIB$FREE_VM((NUM_ITEMS+1)*12,SAVE_ITMLST_ADDRESS)
           NUM_ITEMS = 0                ! Release old itemlist memory
           SAVE_ITMLST_ADDRESS = 0
        ELSE                            ! ITMLST calls cannot be nested.
           WRITE (6,'('' ERROR: INIT_ITMLST called before
previous'',$)')
           WRITE (6,'(''+ ITMLST terminated with END_ITMLST.'')')
           CALL EXIT
        END IF

        RETURN


        ENTRY ADD_2_ITMLST(BUFLEN,CODE,BUFADR)
C
C  ITMLST entries are initially stored in a queue.  Each queue entry
C  needs 8 bytes for pointer + 12 bytes for itemlist info.
C
        CALL LIB$GET_VM(20,INPUT_ITMLST)        ! Get memory for entry

        CALL
STORE_ITMLST_ENTRY(%VAL(INPUT_ITMLST+8),BUFLEN,CODE,BUFADR,0)
                                                ! Store data in
itemlist format
        CALL LIB$INSQTI(%VAL(INPUT_ITMLST),%VAL(QUEUE_HEADER))
                                                ! Insert entry into
queue
        NUM_ITEMS = NUM_ITEMS + 1               ! Increment item count

        RETURN


        ENTRY ADD_2_ITMLST_WITH_RET(BUFLEN,CODE,BUFADR,RETADR)
C
C  ITMLST entries are initially stored in a queue.  Each queue entry
C  needs 8 bytes for pointer + 12 bytes for itemlist info.
C
        CALL LIB$GET_VM(20,INPUT_ITMLST)        ! Get memory for entry

        CALL STORE_ITMLST_ENTRY(%VAL(INPUT_ITMLST+8),BUFLEN,CODE,BUFADR,
        1                                                       RETADR)
                                                ! Store data in
itemlist format
        CALL LIB$INSQTI(%VAL(INPUT_ITMLST),%VAL(QUEUE_HEADER))
                                                ! Insert entry into
queue
        NUM_ITEMS = NUM_ITEMS + 1               ! Increment item count

        RETURN


        ENTRY END_ITMLST(ITMLST_ADDRESS)

        CALL LIB$GET_VM((NUM_ITEMS+1)*12,ITMLST_ADDRESS)
                                                ! Get memory for
itemlist
        SAVE_ITMLST_ADDRESS = ITMLST_ADDRESS    ! Save address to
remove memory

        DO I=1,NUM_ITEMS                        ! Place entries into
itemlist
           CALL LIB$REMQHI(%VAL(QUEUE_HEADER),INPUT_ITMLST)
           CALL LIB$MOVC3(12,%VAL(INPUT_ITMLST+8),
     &          %VAL(ITMLST_ADDRESS+(I-1)*12))
           CALL LIB$FREE_VM(20,INPUT_ITMLST)
        END DO

        CALL LIB$MOVC3(4,0,%VAL(ITMLST_ADDRESS+NUM_ITEMS*12))
                                        ! Place terminating 0 at end of
itemlist

        RETURN
        END



        SUBROUTINE STORE_ITMLST_ENTRY(INPUT_ITMLST,BUFLEN,CODE,BUFADR,
        1                                                       RETADR)

        IMPLICIT INTEGER (A-Z)

        STRUCTURE /ITMLST/
         UNION
          MAP
           INTEGER*2 BUFLEN,CODE
           INTEGER BUFADR,RETADR
          END MAP
         END UNION
        END STRUCTURE

        RECORD /ITMLST/ INPUT_ITMLST(1)

        INPUT_ITMLST(1).BUFLEN = BUFLEN
        INPUT_ITMLST(1).CODE = CODE
        INPUT_ITMLST(1).BUFADR = BUFADR
        INPUT_ITMLST(1).RETADR = RETADR

        RETURN
        END
 
c Mark London
c MRL@PFC.MIT.EDU



      reply	other threads:[~1999-10-29  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-25  4:00 VAX/VMS -> ALPHA/TRU64 migration tool Chris Johnson
1999-10-29  4:00 ` Bob Harris [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox