#!/bin/sh
# Convert an mh folder into a maildir.
# Adam Sampson <ats@offog.org>
# The "maildir" command is part of safecat.
#
# From: http://offog.org/darcs/misccode/mh-to-maildir
# Adapted by Ewen McNeill <ewen@naos.co.nz> to call safecat directly

if [ $# != 2 ] ; then
	echo "Usage: mh-to-maildir mhdir maildir"
	exit 1
fi
mhdir="$1"
maildir="$2"
mkdir -p "$maildir/new" "$maildir/cur" "$maildir/tmp" || exit 1
ls "$mhdir" | egrep '^[0-9]+$' | sort -n | while read n ; do
	safecat "$maildir/tmp" "$maildir/new" <"$mhdir/$n" || exit 1
done
