#!/usr/bin/perl

#NAME
#  QuoteReply - build email reply by quoting the original.

#SYNOPSIS
#  QuoteReply [indent] <oldmessage

#DESCRIPTION
#  This is a conventional Unix filter to convert an email message  to
#  a quoted reply.  It reads from standard input, and writes the text
#  to standard output, with every line  of  the  body  "indented"  by
#  inserting the indent string at the left.

#  The  default  indent is "| ".  This string is used rather than the
#  conventional "> " so that line counters won't reject  the  message
#  for having too much quoted text.

#  With  mh,  this  program  doesn't  get the headers, but it's still
#  probably a good idea to look out for them.  If a mailer strips off
#  both  the  headers  and  the  blank  line,  this  will  have to be
#  modified.

#AUTHOR
#  Copyright 1992, 1998, 2000 by John Chambers <jc@trillian.mit.edu> 
#  You may use this for any purposes whatsoever, as long as you don't
#  claim that it's your own.

$| = 1;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || 2;
print "#$0: Called.\n" if $V>5;
for $arg (@ARGV) {
	++$a;
	print "#$0: Arg $a is \"$arg\"\n" if $V>1;
}
$ind = '| ';
$state = 'hdr';
while ($l = <STDIN>) {
	$l =~ s/[\s\r]+$//;
	print "#GOT: $l\n" if $V>5;
	if ($state eq 'hdr') {
		$state = 'body' unless $l;
	} elsif ($state eq 'body') {
		$l =~ s/^/$ind/;
	}
	print "$l\n";
}

