[comp.mail.mh] Converting MH back to mbox

leviatan@zip.eecs.umich.edu (David Disser) (02/22/90)

Is there any way to convert MH messages all back into one file that could be
read via mail -f?  I have a lot of old messages cat'd into one big file
which I've compressed to save space.  What I want to to is break it back
down into mbox format or individual MH messages.  Neither inc -file nor
mail -f work.

jromine@ics.uci.edu (John Romine) (02/23/90)

(David Disser) writes:
>Is there any way to convert MH messages all back into one file that could
>be read via mail -f?

"packf" packs messages into the so-called "ms" format (messages delimited
with lines of four control-A's.)  I believe "mail -f" wants to see them
delimited with "\n\nFrom <user> <ctime>".  A simple shell script could
easily do this, however.  Something like:

	for i in `mhpath +folder messages`
	do
		echo "From noone `date`"
		cat $i
		echo ""; echo ""
	done > outputfile

>I have a lot of old messages cat'd into one big file
>which I've compressed to save space.  What I want to to is break it back
>down into mbox format or individual MH messages.

If you didn't delimit the messages somehow, it's going to be tough.
Usually, "Received:" is the first header in a message so I'd check
for that as a pseudo-delimiter.  If you've used MH on these messages,
there may be annotations preceeding the "Received:" lines, so you'll
have to check for those as well. (i.e. Forwarded:, Replied: , etc.)
Modifiy the script below as needed.

Here's a script which does a rough job of it.  Extract this somewhere
and run:

	awk -f xtr.awk < inputfile > msgbox
	inc -file msgbox

Of course, if you have any forwarded messages present, they'll be extracted
individually, with any trailing text.

Cheers,
/JLR

: This is a shar archive.  Extract with sh, not csh.
: This archive ends with exit, so do not worry about trailing junk.
echo 'Extracting xtr.awk'
sed 's/^X//' > xtr.awk << '+ END-OF-FILE xtr.awk'
X/^Received:/ && m == 0 {m = -1}		# beginning of new message
Xm == -1 {
X	if (n++ > 0)
X	    printf "%c%c%c%c\n", 1, 1, 1, 1
X	printf "%c%c%c%c\n", 1, 1, 1, 1
X	m = 1
X}
X	{print}
X/^$/	{m = 0}		# end of headers
XEND	{ printf "%c%c%c%c\n", 1, 1, 1, 1 }
+ END-OF-FILE xtr.awk
chmod 'u=rw,g=r,o=' 'xtr.awk'
echo '	-rw-r-----  1 jromine       243 Feb 22 10:57 xtr.awk        (as sent)'
echo -n '	'
/bin/ls -l xtr.awk
exit 0
--
John Romine