#!/bin/sh
#
# LAST CHANGE: Miha Lampret, 8/Jun/2001
#


cd ~oc/ml-archive
ARCH_DIR=$1

if [ -s ${ARCH_DIR}.listarchive/listarchive ]; then
        touch /tmp/mail4${ARCH_DIR}
        sleep 15
        rm ${ARCH_DIR}.tmp
	mkdir ${ARCH_DIR}.tmp
	/usr/local/mhonarc/mhonarc -sort -reverse -tsort -treverse -outdir ${ARCH_DIR}.tmp ${ARCH_DIR}.listarchive/listarchive 2> /dev/null
	chown oc.users  ${ARCH_DIR}.tmp/*.html
	chown oc.users  ${ARCH_DIR}.tmp/.mhonarc.db
	cp ml-convert.cgi ${ARCH_DIR}.tmp/
	cd ${ARCH_DIR}.tmp
	./ml-convert.cgi
	chown oc.users *
	cd ..
	cp -pr ${ARCH_DIR}.processed ${ARCH_DIR}.old
	ln -s ${ARCH_DIR}.old ${ARCH_DIR}
	rm -rf ${ARCH_DIR}.processed
	mv ${ARCH_DIR}.tmp ${ARCH_DIR}.processed
	chown oc.users ${ARCH_DIR}.processed
	rm ${ARCH_DIR}
	ln -s ${ARCH_DIR}.processed ${ARCH_DIR}
	rm -rf ${ARCH_DIR}.old
        ./email_conv.pl /home/oc/ml-archive/${ARCH_DIR}
	chown oc.users ${ARCH_DIR}
	chown root /home/oc/ml-archive/wrapper
	chmod u+s  /home/oc/ml-archive/wrapper
fi

