#!/bin/bash
# Public domain (C) 2001 Martin Macok <martin.macok@underground.cz>

function DEBUG { echo "$@" ; }
#function DEBUG { }

if [ "$#" -lt "2" -o "x$1" == "x--help" ] ; then
	echo "Usage: $0 category mailbox [mailbox2 ...] "
	echo "Learns statistics about mailboxes and store it in category"
	exit 1
fi

CAT="$1"

if ! expr "x${CAT}" : "x[-a-zA-Z0-9_@#]*$" >/dev/null ; then
	echo "ERR: Illegal characters in category name." >&2
	exit 1
fi

shift 1

for MBOX in "$@" ; do
	DEBUG "learning mailbox $MBOX into category $CAT"
	formail -s ifile -h -i "$CAT" <"$MBOX" >/dev/null 2>&1
done
