Subject: Conversion from VMS

From: Jim Clark <[email-masked]>
Date: Sun, 23 Jul 1995 13:20:07 -0500

Hi

I have modified the vmsmail.awk program file that was posted to this group
several weeks ago.  It converts VMS mail files to a format understood by
Pine (and I guess other Unix mail programs).  The changes that I remember
making were:  (a) using /pattern/ to identify <Ctrl>L ($1== didn't seem to
work for me), (b) modifying the From conversion to take into consideration
extra information in this field by including an index variable in the
field identifier (e.g., inclusion of auxiliary name field, hundredths of
seconds in time field), and (c) getting rid of the IN% and quotes from the
name. 

To use the program,
	1. EXTRACT this file as mail.awk or somesuch and edit out all put the 
program lines
	2. "EXTRACT /ALL oldmail.mai" in the Vax mail program; note number 
of messages to check conversion
	3. copy oldmail.mai from Vax to Unix (I used ftp)
	4. type "awk -f mail.awk oldmail.mai > ~/mail/oldmail"
	5. enter Pine and select the oldmail folder.  Index should show 
same number of messages as original, or approximately so.  Should see 
correct date, sender, and subject information.

I've seen a few errors in converting 100s of messages, but nothing major 
that I noticed.  If I've overlooked serious problem or way to improve 
program, I would appreciate hearing about it.  Thanks to the anonymous 
person who first wrote the awk program.

Take care
Jim
****************************************************************************
James M. Clark                       (204) 786-9313
Department of Psychology             (204) 786-1824 Fax
University of Winnipeg               [email-masked]
Winnipeg, Manitoba  R3B 2E9          4L02A
CANADA
****************************************************************************
--------vmsmail.awk----------
# awk program to reformat VMS mail header for Unix mail
BEGIN	{ sun = 0;	dname[sun] = "Sun"
	  mon = 1;	dname[mon] = "Mon"
	  tue = 2;	dname[tue] = "Tue"
	  wed = 3;	dname[wed] = "Wed"
	  thu = 4;	dname[thu] = "Thu"
	  fri = 5;	dname[fri] = "Fri"
	  sat = 6;	dname[sat] = "Sat"
	  mname["JAN"] = "Jan";	firstof["Jan"] = sun
	  mname["FEB"] = "Feb";	firstof["Feb"] = wed
	  mname["MAR"] = "Mar";	firstof["Mar"] = wed
	  mname["APR"] = "Apr";	firstof["Apr"] = sat
	  mname["MAY"] = "May";	firstof["May"] = mon
	  mname["JUN"] = "Jun";	firstof["Jun"] = thu
	  mname["JUL"] = "Jul";	firstof["Jul"] = sat
	  mname["AUG"] = "Aug";	firstof["Aug"] = tue
	  mname["SEP"] = "Sep";	firstof["Sep"] = fri
	  mname["OCT"] = "Oct";	firstof["Oct"] = sun
	  mname["NOV"] = "Nov";	firstof["Nov"] = wed
	  mname["DEC"] = "Dec";	firstof["Dec"] = fri
	}
 
//	{ pagesep = 1; next }	# delay formfeeds
 
$1 == "From:" {
	if (!pagesep)		# not a new mail header
	  {print; next  }
	if (NR>3) print ""	# substitute blank line for formfeed
	pagesep = 0; newmsg = 1
	# unread mail has final asterisk in VMS and Status: RO in Unix
		status = "Status: RO"
		if (substr($0,length($0),1) == "*") status = ""
	# reformat date/time from DD-MMM-YYYY HH:MM to Day Mmm DD HH:MM:00 YYYY
		i = 0
		if (NF > 4) i = NF - 4
		if (status == "") i = i-1
		dash = index($(3+i), "-")
		date = substr($(3+i), 1, dash - 1)
		month = substr($(3+i), dash + 1, 3); month = mname[month]
		year = substr($(3+i), dash + 5, 4)
	# find day-of-week (baseline = Jan 1, 1972, a Saturday)
		y = year - 1972
		leapdays = int(y/4) - int(y/100) + int(y/400) + 1
		d = y + leapdays + firstof[month] + date - 1 + sat
		if ((year % 4) == 0 || (year % 400) == 0)
			if (month == "Jan" || month == "Feb")
			--d	# adjust for date in Jan/Feb of a leap year
	if (date < 10) date = " " date
	# truncate time
		time = $(4+i)
		if (index($(4+i), ".") > 0) time = substr($(4+i),1,index($(4+i),".")-1)
	# modify address
		from = substr($2, 5, length($2)-5)
	print "From", from, dname[d % 7], month, date, time , year
	print "From: " from
	print "Date: " dname[d % 7], month, date, year, time
	next }
 
$1 == "Subj:" {print "Subject: ", substr($0, 7, length($0)-6)
	# "Status" after "Subj"
		if (newmsg = 1) {print status; newmsg = 0 }
	 next }
{		# ordinary line
	print $0
	if (pagesep = 1 && newmsg = 0)  {pagesep = 0; print "" }
	next}