#!/tools/perl_5.004_01/bin/perl

#Written by:  Paulo Dutra (paulo@xilinx.edu)
#Created: 04/26/95
#Updated: 02/27/96
#This program edits e-mail messages that have been saved as a file.
#Saves the original with a ".old" extension unless specified otherwise
#Removes all headers and beginning ">".

sub usage
{
die <<"EndUsage";

usage: clean [-h] [-dfns filename_list]

Edits e-mail or news articles that have been saved
as a file.

Display Options:
	-h  Help -- just display this message and quit.
Input Options:
	-d  remove date of message
	-f  No backup file of original file
		(NOT RECOMMENDED!!)
	-n  Don't remove headers
		(This option overrides -s and -d)
	-s  remove subject 

Author: Paulo Dutra (paulo\@xilinx.com)

EndUsage
}

require "getopts.pl";
&Getopts('dfhns');
if ($@ || $opt_h) { &usage; }

$#ARGV >= 0 || die "clean has no file to edit!\n",
			"Try \"clean -h\" for help\n";

#envoke in-place editing and saves the orginal file with ".old" extension
$^I = ($opt_f)?"":".old";

while(<>)
{
s/^( *(>|:)+)+//;                        	#removes all leading ">"
if (!$opt_n && /^(From| Received)|(Forwarded [Mm]essage)/)
	{
	while(<>)
		{
		y/>//d if /^>/;		#removes all leading ">"
		print if (/^Date/ && !$opt_d);
		print if (/^Subject/ && !$opt_s);
		last if /^$/;
		}
	}
print;	#this prints the edited version of original filename
if (eof)
	{ 
	print STDOUT "Finished $ARGV\n";
	close (ARGV);
	++$count;	#count files cleaned
	}
}		#end of while loop
print "Edited $count file(s)\n";
exit
