From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX"  3-APR-1993 01:15:33.04
To:	Info-VAX@KL.SRI.COM
CC:	
Subj:	Re: converting VMS mail to Unix

In article <dsmith.733708570@aa.cad.slb.com>
dsmith@ann-arbor.applicon.slb.com (J. Daniel Smith) writes:
>
>Somebody must have a combination of C code, COM files, and shell
>scripts to convert a VMS mail file to something that can be used under
>Unix (either MH format or Berkeley mail).

Here's a script I've used to convert large amounts of VMS mail to MH.
It's not perfect, but it works pretty well.

To use:

"extract/all" the messages you want to move to a file.  Copy the file
from VMS to UNIX.  Then run the script, e.g.

	vmsmail2mh +foo vmsmail.txt

/Bob

----> cut here <----
#! /bin/sh
##
## Extensively rewritten by Bob Heiney on Thu Jan 21 11:56:36 PST 1993
## to fix bugs and improve robustness.
##
# $Header: /u3/acs/jdpeek/.bin/RCS.Z/vmsmail2mh,v 1.2 90/03/22 06:53:59 jdpeek Exp $
###	vmsmail2mh - split VMS mail messages from EXTRACT/ALL into MH folder
###	Usage: vmsmail2mh [+folder] [...vmsmsg-files]
##
##	AN EASY WAY TO TRANSFER VMS MAIL MESSAGES TO UNIX IS BY EXTRACTING
##	ALL THE MESSAGES FROM A VMS MAIL FOLDER INTO A FILE... USE:
##		MAIL> EXTRACT/ALL
##		_file: FILENAME
##	THEN, YOU CAN ftp THEM TO THE SYSTEM RUNNING MH.
##
##	WHEN YOU GET THEM TO THE MH SYSTEM, vmsmail2mh WILL READ THROUGH
##	THE FILE (OR STANDARD INPUT, IF YOU DON'T GIVE A FILENAME):
##		- THE MESSAGES ARE SEPARATED BY FORMFEEDS (CONTROL-L).
##		  vmsmail2mh WILL CUT THEM INTO SEPARATE MH MESSAGES
##		  IN THE CURRENT FOLDER (OR +folder IF YOU GIVE ONE).
##		- THE FORMAT OF THE VMS MAIL MESSAGE IS DIFFERENT.
##			* Subj: LINES ARE CONVERTED TO Subject: LINES.
##			* From: LINES ARE SPLIT INTO From: AND Date: LINES.
##		  ONLY THE FIRST Subj: AND From: IN EACH MESSAGE IS CONVERTED.
##
##	BUG: VMS ADDRESSES LIKE:
##		SMTP%"user@host"
##		HOST::USER
##	AREN'T CONVERTED.  IN FACT, *NO* ADDRESSES ARE CONVERTED.

#	NOTE: PROGRAM HASN'T BEEN TESTED THOROUGHLY.
# 	CHECK THE MESSAGES!
#	Placed in the public domain.  Use at your own risk.
#		--Jerry Peek, 22 March 1990

dfltprot=600	# DEFAULT MESSAGE PROTECTION (IF NONE IN MH PROFILE)
folopts="-fast -nolist -nototal -nopack -norecurse"
mh=/usr/bin/mh
scanopts="-noclear -noheader -noreverse"

case "$1" in
[@+]?*)
	# IF $1 DOESN'T EXIST, folder WILL CREATE IT (SIGH).
	# THAT'S BECAUSE stdout IS REDIRECTED AWAY FROM TERMINAL.
	if $mh/folder $folopts "$1" </dev/null >/dev/null
	then
		# GET PATHNAME OF FOLDER, LAST MESSAGE NUMBER:
		folpath="`$mh/mhpath`" || exit
		firstmsg="`$mh/scan -format '%(msg)' last`" || firstmsg=0
	else
		echo "`basename $0`: no folder.  quitting." 1>&2
		exit 1
	fi
	;;
*)	echo "Usage: `basename $0` +folder|@folder [file]
	('$1' doesn't start with + or @.)" 1>&2
	exit 1
	;;
esac

if [ -n "$2" -a \( ! -r "$2" \) ]
then
	echo "`basename $0`: quitting: can't read VMS file '$2'." 1>&2
	exit 1
fi

# GET PROTECTION MODE FROM MH PROFILE (IF NONE, USE $dfltprot):
#msgprot="`$mhprofile -b msg-protect`" || msgprot=$dfltprot
msgprot=$dfltprot

# MAKE SHELL ARCHIVE FILE ON awk'S STANDARD OUTPUT.
# PIPE IT INTO sh TO CREATE THE MESSAGE FILES...
nawk "BEGIN {
	folpath=\"$folpath\" # STORE AS STRING, WITH QUOTES
	msgprot=$msgprot     # STORE AS NUMBER (NO QUOTES)
	msgnum=$firstmsg"'   # CHANGE FROM DOUBLE- TO SINGLE-QUOTES
	inmsg = 1
	sawff = 0
	suppressff = 1
}
# PROCESS MESSAGES.  EACH MESSAGE STARTS WITH CONTROL-L
{
	# MESSAGE STARTS WITH CTRL-L ON A LINE BY ITSELF.
	# PRINT SHELL COMMANDS AND RESET FLAGS:
	if ($1 ~ /^From:/ && sawff) {
	  if (!suppressff) {
		printf "END-OF-%s/%d\n", folpath, msgnum
		# SET PROTECTION (INEFFICIENT; SHOULD DO ALL MSGS. AT ONCE)
		printf "chmod %d %s/%d\n\n", msgprot, folpath, msgnum
	  }
	  suppressff = 0
	  inmsg = 0
	}
	else
	{
	  sawff = 0
	}
	# AT START OF MESSAGE, PRINT START OF ARCHIVE AND SET FLAGS:
	if (inmsg == 0) {
		inmsg = 1
		msgnum += 1
		printf "/bin/cat > %s/%d << \\END-OF-%s/%d\n", \
			folpath, msgnum, folpath, msgnum
		didsubj = 0
		didfrom = 0
	}
	# TURN Subj: INTO Subject: AND SET FLAG TO MAKE SURE WE DO NOT
	# TRASH ANY OTHER Subj: LINES (LIKE IN FORWARDED MESSAGES).
	# STRIP DATE (14-MAR-1990 15:31:12.02) OFF END OF THE From: LINE
	# AND MOVE IT TO LINE OF ITS OWN, THEN SET FLAG LIKE ABOVE:
	if ($1 ~ /^Subj:/ && didsubj == 0) {
		$1 = "Subject:"
		didsubj = 1
		print $0
	}
	else if ($1 ~ /^From:/ && didfrom == 0) {
		printf "%s %s", $1, $2
		if (NF > 4) {
			printf " ("
			for (i = 3; i <= NF - 2; i++) {
				if (i!=3) { printf " " }
				printf "%s", $i
			}
			printf ")"
		}
		printf "\n"
		printf "Date: %s %s\n", $(NF - 1), $NF
		didfrom = 1
	}
	else if ($0 ~ /^\f$/ && inmsg == 1) {
		sawff=1
		next
	}
	else
		print
}
END {
		printf "END-OF-%s/%d\n", folpath, msgnum
		# SET PROTECTION (INEFFICIENT; SHOULD DO ALL MSGS. AT ONCE)
		printf "chmod %d %s/%d\n\n", msgprot, folpath, msgnum
}' $2 |		# IF NO $2, WILL READ STANDARD INPUT...
/bin/sh -e	# EXIT ON ANY ERROR

exit
-- 
Bob Heiney  ( heiney@pa.dec.com )                     "Who is John Galt?"
Digital Equipment Corporation, Palo Alto Operations
All opinions expressed are mine, and not necessarily those of my employer

