#!/bin/bash
# This script converts MH mail folders to the folders that KMail
# prefers (all messages in one file)
#
# usage:  mh2kmail <dirname>
#
# SPDX-FileContributor: Stefan Taferner <taferner@kde.org>
# SPDX-License-Identifier: GPL-2.0-only
#
if [ "X$*" = "X" ]; then
	echo "usage: mh2kmail <dirname>"
	exit 0
fi

MH_DIR=$1
FOLDER=${MH_DIR}.mbx

# remove old kmail folder if any
rm -f $FOLDER

for f in $(/bin/ls $MH_DIR | sed -e :a -e 's/^.\{1,5\}$/ &/;ta' | sort); do
	echo "From ???@??? 00:00:00 1997 +0000" >>$FOLDER
	cat $MH_DIR/$f >>$FOLDER
done

echo "Done. Messages stored in file $FOLDER."
