#!/bin/sh
#
#	Tiny ML filter modefied by wd@ics.nara-wu.ac.jp on Jan. 10, 1995
#	from the original script
#	 "Tiny ML filter by motonori@wide.ad.jp on Mar.16,1994".
#
# usage: /this/script mlname
#
# entries in /etc/aliases:
#	ayaya:			"|/this/script ayaya"
#	ayaya-recipients:	:include:/member/list/file
#	owner-ayaya:		error message receiver
#

# modify here for your site
AWK=/usr/bin/nawk
SENDMAIL=/usr/lib/sendmail

if [ $# -ne 1 ]
then
	exit 1;
fi
mlname=$1
$AWK -v mlname=$mlname '
BEGIN {skip = 0; rplto = 0}
/^$/ {
	if (!rplto){
		if (mlname) {
			printf "Reply-To: %s\n", mlname;
		}
		rplto = 1;
	}
}
/^$/, NR == 0 {print; next;}
/^Reply-To:/ {print; rplto = 1; next;}
/^(X-Ml-Name|Received|Return-Path|Return-Receipt-To):/ {skip = 1; next;}
/^[ 	]/ && skip == 1 {next;}
{skip = 0};
/^From:/ {
	print "Precedence: list";
	if (mlname) {
		printf "X-Ml-Name: %s\n", mlname;
	}
	print;
	next;
}
{print;}
' | $SENDMAIL -oi -fowner-${mlname} ${mlname}-recipients
