#!/usr/bin/perl -s

@delete = qw(
	Received:
	In-Reply-To:
	User-Agent:
	X-[-\w]*:
	Mailing-List:
	Delivered-To:
	List-Archive: List-Help: List-Id: List-Post:
	List-Subscribe: List-Unsubscribe:
	Thread-[-\w]*:
	Importance: Precedence: Priority: Sensitivity:
	Auto-Submitted:
	Disposition-Notification-To:
	Status:
	DomainKey-Signature:
	Comment: Comments:
	HOP-COUNT:
	Expiry-Date:
	DKIM-[-\w]*:
	Seal-Send-Time:
	Accept-Language: acceptlanguage:
	Face:

	Path:
	Organization:
	Lines:
	ACategory:
	Slugword:
	Threadword:
	Approved:
	NNTP-[-\w]*:
	Originator:
);

@mime = qw( MIME-[-\w]*: Content-[-\w]*: );

# minhdr - filter out commonly unwanted message header lines
# Steve Kinzler, kinzler@cs.indiana.edu, Jun 03/Jun 09
# http://www.cs.indiana.edu/~kinzler/home.html#unix

$usage = "usage: $0 [ -m ] [ -b ] [ file ... ]
	-m	also filter out MIME header lines
	-b	take input as a mbox and filter all message headers\n";
die $usage if $h;

$delete = '^(' . join('|', @delete, ($m) ? @mime : ()) . ')$';
study $delete;

AGAIN:

$fld = '';
while (<>) {
	print, last if /^$/;

	1 while s/^(\t*) {8}/$1\t/;

	$fld = $& if /^\S+/;
	print unless $fld =~ /$delete/io;
}

while (<>) {
	print;
	goto AGAIN if $b && /^From /;
}
