#!/bin/sh
# http://www.berklix.com/~jhs/src/bsd/jhs/bin/local/mail/header_add
# Author: jhs_ERASE_@berklix.com
# Used by http://www.berklix.com/~jhs/dots/.procmailrc_last
# Typical use by .procmailrc_last:
#	:0 H
#	* !^X-Strip-Berklix:
#	* MIME-Version:
#	* Content-Type: text/html
#	| header_add X-Strip-Berklix: Text | $NOMIME_BOTH | sendmail -i -t
# The occurence of Text is some non null string of word[s],
# as otherwise demime
#	http://www.berklix.com/~jhs/src/bsd/fixes/FreeBSD/ports/gen/mail/demime/
# will discard header lines with no Text set on right of the colon.

header=yes

# Output Header
IFS=
# IFS avoids loosing space between left margin & text
export IFS
while read line ; do
	if [ "X$line" != "X" ] ; then
		# Not an empty line so emit.
		echo $line
	else
		# Empty line 
		if [ "$header" = "yes" ] ; then
			# Still in header, this is seperater between header and body.
			# Add New Header Line
			echo $*
			echo	# Insert a blank line between header & body.
			header=no
			# End of Header
		else
			echo	# replicate the blank line in body of mail
		fi
        fi
	done
exit $?
