#!/usr/bin/sed -f
#
# split_digest
#
# Splits one digest mail into separate mails by duplicating the
# From_ header for each message in the digest. Digest sender's
# Reply-To: is also duplicated for each message.
#
# Script assumes that messages are separated with a line consisting
# of hyphens + blank line, following one of the headers From:, Date:,
# Subject: or To:. From_ must be found from the first line, and
# Reply-To: is seeked from lines 2-20.
#  
# This should work at least for digests generated by Majordomo and
# listserv, and FAQs using "minimal digest format".
#
# Written by Aaro Koskinen (aaro@iki.fi), January 1997.
#

# Check for From & Reply-To: headers & memorize them
2,$ b a
/^From / h
b b
:a
21,$ b b
/^Reply-To: / H
:b

# Check for separator
/^-*-$/ !b 
n  
/^$/ !b 
n  
/^Date: / b c
/^From: / b c
/^Subject: / b c
/^To: / b c
b 

# Split
:c
x  
p  
x  


### colorized by sedsed, a debugger and code formatter for sed scripts
### original script: http://sed.sf.net/grabbag/scripts/splitdig.sed