SUMMARY VMS -> UNIX mail conversion

From: Patrick O'Brien <pobrien_at_draco.harvard.edu>
Date: Wed, 1 Nov 1995 15:19:22 -0500

The problem as posted was that we have a number of users migrating
from VMS to DU, and who want to bring their VMS mail with them.
I was looking for a utility to help in that.

The solution I adopted was a Perl script (with man page) written
by Dr. Laurence G. Yaffeof the University of Washington Physics Dept.
It's appended here. Another program, written in C, was provided
by Harold March. Other suggestions were made, such as using
emacs rmail mode on both the VMS and UNIX sides.

Thanks to all for prompt replies, and apologies for a delay in summary.


G. Del Merritt
Sid Fagan
Hugh Messenger
Jim Belonis
Harold March


#!/pub/bin/perl -i.orig
'di';
'ig00';
#
# Fixmail - convert VMS mail files to Unix form.
# To save a VMS e-mail folder in a usable text file...
# inside of VMS MAIL
# EXTRACT/ALL/MAIL filename
#
# N.B.: does in-place editing.
#
$/ = "\f\nFrom" ; # Break at messages, not lines
 
$frompat = '^:\t(\S+)' # sender address
         . ' +(".+")?' # sender name
         . ' *(\d+)-(\w{3})-(\d{2}(\d{2}))' # dd-mm-yyyy date
         . ' +(\d+:\d+:\d+)\.?\d*' # hh:mm:ss.xx time
         . " *\n" ;
 
while (<>) # Read next message
    {
    s|$/$|\n| ; # Drop start of next message
 
    if ($. == 1) # First message in input file?
        {
        s/^\s*From// ; # Handle missing initial \f\n
        next if ! /\S/ ; # Handle leading \f\nFrom
        }
    $mesg++ ; # Count messages
 
    if (($addr, $name, $day, $mon, $year, $yr, $time) = (/$frompat/))
        {
        s/^.*\n// ; # drop From: line
        (($to) = /^To:\t(\S+) */) && s/^.*\n// ; # drop To: line
        (($cc) = /^CC:\t(.*)/) && s/^.*\n// ; # drop CC: line
        (($subj) = /^Subj:\t(.*)/) && s/^.*\n// ; # drop Subj: line
 
        $name =~ s/^"(.+)"$/$1/ ; # drop quotes
        $addr =~ s/^IN%"([^"]+)"$/$1/i ; # fix IN%
        $addr =~ s/^ARPA%"([^"]+)"$/$1/i ; # fix ARPA%
        $addr =~ s/^JNET%"([^"]+)"$/$1.bitnet/i ; # fix JNET%
        $addr =~ s/^UUCP%"([^"]+)"$/$1.uucp/i ; # fix UUCP%
        $addr =~ s/^BITNET%"([^"]+)"$/$1/i ; # fix BITNET%
        $addr =~ s/(\S+)::(\S+)/$2_at_$1/ ; # fix VMS hosts
        $day = sprintf ("%2d", $day) ; # pad date
        $wkdy = &weekday ($day, $mon, $year) ;
 
        print "From \L$addr\E $wkdy \u\L$mon $day $time $year\n" ;
        print "From: $name <\L$addr\E>\n" if $name ;
        print "Subject: $subj\n" if $subj ;
        print "To: \L$to\n" if $to ;
        print "Date: $wkdy, $day \u\L$mon\E $yr $time\n" ;
        print "Cc: $cc\n" if $cc ;
        print ;
        next ;
        }
    /^(.*)/ && warn ("\nSkipping garbled message \#$mesg:\n\tFrom$1\n") ;
    }
continue
    {
    close (ARGV) if (eof) ; # Reset line numbers if multiple files
    }
 
sub weekday
sub weekday
    {
    local ($day, $mon, $year) = _at__ ;
    %month = ( jan, 0, feb, 1, mar, 2, apr, 3, may, 4, jun, 5,
                jul, 6, aug, 7, sep, 8, oct, 9, nov, 10, dec, 11 ) ;
    _at_offset = ( 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 ) ;
    _at_wkday = ( Mon, Tue, Wed, Thu, Fri, Sat, Sun ) ;
 
    $m = $month {"\L$mon"} ; # month number
    $y = $year - ($year % 4) ; # previous leapyear
    $leap = $year == $y ; # current leapyear
    $weekday = 5 ; # for 1/1/2000
    $weekday += 5 * ($y - 2000) / 4 ; # for 1/1/$y
    $weekday += ($year - $y) + !$leap ; # for 1/1/$year
    $weekday += $offset [$m] + ($leap && ($m > 1)) ; # for $m/1/$year
    $weekday += $day - 1 ; # for $m/$day/$year
    $wkday [$weekday % 7] ;
    }
########################
 
.00;
 
'di
.nr nl 0-1
.nr % 0
'; __END__
 
.TH FIXMAIL 1 "November 30, 1993"
.AT 3
.SH NAME
fixmail \- convert VMS mail files to Unix form
.SH SYNOPSIS
.B fixmail file1 file2 ...
.SH DESCRIPTION
 
.I Fixmail
converts VMS mail files to conventional Unix form.
The input files
.I must
be plain text files as produced by the VMS Mail 'extract' command;
not binary indexed VMS mail files.
.I Fixmail
edits the header lines of each message,
and attempts to translate the sender's address to an acceptable Internet form.
A backup copy of the original file is saved (with .orig appended to its name).
 
.SH AUTHOR
Laurence G. Yaffe (lgy_at_phys.washington.edu)
.SH DIAGNOSTICS
Complains about garbled From: lines which it does not recognize.
.SH BUGS
May not be able to translate all VMS addresses into a useful (reply-able) form.
 
Received on Wed Nov 01 1995 - 21:45:20 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT