#!/exp/rcf/share/bin/perl

# NAME 
#   qrunch
# USAGE
#   qrunch < rfc822+mbox-format > rfc822+mbox-format
# DESCRIPTION
#      Filters stdin to stdout, and prunes all header lines that are marked
#   as 'set ignore' in $HOME/.mailrc, using the same conventions that the
#   standard unix mail(1) or mailx(1) program does.
#      Understands header continuation lines, and concatenates them into
#   one line in output.
# LIMITATIONS
#   Continuation lines are concatenated into one big line.
# FILES
#    $HOME/.mailrc - for the 'set ignore' lines.
# SEE ALSO
#   perl(1), mail(1)
# AUTHOR
#   H.Shrikumar shri@cs.umass.edu Sat Apr 15 14:54:33 EDT 1995
#   Free for personal use.
# INSTALATION
#   Edit line 1 above to reflect the path of your perl. (which perl)
#   Edit ~/.mailrc to have a line such as the following :
#    ignore Approved-By Errors-To In-Reply-To Message-Id Mime-Version ...
# 

# Example 'ignore' ... concatenate all following into one long line.
#   ignore Approved-By Content-Length Content-Transfer-Encoding
#    Content-Type Errors-To In-Reply-To Message-Id Mime-Version Newsgroups
#    Originator Precedence Received References Reply-To Resent-Date
#    Resent-From Resent-Message-Id Resent-To Sender Status
#    X-Authentication-Warning X-Comment X-Envelope-To
#    X-Listprocessor-Version X-Mailer X-Mts X-Vms-Cc X-Vms-To

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#

$HOME=$ENV{'HOME'} ;

$Ignore = `grep ignore $HOME/.mailrc ` ;
$Ignore =~ s/^ignore *//g ; 
$Ignore =~ s/ /|/g ; 
$Ignore =~ s/^\|*// ;
$Ignore =~ s/\|*$// ;

$, = "\n" ;

$lot = "" ;

while ( <> ) {
	Begin: 
	$lot .= $_ ;
	if (/^$/) {
		&doHeader ;
		while (<>) { 
			/^From / && goto Begin; 
			print; 
		}
	}
}
&doHeader ;

sub doHeader {
	$lot =~ s/\n[\t ]/ /g ; 

	@lot = grep( !/$Ignore/ ,split( /\n/, $lot ));
	print @lot ;
	print "\n\n" ;

	$lot = "" ; 
}


